[GH-ISSUE #189] logged or not? #113

Closed
opened 2026-03-03 16:45:48 +03:00 by kerem · 3 comments
Owner

Originally created by @sourov2008 on GitHub (Feb 23, 2016).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/189

`@IBAction func stratAuth(sender: AnyObject) {
     let oauthswift = OAuth2Swift(
        consumerKey:    "xxx",
        consumerSecret: "xxx",
        authorizeUrl:   "https://www.fitbit.com/oauth2/authorize",
        responseType:   "token"
    )

    oauthswift.authorizeWithCallbackURL(
        NSURL(string: "HealthAnother://oauth-callback/fitbit")!,
        scope: "activity+profile+location+sleep+weight", state:"Fitbit",
        success: { credential, response, parameters in

            print(credential.oauth_token)
            self.testFitbit2(oauthswift)

        },
        failure: { error in
            print(error.localizedDescription)
        }
    )

}

func testFitbit2(oauthswift: OAuth2Swift) {
    oauthswift.client.get("https://api.fitbit.com/1/user/227G3S/activities/tracker/steps/date/2016-02-23.json", parameters: [:],
        success: {
            data, response in
            let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: [])
            print(jsonDict)
        }, failure: { error in
            print(error.localizedDescription)
    })
}

`
The scenario is i want to set a button and the text of the button will change depends on user Authenticated or Not .
If someone already authenticated button text will set Disconnect/Logged out Or Authenticate Here .
How can i checked is user already Authenticated or Not .

  • **OS targeted (with version): ios 9.2
  • **OAuth provider: Fitbit
  • **OAuthSwift version: Current Version
Originally created by @sourov2008 on GitHub (Feb 23, 2016). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/189 ``` `@IBAction func stratAuth(sender: AnyObject) { let oauthswift = OAuth2Swift( consumerKey: "xxx", consumerSecret: "xxx", authorizeUrl: "https://www.fitbit.com/oauth2/authorize", responseType: "token" ) oauthswift.authorizeWithCallbackURL( NSURL(string: "HealthAnother://oauth-callback/fitbit")!, scope: "activity+profile+location+sleep+weight", state:"Fitbit", success: { credential, response, parameters in print(credential.oauth_token) self.testFitbit2(oauthswift) }, failure: { error in print(error.localizedDescription) } ) } func testFitbit2(oauthswift: OAuth2Swift) { oauthswift.client.get("https://api.fitbit.com/1/user/227G3S/activities/tracker/steps/date/2016-02-23.json", parameters: [:], success: { data, response in let jsonDict: AnyObject! = try? NSJSONSerialization.JSONObjectWithData(data, options: []) print(jsonDict) }, failure: { error in print(error.localizedDescription) }) } ``` ` The scenario is i want to set a button and the text of the button will change depends on user Authenticated or Not . If someone already authenticated button text will set Disconnect/Logged out Or Authenticate Here . How can i checked is user already Authenticated or Not . - **OS targeted (with version): ios 9.2 - **OAuth provider: Fitbit - **OAuthSwift version: Current Version
kerem 2026-03-03 16:45:48 +03:00
Author
Owner

@phimage commented on GitHub (Feb 23, 2016):

⚠️ don't share in github your consumer key and secret (secret means secret), I edit your message...

A user is not disconnected or logged... You have a token, valid or not, or you have not a token

So store the token in success callback, you are logged
no token you are not logged
then to know if token always valid you must do an api request and see if success or failed

<!-- gh-comment-id:187699636 --> @phimage commented on GitHub (Feb 23, 2016): :warning: don't share in github your consumer key and secret (secret means secret), I edit your message... A user is not disconnected or logged... You have a token, valid or not, or you have not a token So store the token in `success` callback, you are logged no token you are not logged then to know if token always valid you must do an api request and see if success or failed
Author
Owner

@sourov2008 commented on GitHub (Feb 23, 2016):

Thank You :)
How Long token will alive ?

<!-- gh-comment-id:187706142 --> @sourov2008 commented on GitHub (Feb 23, 2016): Thank You :) How Long token will alive ?
Author
Owner

@phimage commented on GitHub (Feb 23, 2016):

depending on the provider, here fitbit, and sometimes when requesting authorization you can specify the token duration

in success handler there is parameters and sometimes expiration time is defined in this dictionary

but token could also be invalidated, exception must be handled
more info here https://github.com/OAuthSwift/OAuthSwift/wiki/OAuth-2.0-Token-Expiration

you can close issue if no more question

<!-- gh-comment-id:187710170 --> @phimage commented on GitHub (Feb 23, 2016): depending on the provider, here fitbit, and sometimes when requesting authorization you can specify the token duration in `success` handler there is `parameters` and sometimes expiration time is defined in this dictionary but token could also be invalidated, exception must be handled more info here https://github.com/OAuthSwift/OAuthSwift/wiki/OAuth-2.0-Token-Expiration you can close issue if no more question
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#113
No description provided.