I’m trying to integrate Auth0 into my existing App. I followed the guide at Postgrest Docs to add a rule to get the role from app_metadata
. I’ve stored a custom property role
in the app_metadata
, and created a rule to Add persistent attributes to the user. However when I do a webAuth(), the credentials returned doesn’t have the custom claim in the JWT (in both accessToken and idToken). Here’s the code that I’m using.
Auth0.webAuth()
.scope("openid role profile read:current_user update:current_user_metadata")
.audience("https://mydomain.eu.auth0.com/api/v2/")
.start { [weak self] in
switch $0 {
case .failure(let error):
print("Error: \(error)")
case .success(let credentials):
_ = self?.credentialsManager.store(credentials: credentials)
// accessToken or idToken here don't contain the `role` claim, which I verify on jwt.io
}
}
The rule that adds persistent attribute to the user
function (user, context, callback) {
const namespace = 'https://mydomain.eu.auth0.com/';
const key = "role";
const value ="my_role";
context.idToken[namespace + key] = value;
context.accessToken[namespace + key] = value;
callback(null, user, context);
}
Testing the Rule on dashboard gives this data:
{
"https://mydomain:eu:auth0:com/role": "my_role"
}