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}<br>
Mac and iPhone doesn't have any date/time issue. Any idea? What would be the problem?