使用 OAuthSwift 和 identityserver3 时所需的示例代码
example codes needed when using OAuthSwift and identityserver3
我已经使用 identityServer3 设置了身份服务器。现在我正在编写一个 iOS 应用程序来对身份服务器进行身份验证。我找不到此设置的任何示例或代码。我找到的示例都使用 google 或 github 等。我的问题是调用 OAuthSwift.authorizeWithCallbackURL
只是将屏幕切换到 safari,然后什么也没有显示。我怀疑我的 callbackurl 或 url 方案设置不正确。
这是我的代码片段
在服务器端:
new Client {
ClientId = "implicitclient1",
ClientName = "Example Implicit Client1",
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
Enabled = true,
Flow = Flows.Implicit,
RequireConsent = true,
AllowRememberConsent = true,
RedirectUris =
new List<string> {"oauth-swift://oauth-callback/TestOAuth2"},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email
},
AccessTokenType = AccessTokenType.Jwt
},
在 iOS 应用端:
let oauthswift = OAuth2Swift(
consumerKey: "implicitclient1",
consumerSecret: "secret",
authorizeUrl: "https://example.com/idserver/core/connect/authorize",
accessTokenUrl: "https://example.com/idserver/core/connect/token",
responseType: "token"
)
oauthswift.authorizeWithCallbackURL(NSURL(string: "oauth-swift://oauth-callback/TestOAuth2")!,
scope: "openid",state: "",
success: {
credential, response, parameters in
print(credential.oauth_token)},
failure: {
error in
print(error.localizedDescription)
})
在 ios 应用程序中添加 URL 类型时,我输入了 "TestOAuth2"。
我做错了什么?
非常感谢。
我成功了。
打开 identityserver3 日志记录是一个巨大的帮助。我将流程从隐式更改为授权代码。 (我不确定为什么需要这样做,但这就是我让它工作的方式。)我将回调字符串更改为 "myiosappname://oauth-callback"。在 ios 应用程序中,我将 "myiosappname" 放入 plist 的 URL 类型方案。
我仔细检查了那个 ssl 证书。
然后开始工作了。我希望它对以后的人有所帮助。
赫兹
我已经使用 identityServer3 设置了身份服务器。现在我正在编写一个 iOS 应用程序来对身份服务器进行身份验证。我找不到此设置的任何示例或代码。我找到的示例都使用 google 或 github 等。我的问题是调用 OAuthSwift.authorizeWithCallbackURL
只是将屏幕切换到 safari,然后什么也没有显示。我怀疑我的 callbackurl 或 url 方案设置不正确。
这是我的代码片段
在服务器端:
new Client {
ClientId = "implicitclient1",
ClientName = "Example Implicit Client1",
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
Enabled = true,
Flow = Flows.Implicit,
RequireConsent = true,
AllowRememberConsent = true,
RedirectUris =
new List<string> {"oauth-swift://oauth-callback/TestOAuth2"},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email
},
AccessTokenType = AccessTokenType.Jwt
},
在 iOS 应用端:
let oauthswift = OAuth2Swift(
consumerKey: "implicitclient1",
consumerSecret: "secret",
authorizeUrl: "https://example.com/idserver/core/connect/authorize",
accessTokenUrl: "https://example.com/idserver/core/connect/token",
responseType: "token"
)
oauthswift.authorizeWithCallbackURL(NSURL(string: "oauth-swift://oauth-callback/TestOAuth2")!,
scope: "openid",state: "",
success: {
credential, response, parameters in
print(credential.oauth_token)},
failure: {
error in
print(error.localizedDescription)
})
在 ios 应用程序中添加 URL 类型时,我输入了 "TestOAuth2"。
我做错了什么?
非常感谢。
我成功了。 打开 identityserver3 日志记录是一个巨大的帮助。我将流程从隐式更改为授权代码。 (我不确定为什么需要这样做,但这就是我让它工作的方式。)我将回调字符串更改为 "myiosappname://oauth-callback"。在 ios 应用程序中,我将 "myiosappname" 放入 plist 的 URL 类型方案。
我仔细检查了那个 ssl 证书。
然后开始工作了。我希望它对以后的人有所帮助。
赫兹