One other thing. I´m not trying to create a Database user with password. I´m just trying to extend the social connection with username. How can I use CreateUser with social connection? Then I think I´ll have to create the temp token in the rule like the following so I get all the other claims?
I did notice that the user gets created before the redirect. But I will have to then update that user to have a username.
Now i’m trying the update user in management api but I´m confused what token the ManagementApiClient wants. In your example where do you get the parameter yourApiToken??
Yes, the sample code was for option 1.
Option two, as described by Abhishek:
Step 1 will remain the same, However, the page will simply ask for a username.
Step 2 will simply add the username to app_metadata.username, in this case, you’ll need to fetch if any users have the same username in order to maintain the uniqueness with Management API v2 Search User and then add app_metadata via the update user command.
That means that, instead of creating a user, you will be adding the “username” as a field in the app_metatada for the user. It’s just additional information that you will use for any purpose within the application. But, for login purposes, the user will be using his or her social identity (that username you are asking will not be involved in the login process when using a social connection).
For social connections you can’t “create” an user, but you can add additional information using app_metadata.
How do I make the user get a new valid jwt token that contains the username?
Remember that this was a redirect rule. So after you set the username in the app_metadata, the authentication flow will run again, and the generated JWT will contain any information you put in the app_metadata, as long as you include it in the scope. I.e. `scope: ‘openid username’.
Make sure that no one else has that username? (Consistency)
Why do you want a username for the user? Do you use it for something in your application? If so, I guess you have a database or something like that with your existing usernames. Check there before assigning the username to the user, in the action, and return some error if the username already exists.
Keep in mind this is an Angular 2 SPA application that does not like server routing very much. What is the best approach here. Can I redirect from the angular app? Maby with ?token=… query parameter?
I’m curious how are you POSTing the form? Is this as an XHR? Its being blocked CORS, You can redirect to the continue endpoint from your SPA aswell, in that scenario your POST request should return the response with which you later redirect.
public register(token, user) {
let endpoint = `${this.apiEndpoint}users/register?token=${token}`;
let result = this.http.post(endpoint, user)
.map(res => res.json());
return result;
If this is an XHR then you can simply return JSON from your server, and use it to show errors etc if the request succeeds then you should redirect to https://{YOUR_DOMAIN}.auth0.com/continue?state={STATE} where the state is the same as the state in your querystring.
invalid_request: Error resuming the authentication transaction after redirect. If you are using any social network as a connection, make sure you register your own account (vs. using Auth0’s Dev Keys). Please check Redirect Users from Within Rules for more information.
When you use redirect rules, you should have a state parameter added to the page where the user enters the username and finishes the procedure. The state=movies looks suspicious to me, this state is not the one that you send to Auth0, this is a special state used by Auth0 to know if the redirect is returning from an Authorized Client. If this state is missing, you can simply return nothing (this is part of the experimental pipeline but will be enforced).