Get Auth0 user_id for IOS

I’m trying to retrieve the Auth0 userid for my app. I see that it is held in the Idtoken field but this needs to be requested during authentication. How do I do this?
This is my current authentication request
Auth0
.webAuth()
.scope(“openid offline_access profile email”)
.audience(“https://xxxxxxxxxxxxx”)
.start { result in
switch result {
case .failure(let error):
// Handle the error
print(“Error: (error)”)
case .success(let credentials):
etc.

Hi @elizabeth.wright,

Welcome to the Community!

You should be able to see it as the sub claim in the token. Is that claim not being returned?

Hi Dan,

thanks for the reply. Forgive me, I must be missing something obvious. This is my login :

Auth0
.webAuth()
.scope(“openid offline_access profile email”)
.audience(“https://xxxxxxxxx.auth0.com/userinfo”)
.start { result in
switch result {
case .failure(let error):
// Handle the error
print(“Error: (error)”)
case .success(let credentials):
// make the login button a pale grey colour
print(“Credentials: (credentials)”)

etc.

I get the access token from the credentials, but there’s no sub claim attached? If I try typing credentials.accessToken, there’s no ‘sub’ field available

                print("accesstoken = " , credentials.accessToken ?? "")

Liz

Are you not recieving the ID token? Or does the ID token not contain the userID?

Thanks Dan, I was missing the jwt decode. I have it now. Thanks for the guidance.

1 Like

Thanks for the follow up.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.