Hello everyone,
I have been working on an iOS application and want to access user's private repository, download a file to phone then make some changes and push it back. All of those were working with a hard coded user account credentials. Lately I've implemented Auth0 for login/authentication.
This is the code for Auth0 part:
```
Auth0
.webAuth()
.scope("openid profile email offline_access account repository:admin")
.audience("https://" + clientInfo.domain + "/userinfo")
.start {
switch $0 {
case .success(let credentials):
guard let accessToken = credentials.accessToken,
let refreshToken = credentials.refreshToken else { return }
SensitiveInfoManager.shared.keychain.setString(accessToken, forKey: .accessToken)
SensitiveInfoManager.shared.keychain.setString(refreshToken, forKey: .refreshToken)
DispatchQueue.main.async {
let main = UIStoryboard(name: "Main", bundle: nil)
let tabbar = main.instantiateInitialViewController()
self.present(tabbar!, animated: true, completion: nil)
}
case .failure(let error):
NSLog("Error authenticating user: \(error)")
SensitiveInfoManager.shared.keychain.clearAll()
}
}
```
After saving access token have another network call to GET user information. But every time I'm getting 401 error: "Access token expired. Use your refresh token to obtain a new access token".
In the documentation it says access token expires in 1 or 2 hours based on the documentation. But when I print expiresIn value, expiration time's at least 4 hours from now.
One hour - https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication
Two hour - https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
The endpoint: https://api.bitbucket.org/2.0/repositories/username/reponame
I'm sending access token in a request header: Authorization: Bearer {access_token}
Mac and iPhone doesn't have any date/time issue. Any idea? What would be the problem?
Hello @Ilgar Ilyasov,
It is not clear to me from the code excerpt you posted: which OAuth flow are you using from those listed here? What parameters are you sending with the request?
It's hard to make assumptions without clarifying these details first.
In the documentation it says access token expires in 1 or 2 hours based on the documentation. But when I print expiresIn value, expiration time's at least 4 hours from now.
Token expiration time is currently set to two hours (I noted that there's inconsistency in the docs and will get it fixed soon), and expires_in parameter returned back with the tokens contains a (relative) number of seconds, that is always 7200. Looks like this doesn't match with what you observed, so let's start with the questions I mentioned above.
Cheers,
Daniil
Hey Daniil, thank you for getting back to me.
I was using Authorization Code Grant. And I figured out that Auth0 is not sending back an access_token, they are sending back a code but their naming is confusing (credentials.accessToken). After swapping the code with an actual access token, everything is working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, so the issue is resolved, glad to hear that :)
Cheers,
Daniil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.