Skip to content

Refresh token is not working as expected #188

@VasantHugar

Description

@VasantHugar

Describe the bug?

We are using OktaWebAuthenticationUI for Okta login into our iOS Swift app. When user signedIn on the app, we store the unique id of the token to fetch token based on unique id for later use

Store token and id

try Credential.store(token)
UserSettingsHelper.setObject(object: token.id, forKey: Constants.k_OktaTokenId) 

Fetch:

        if let tokenId = UserSettingsHelper.object(for: Constants.k_OktaTokenId) as? String {
            do {
                let credential = try Credential.with(id: tokenId)
                self.refreshIfNeeded(credential: credential)

                // this is used as an access_token for all our api calls
                let token = credential.token.accessToken
            } catch let error as NSError {
                print("Error: ", error.localizedDescription)
            }
        }
    }
 
func refreshIfNeeded(credential: Credential) {
        Task {
            do {
                try await credential.refreshIfNeeded()
            } catch {
               print("Error: \(error.localizedDescription) while calling refreshIfNeeded")
            }
        }
    }

Above code works well and good until it expires. token is not getting refresh after 6-7days(expired).

Question:

  • What is the best way to retrieve the token for later use?
  • How to refresh the token?
  • does okta generates new token with new id after refresh? if yes should we use new token id to fetch the token for later use.
  • Could you please share us sample project?

What is expected to happen?

  • We should be able to fetch token for later use
  • Refresh token should work with logout and login if expired

What is the actual behavior?

Refreshed token is not working even after calling refreshIfNeeded() func

Reproduction Steps?

Steps

  • Login into okta
  • Wait for 6 to 7days till it expires
  • Use the availble token to call an api.
  • Api should work

Additional Information?

No response

SDK Version(s)

pod 'OktaWebAuthenticationUI', '1.6.1'

Build Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions