Search code examples
iosswiftauth0

Auth0 v2 for iOS: Renew idToken


I have a question regarding Auth0 v2 for iOS, how to renew the idToken?

I am using renew(withRefreshToken refreshToken: String, scope: String?) method with refreshToken, but it's only returning new accessToken, and I need idToken.

Does anyone know how to obtain it?


Solution

  • I've managed to obtain new idToken using delegation, maybe it'll be helpful for someone, so I'm posting it below:

    Auth0
            .authentication()
            .delegation(withParameters: ["refresh_token": refreshToken])
            .start { result in
                switch result {
                case .success(let data):
                    guard let idToken = data["id_token"] as? String else {
                        // No id token
                        return
                    }
    
                    // Save your idToken
                case .failure(let error):
                    print(error.localizedDescription)
                }
        }