trivago / Heimdallr.swift

Easy to use OAuth 2 library for iOS, written in Swift.
Apache License 2.0
639 stars 86 forks source link

Question: Retrieve Access Token that is store for use in the application #78

Closed daande closed 8 years ago

daande commented 8 years ago

After I login using this:

let tokenURL = NSURL(string: URL.signin)!
        let heimdall = Heimdall(tokenURL: tokenURL)
        heimdall.requestAccessToken(username: self.txtEmail.text!, password: self.txtPassword.text!) { result in
            switch result {
            case .Success:

How would I use the access token? I need it to open a websocket using a different library. In my AppDelegate.swift I have:

protocol OAuthAccessTokenStore {
    func storeAccessToken(accessToken: OAuthAccessToken?)
    func retrieveAccessToken() -> OAuthAccessToken?
}

Any idea I just need the token string for example:

"ba81a9251150a0f229ff7bb0d117eecbe3ec75dafecf8497e42d282fc19f9772"

Kalzem commented 8 years ago

To get the access token if you are using the default AccessTokenKeychainStore

let oauthStore = OAuthAccessTokenKeychainStore()
if let token = oauthStore.retrieveAccessToken() {
    print("\(token.accessToken) & \(token.refreshToken)")
}
daande commented 8 years ago

@BabyAzerty Thank you