2016-09-01 13 views
1

私はidentityServer3を使用してIDサーバーをセットアップしました。今、アイデンティティサーバーに対して認証するためのiOSアプリケーションを作成しています。私はこの設定のための例やコードを見つけることができませんでした。私が見つけた例は、すべてgoogleやgithubなどを使用しています。私の問題は、OAuthSwift.authorizeWithCallbackURLという呼び出しが画面をSafariに切り替えるだけで何も表示されないということです。私はcallbackurlまたはURLスキームの私のセットアップが正しくないと思われる。ここでOAuthSwiftとidentityserver3を使用する場合に必要なサンプルコード

は私のコードスニペットは、サーバ側で

です:のiOSアプリ側の

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 
     }, 

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"を入れてください。

どうしたのですか?

ありがとうございます。

答えて

0

私はそれを働かせました。 identityserver3ログを有効にすることは大きな助けとなりました。フローを暗黙的からAuthorization Codeに変更しました。 (私はこれがなぜ必要なのか分かりませんが、それはどうしたのですか)コールバック文字列を "myiosappname:// oauth-callback"に変更しました。 iosアプリケーションでは、 "myiosappname"をplistのURL Typesスキームに入れました。

私はSSL証明書をダブルチェックしました。

その後、動作し始めました。誰かが道を歩くのを助けることを願っています。

HZ

関連する問題