2

I am currently trying to authorize my users with OAuth2.0. I am currently using the following library: https://github.com/p2/OAuth2. Here is my Code:

let oauth2 = OAuth2CodeGrant(settings: [
    "client_id": "******",  //ID from Fitbit
    "client_secret": "***************************", //Secret from Fitbit
    "authorize_uri": "https://www.fitbit.com/oauth2/authorize",
    "token_uri": "https://api.fitbit.com/oauth2/token",  
    "redirect_uris": ["http://google.com/"],   
    "scope": "profile settings activity nutrition heartrate location nutrition profile settings sleep social weight",
    "secret_in_body": true,
    "keychain": false,        
    ] as OAuth2JSON)

And here is my function to authorize:

func startAuthorization() {
    oauth2.logger = OAuth2DebugLogger(.trace)

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

Here's my log-trace :

[Debug] OAuth2: Starting authorization
[Debug] OAuth2: No access token, checking if a refresh token is available
[Debug] OAuth2: I don't have a refresh token, not trying to refresh
[Debug] OAuth2: Opening authorize URL in system browser: https://www.fitbit.com/oauth2/authorize?state=35701F98&response_type=code&scope=profile+settings+activity+nutrition+heartrate+location+nutrition+profile+settings+sleep+social+weight&redirect_uri=http%3A%2F%2Fgoogle.com%2F&client_id=******

It works perfectly without any errors, but I just don't get the access token. Every tutorial I found was in Swift 2. Hope you can help me!

Mr. Xcoder
  • 4,719
  • 5
  • 26
  • 44
Moo123
  • 21
  • 5

0 Answers0