Auth0 user uuid

Hi all,

Lately I’ve been playing around with Auth0.
I’ve managed to setup a custom action that generates an UUID and saves that to the user’s app_metadata. However, this only works with regular user signups, not with SSO.

As @rueben.tiow said in his post. The only trigger that works is the login trigger.

To come to my question: I’m looking for a solution to generate an UUID for all users, including SSO logins. Is this possible?

Edit: So appearently legacy rules do seem to work with SSO. With some help of @markd 's rules i’ve managed to get it working.

I assume these rules will be deprected someday, would I be able to replace this with actions in some way?

Thanks :slight_smile:

1 Like

Hi @Quintenps,

Welcome to the Auth0 Community!

I’m glad to hear that you found a workaround using Rules and wanted to know more about the deprecation of Rules.

Yes, you are encouraged to convert your Rules into Actions if possible. At this time, we will continue to support Auth0 Rules until 2022.

Since long-term support for Node 12 will be ending in April 2022, we strongly recommend you begin to migrate to Auth0 Actions, which will allow you to stay on a supported Node version without additional future action or overhead. Note that we do not expect any replacement strategies to emerge until 2022.

For now, I can confirm that it’s safe to continue using Rules until the time comes for the migration.

By which point, you should have ample time to convert your Rules into Actions with the provided migration strategies.

Lastly, If you would like, I would be happy to look at your Rule and see if we can convert it into an Auth0 Action.

Thank you.

1 Like

Sweet, yes please :slight_smile:

Hi @Quintenps,

Thank you for the quick reply!

Could you please share with me the Rule you would like to convert into an Action?

Thank you.

Yeah for sure.

Basically I’m using 3 of Markd’s rules listed in this repo

1 Like

Hi @Quintenps,

Thank you for your response and patience!

First, you’ll need to configure 3 Post-Login Action scripts.

Here is the equivalent code using Auth0 Actions:

//add-user-metadata-to-idtoken Action
exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://sr2.ca/claims/";
  api.idToken.setCustomClaim(namespace + "user_metadata", event.user.user_metadata)
};

//add-uuid-to-app-metadata Action
exports.onExecutePostLogin = async (event, api) => {
  const { v4: uuidv4 } = require('uuid');
  event.user.app_metadata.uuid = event.user.app_metadata.uuid || uuidv4(); 
  api.user.setAppMetadata("uuid", event.user.app_metadata.uuid)
};
//add-uuid-to-idtoken Action
exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://sr2.ca/claims/";
  api.idToken.setCustomClaim(namespace + "uuid", event.user.app_metadata.uuid);
};

In these Action scripts, I also did not implement an unnecessary line of code for setting the app_metadata to itself, but is never used: user.app_metadata = user.app_metadata || {};

I have just tested these Action scripts myself and confirm that they work.

Here are some useful resources:

Please let me know how this works for you.

Thank you.

1 Like

Thank you so much for your effort! I’m going to try this tonight. Just to be sure; does this also work with SSO?

Hi @Quintenps,

Thank you for your reply!

Yes, this will work with SSO. These Action scripts will assign a UUID to a user logging in with any type of Connection such as Social Logins (Facebook, Google, etc) or Database Logins.

Please let me know if there’s anything else I can do to help.

Thank you.

I can’t thank you enough! It works!

I completely overlooked the post-login possibility. I was too focused on trying to generate an UUID on pre/post registration.

Sweet :smiley:

1 Like

Hi @Quintenps,

You’re most welcome!

I’m happy to hear that everything works.

Have a great rest of your day!

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