I need to store all social users in the Auth0 database. All users are required to have an email and will be linked by email. At the same time, it’s required to have a record in the Auth0 database. This will make all users have an integer identifier (with the
auth0| prefix). This identifier will then be used as a key for user records in the local database in the external application. We can not change this behavior of the external app and introduce string user identifiers. So the only way to have a consistent numeric key identifier for all Auth0 users I see in having records in the Auth0 database. How can I achieve that? Or are there any better options?
Hi @alex.pravdin ,
I think that using the Account Linking feature would accomplish what you need, you could create an Auth0 Database user with your own custom ID to meet the external app’s needs, rather than using the autogenerated ID Auth0 creates (as this is not an integer value).
This database user could be then used as the primary account, and linked to the relevant social connection user as the secondary account. Please see the below link for more information on account linking and creating users:
Hi @sgo , thank you for your reply.
I plan to use the Account Linking extension. But I still have questions:
- How can I force any user to be stored in the database on the Auth0 side by using rules/hooks? I don’t want to modify the Account Linkin extension to keep it managed and updated.
- How can I create an auto-increment integer field in user data stored in the Auth0 database?
- How can I add this custom field to id and access tokens?
I tried to use the following tutorial Sample Use Cases: Scopes and Claims for adding custom claims to tokens but it doesn’t work for access tokens. I also didn’t find the
api parameter documentation, what functionality this API has. It would be nice if you add any documentation right to the action editing page or a link to the default code in the action editor.
Trying to make access tokens to contain custom claim I copied the same code to an M2M / Client-Credentials action, but it doesn’t work and I can’t find any docs about getting user data in it.
Auth0 seems to be a great and powerful tool. But it’s not the first time I try to do something with it but every time it hurts because I feel like a blind kitten. Every minor customization is unintuitive and requires a lot of googling and support from a live person and takes a few days to get it working…
Here in actions, I see a code editor, nice. But what can I do in it? I have a function and some params. Alright. But what about params objects’ documentation? I can’t find any links to the Actions documentation from the Actions section. But I can find a link to some piece of docs in… Rules and Hooks sections pages! Why no links to docs on the Actions page?
Okay, I see
PostLoginAPI. And what do they mean? What can I do with them? I’m googling these names and can’t find documentation. Why do you make your users spend so much time on very basic things?
Interface whose methods can be used to change the behavior of the login. - false, because nobody knows HOW to use this interface and what methods it has.
Hi @alex.pravdin ,
You should be able to find all the actions documentation here: Auth0 Actions
Depending on the flow involved, the params will have different contents, each action trigger has a reference section detailing what is available in the event and API objects for example, the login trigger:
In the action code editor, there is a link in the bottom right that takes you to the relevant trigger’s documentation too.
In the docs you linked, the example shows how to add claims to the ID tokens, but there is also a paragraph explaining that access tokens require a different method;
Here is a direct link to the login trigger’s API documentation, which can be found in the references section in the above docs I linked.
Please note however that in an M2M/Client credential flow there is no notion of a user, it is a client that is authenticating and not a user in that scenario, so no user details will be available.
1. How can I force any user to be stored in the database on the Auth0 side by using rules/hooks? I don’t want to modify the Account Linkin extension to keep it managed and updated.
All user profiles are stored in Auth0, the only difference is when using an external IdP, the profile would be updated from the external source on a new login, and Auth0 will have no hash of the password.
2. How can I create an auto-increment integer field in user data stored in the Auth0 database?
This would either be sent when creating a new Database user via the Management API, or be stored as app_metadata alongside the auto-generated user_id.
For the latter case, a pre-user registration triggered action could be used to set this, but auto-incrementing would not be possible with Actions alone as they do not support caching - they have no persistence with other previous runs of Actions.
But you could make a call to your backend to fetch what should be the new ID perhaps.
Is the link called “View samples”? Doesn’t look like a good name for a link to the documentation. At least, it should be named as “View samples and documentation”.
When I see the “trigger” word in the article header it’s not associated in my mind with the action method parameters. That’s why I missed this page. I’d suggest renaming it to something like “post-login action parameters”. That’s the best name from my point of view for what is described there.
That’s not a good way to achieve what I need. An API call can not be atomic and safe. Any chance to implement this on the Auth0 side by utilizing client metadata, for example?