2017-07-28 1 views
0

Ich versuche, AppAuth in iOS zu implementieren. Grundlegende Implementierung wurde durchgeführt. scheint alles gut zu funktionieren. aber ich erhalte das Token nicht wie erwartet. im immer Fehler Error Domain=org.openid.appauth.general Code=-4OAuth Fehler Allgemeiner Code 4 Swift - AppAuth für 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

Sie clientSecret mit der Bitte – Govaadiyo

+0

Ah no gesetzt hat. es wurde nicht im Dokument "https: // github.com/openid/AppAuth-iOS" erwähnt, wie das geht? –

+0

fand es im Dokument, aber 'client_secret \t Das Client-Geheimnis von der API-Konsole erhalten. Dieser Wert wird für Clients, die als Android-, iOS- oder Chrome-Anwendungen registriert sind, nicht benötigt, da er für iOS nicht benötigt wird. –

Antwort

0

Nach Umgang mit Fehlern und Veränderungen dachte ich, das Problem nach mit redirectUri und Token zu tun. redirectUri - Sobald Sie mit Google autorisiert haben, wird das Token generiert und danach sollten Sie die App öffnen. redirectUri wird dabei helfen. Dies ist, wie können Sie Setup 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.