Auth0 Home Blog Docs

iOS Auth0 v2 refresh idToken

ios
swift
idtoken

#1

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. In v1 there was a method fetchNewIdTokenWithRefreshToken, but how to do this in v2?

Thanks


#2

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)
			}
	}

#3

I’m getting this in response

{“error”:“invalid_request”,“error_description”:“Cannot
set property
’undefinedorganization_uri’ of
undefined”,“statusCode”:400}


#4