2

I am using the Fitbit API to authorize my app and it is working fine however in the OAuthSwift documentation I don't see a way to set the expiration date of the generated token even tho the Fitbit API has a method to do so and the Implicit Grant Flow lets you set the expiration date to up to a year.

Here is my config for oAuthSwift:

let config = OAuth2Swift(
    consumerKey:    Constants.FitbitApi.consumerKey,
    consumerSecret: Constants.FitbitApi.consumerSecret,
    authorizeUrl:   Constants.FitbitApi.authorizeUrl,
    accessTokenUrl: Constants.FitbitApi.accessTokenUrl,
    responseType:   Constants.FitbitApi.responseType
)

Per de documentations those are the parameters it takes but no expiration date parameter. And here is my authorization method:

@IBAction func doOAuthFitbit(sender: AnyObject) {
    let oauthswift = FitbitOAuth.sharedInstance.config
    oauthswift.accessTokenBasicAuthentification = true
    FitbitOAuth.sharedInstance.oauthswift = oauthswift

    let state = generateState(withLength: 20)
    oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift)

    guard let callbackURL = URL(string: Constants.FitbitApi.callBackUrl) else { return }

    let _ = oauthswift.authorize(withCallbackURL: callbackURL, scope: "weight", state: state) { result in
        switch result {
            case .success(let (credential, response, parameters)):
              if let resp = response {
                print(resp)
              }

              print(parameters)
              print(credential.oauthToken)

              FitbitOAuth.sharedInstance.saveOAuthInStorage()

              self.authorizationLabel.text = "Authorized"

            case .failure(let error):
              print(error.localizedDescription)

              self.authorizationLabel.text = "Not Authorized"
        }
    }
}

As noted this is working fine however the token always comes with an expiration date of 277895 and I would like to set it to 30 days or a year.

Thanks in advance.

Hols
  • 361
  • 1
  • 5
  • 21

0 Answers0