I’m trying to assign a role to the user and then read it on a client. I use Vue and npm auth0, not a special Vue adaptation. I’ve made the simple authorisation works, thanks to the explicit lessons on this resource. I have successfully made a rule, at least it passed the tests.
Now I stuck with the question what to do next. I can not read roles in my app, although I see there is one by default in the user profile. The rule I’ve made pass the test but do not assign the right role. Maybe I send a wrong request how to check that?
I’ve read the forum most of the advice come to this article. OpenID Connect Scopes Honestly I do not understand how could I apply this.
I’ll be very appreciated for any help where to look and what to do.
let webAuth = new auth0.WebAuth({
domain: 'cornices.eu.auth0.com',
clientID: 'AHS6j7tx5Jby4L24p0OoFq95j2XCDb0t',
// make sure this line is contains the port: 8080
redirectUri: 'http://localhost:8080/callback',
// we will use the api/v2/ to access the user information as payload
audience: 'https://cornices.eu.auth0.com/api/v2/',
responseType: 'token id_token',
scope: 'openid profile roles',
roles: 'pl' // **so i've add this for the test**
})
The role is:
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
var addRolesToUser = function(user, cb) {
if (context.roles === 'pl') {
cb(null, ['plasterer']);
} else {
cb(null, ['user']);
}
};
addRolesToUser(user, function(err, roles) {
if (err) {
callback(err);
} else {
user.roles = user.app_metadata.roles; //**was added by the advice on this forum to avoide error when user doesn't exist**
user.app_metadata.roles = roles;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
.then(function(){
context.idToken['cornices.eu.auth0.com/roles'] = user.app_metadata.roles; //**was in the tamplate have know idea what it does**
callback(null, user, context); //**was in the tamplate have know idea what it does**
})
.catch(function(err){
callback(err);
});
}
});
callback(null, user, context);
}
Sorry for such huge delay in response! We’re doing our best in providing you with best developer support experience out there, but sometimes our bandwidth is not enough comparing to the number of incoming questions.
Wanted to reach out to know if you still require further assistance?