p2 / OAuth2

OAuth2 framework for macOS and iOS, written in Swift.
Other
1.14k stars 278 forks source link

[Debug] OAuth2: Cannot open authorize URL #335

Closed iampaulanca closed 4 years ago

iampaulanca commented 4 years ago

I've been trying to get this pod to work with Google's oauth flow. Doesn't seem to be working and I get an error "[Debug] OAuth2: Cannot open authorize URL" when I try to authorize.

Any help is appreciated. Thanks

Here are some console logs [Debug] OAuth2: Starting authorization [Debug] OAuth2: No access token, checking if a refresh token is available [Debug] OAuth2: Error refreshing token: I don't have a refresh token, not trying to refresh [Debug] OAuth2: Opening authorization in browser with params. nil [Debug] OAuth2: Opening authorize URL in system browser: https://accounts.google.com/o/oauth2/v2/auth?state=9C3B137C&redirect_uri=com.googleusercontent.apps.528223174950-irjpdvnng8s8t99f9e00pks39vinjb%3MyAppCallBack%3A%2F%2F&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.readonly&code_challenge_method=S256&client_id=528223174950-irjpdvnng8s8t99f9e00pks3f59vinjb.apps.googleusercontent.com&code_challenge=yVcgn-lHJMBwC45ZGYEh0w5mn2w6O_gHu363zZXFuYw [Debug] OAuth2Authorizer: Made it here [Debug] OAuth2: FAILED tryToObtainAccessTokenIfNeeded [Debug] OAuth2: Cannot open authorize URL

Here are some relevant code

var oauth2 = OAuth2CodeGrant(settings: [
        "client_id"     : "528223174950-irjpdvnng8s8t99f9e00pks3f59vinjb.apps.googleusercontent.com",
        "use_pkce"      : true,
        "authorize_uri" : "https://accounts.google.com/o/oauth2/v2/auth",
        "redirect_uris" : ["com.googleusercontent.apps.528223174950-irjpdvnng8s8t99f9e00pks3f59vin:MyAppCallBack://"],
        "scope"         : "https://www.googleapis.com/auth/gmail.readonly",
        "secret_in_body": true,    // Github needs this
        "keychain"      : false        // if you DON'T want keychain integration
    ] as OAuth2JSON)

oauth2.handleRedirectURL(URL(string:"com.googleusercontent.apps.528223174950-irjpdvnng8s8t99f9e00pks3f59vinjb:MyCallBack://")!)
oauth2.logger = OAuth2DebugLogger(.trace)`

oauth2.authorize(params: nil) { authParameters, error in
            if let params = authParameters {
                print("Authorized! Access token is in `oauth2.accessToken`")
                print("Authorized! Additional parameters: \(params)")
            }
            else {
                print("Authorization was canceled or went wrong: \(error)")   // error will not be nil
            }
        }