2017-07-28 16 views
0

iOSでAppAuthを実装しようとしています。基本的な実装が行われています。うまく動作しているようです。期待どおりにトークンを受け取っていません。イム取得エラーError Domain=org.openid.appauth.general Code=-4OAuthエラー一般コード4 Swift - AppAuth for iOS

let authorizationEndpoint : NSURL = NSURL(string: "https://accounts.google.com/o/oauth2/v2/auth")! 
    let tokenEndpoint : NSURL = NSURL(string: "https://www.googleapis.com/oauth2/v4/token")! 

    let configuration = OIDServiceConfiguration(authorizationEndpoint: authorizationEndpoint as URL, tokenEndpoint: tokenEndpoint as URL) 

    let request = OIDAuthorizationRequest.init(configuration: configuration, clientId: "<MyTOKEN>", scopes: [OIDScopeOpenID], redirectURL: URL(string: "http://127.0.0.1:9004")!, responseType: OIDResponseTypeCode, additionalParameters: nil) 

    let appDelegate = UIApplication.shared.delegate as! AppDelegate 
    //  appDelegate.currentAuthorizationFlow 
    appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: self, callback: { (authState, error) in 
     if((authState) != nil){ 
      print("Got authorization tokens. Access token: \(authState?.lastTokenResponse?.accessToken)") 
     }else{ 
      print("Authorization error \(error?.localizedDescription)") 
     } 
    }) 
+0

はあなたが要求 – Govaadiyo

+0

なしああでclientSecretを設定しなかったことができる方法です。それはドキュメント 'https:// github.com/openid/AppAuth-iOS'には言及されていませんでしたか? –

+0

はドキュメント内でそれを見つけましたが、 'client_secret \t APIコンソールから取得したクライアントシークレットです。この値は、Android、iOS、またはChromeアプリケーションとして登録されたクライアントには必要ありません。 –

答えて

0

は、エラーや変化に対応した後、私はredirectUriとトークンを扱った後、問題を考え出しました。 redirectUri - Googleで承認した後はトークンを生成し、その後でアプリを開く必要があります。 redirectUriはそれを助けます。 これは、セットアップredirectUri

The value for iOS URL scheme wil be the scheme of your redirect URI. This is the Client ID in reverse domain name notation, e.g. com.googleusercontent.apps.IDENTIFIER. To construct the redirect URI, add your own path component. E.g. com.googleusercontent.apps.IDENTIFIER:/oauth2redirect/google. Note that there is only a single slash (/) after the scheme.

関連する問題