Include user_metadata and app_metadata in JWT using Auth0

坚强是说给别人听的谎言 提交于 2019-12-06 08:12:38

You could use an Auth0 Hook. Login to Auth0 and on the left side navigation pane choose "Hooks". Under "Client Credentials Exchange" create a new hook. In here you can add to the scopes that by default your app passes in to the Lock API. Adding the following line:

access_token.scope.push('user_profile');

I believe should include both user_metadata AND app_metadata.

You should be able to also specify this from the client itself without using a hook. If you check out this link it should show you some extra options you can specify with regards to the scope parameter. This sample looks particularly useful:

var options = {  auth: {
params: {scope: 'openid email user_metadata app_metadata picture'},  }};  

Deevz answer is correct, accept it so it is marked as such. I would like to expand on it, however. You have to add a new rule to your auth0 client. This is done in the 'Rules' section.

function (user, context, callback) {
    var namespace = 'unique-namespace';
    context.idToken[namespace + 'app_metadata'] = user.app_metadata;
    context.idToken[namespace + 'user_metadata'] = user.user_metadata;
    context.accessToken[namespace + 'app_metadata'] = user.app_metadata;
    context.accessToken[namespace + 'user_metadata'] = user.user_metadata;
    callback(null, user, context);
}

I hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!