简体   繁体   中英

Auth0 Add Custom Claims to User Profile

I want Auth0 to send some additional info in the user profile. So I created the following rule:

function (user, context, callback) {
  user.app_metadata = user.app_metadata || {};
  user.app_metadata.test = "some info here";
    auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
      .then(function() {
        context.idToken['https://example.com/test'] = user.app_metadata.test;
        callback(null, user, context);
      })
      .catch(function(err) {
        callback(err);
      });
}

However, instead of receiving this (which I expected):

{
  user_metadata: {
   test: "some customer id"
  }
  nickname: "afaafa11fdf"
  name: "afaafa11fdf@bob.com"
}

I receive this:

{
  https://example.com/test: "some customer id"
  nickname: "afaafa11fdf"
  name: "afaafa11fdf@bob.com"
}

I have been following these guidelines here .

I contacted Auth0 and apparently that's the desired behaviour. I expected the wrong result, but what I describe above and did in fact receive is correct. So for anyone with this question, you will in the end receive something along these lines:

{
  https://example.com/test: "some customer id"
  nickname: "afaafa11fdf"
  name: "afaafa11fdf@bob.com"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM