# New user via API - set password flow

**URL:** <https://community.auth0.com/t/new-user-via-api-set-password-flow/62654>\
**Category:** Get Help\
**Tags:** password, manage-users, auth0\
**Created:** [May 12, 2021, 10:03am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654 "2021-05-12T10:03:12Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 12, 2021, 10:03am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/1 "2021-05-12T10:03:12Z")

</div>

We would like to create users from a system, which will eventually make an API call to Auth0 Management API. I’m wondering if there’s a flow possible, where the created user will receive an email that would contain a link with automatic login and force them to set/ reset their password immediately.  
We’d rather not generate and send a plain text password to the user by email. What would be the recommended flow here? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 12, 2021, 11:42am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/3 "2021-05-12T11:42:59Z")

</div>

Hi @adeliab,

> [@adeliab](#):
>
> We would like to create users from a system, which will eventually make an API call to Auth0 Management API.

To clarify, will you be creating users via the Management API, or will the users be calling your tenant’s Management API?

> [@adeliab](#):
>
> I’m wondering if there’s a flow possible, where the created user will receive an email that would contain a link with automatic login and force them to set/ reset their password immediately.

Here is a guide for implementing an invitation-only flow:

> **[Send Email Invitations for Application Signup](https://auth0.com/docs/customize/email/send-email-invitations-for-application-signup)**
>
> Describes how to customize the signup process to invite users to signup for an account in the context of a specific Auth0 application.

---

<div class="post-metadata">

**Author:** ![daniel10](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@daniel10](https://community.auth0.com/u/daniel10)\
**Post date:** [May 12, 2021, 11:47am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/4 "2021-05-12T11:47:42Z")

</div>

HI @stephanie.chamblee how do I specify query params to use the invite flow of Universal login like it mentions?

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 12, 2021, 11:56am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/5 "2021-05-12T11:56:03Z")

</div>

Hi @stephanie.chamblee , sorry I’m new with Auth0 so I’m not sure what is the difference between Management API and tenant’s Management API.

The idea is to have an external application calls our custom User API, which will send a request to Auth0 to create the user - with this call [Auth0 Management API v2](https://auth0.com/docs/api/management/v2#!/Users/post_users)

We don’t want users to sign up by themselves because we need to set the app\_metadata when the user is created. From the documentation you sent, it seems possible to create a user first and then send a change password link. Let me have more read and let you know if I have any question.

Thanks!

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 12, 2021, 12:09pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/6 "2021-05-12T12:09:12Z")

</div>

Hi @stephanie.chamblee the **mark\_email\_as\_verified** parameter in the change password ticket, if it’s set to true - does that mean the email is verified during the ticket generation? or after the user sets the password?

And how can we trigger the sending of invitation email after the user is created?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 12, 2021, 1:46pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/7 "2021-05-12T13:46:52Z")

</div>

> [@adeliab](#):
>
> The idea is to have an external application calls our custom User API, which will send a request to Auth0 to create the user - with this call [Auth0 Management API v2](https://auth0.com/docs/api/management/v2#!/Users/post_users)

Thanks for clarifying!

> [@adeliab](#):
>
> the **mark\_email\_as\_verified** parameter in the change password ticket, if it’s set to true - does that mean the email is verified during the ticket generation? or after the user sets the password?

The user’s email will be verified only after they reset their password when `mark_email_as_verified` is `true`.

> [@adeliab](#):
>
> And how can we trigger the sending of invitation email after the user is created?

When you call the `/api/v2/tickets/password-change` endpoint, you will receive a URL that can be used in a template in your own external email provider. You can use the [Post-User Registration Hook](https://auth0.com/docs/hooks/extensibility-points/post-user-registration?_ga=2.227476888.464884123.1620041333-1595415333.1607347674&_gac=1.86497002.1620663261.Cj0KCQjws-OEBhCkARIsAPhOkIbhK13acrxZIWhKyPE4GlpGf7ZKmKpxtmuQbD_VcaLmyScFgvNZcmAaAntFEALw_wcB) to trigger the email.

Here is an example of sending an email in a Rule with the Mandrill email provider: [Auth0 Actions](https://auth0.com/rules/mandrill?_ga=2.227476888.464884123.1620041333-1595415333.1607347674&_gac=1.86497002.1620663261.Cj0KCQjws-OEBhCkARIsAPhOkIbhK13acrxZIWhKyPE4GlpGf7ZKmKpxtmuQbD_VcaLmyScFgvNZcmAaAntFEALw_wcB). You could do something similar in a Post-User Registration Hook to send the email.

You can also follow this answer to use the Auth0 change password email template: [Sending password change email instead of verification email for a new user - #3 by stephanie.chamblee](https://community.auth0.com/t/sending-password-change-email-instead-of-verification-email-for-a-new-user/55713/3)  
With this solution, you would likely need to configure the template in a way that regular password change requests would look different than the initial password reset.

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 12, 2021, 1:55pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/8 "2021-05-12T13:55:02Z")

</div>

Thanks for your reply @stephanie.chamblee !

In your example, I suppose the call to create password change ticket also happens in the hook?

As an alternative, I think our custom API can also perform this task and use our external provider to send the email. The flow would be:

1. Our custom API creates user in Auth0 via Management API
2. Our custom API creates password change ticket
3. Our custom API sends the generated URL to SendGrid where the URL will be put in the template and sent to the user

In this flow we’re not using Auth0 email template or sending the email from Auth0. I suppose this would work too?

I feel the email template will be cleaner because don’t need to add IF statements to the auth0 change password template to support localization & change template VS invite format.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 12, 2021, 1:57pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/9 "2021-05-12T13:57:02Z")

</div>

> [@adeliab](#):
>
> In this flow we’re not using Auth0 email template or sending the email from Auth0. I suppose this would work too?

Yes, that will work nicely! Since your API is able to handle all aspects of user creation, I believe that makes a lot of sense. I agree it would be a cleaner template.

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 25, 2021, 7:20am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/10 "2021-05-25T07:20:50Z")

</div>

Hi @stephanie.chamblee , we’re still looking into the best place to send the email from. Is it possible to use Auth0 Actions to call the get a password ticket and trigger a sendgrid email?

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 25, 2021, 7:34am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/11 "2021-05-25T07:34:10Z")

</div>

hmm… it seems that the creation of Action is not supported by the terraform library yet: [Terraform Registry](https://registry.terraform.io/providers/alexkappa/auth0/latest/docs/resources/hook)  
I suppose it can work with a Hook too?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 26, 2021, 1:31pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/12 "2021-05-26T13:31:28Z")

</div>

Hi @adeliab,

Yes, you can use an Action or a post-user registration hook or a rule to generate the change-password email and send the email. Here is an example in rules: [Customize Email Handling](https://auth0.com/docs/email/manage-email-flow#send-welcome-email-using-your-own-api)

Regarding Terraform’s support of Actions, I’ve asked the team about this and I will let you know what I hear back.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 28, 2021, 4:41pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/13 "2021-05-28T16:41:51Z")

</div>

@adeliab, one thing to note that I’ve realized after doing some testing, it is uncommon but possible that the user will not exist yet in the user registration hook. If going that route, you would need to handle a 404 error when you generate the password-change ticket and re-try the request. This should not be common, but because of the async nature of this hook, it is possible.

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 28, 2021, 5:33pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/14 "2021-05-28T17:33:54Z")

</div>

Hi Stephanie, thanks for the heads up! Our plan now is to have auth0 hook sends a message to a service bus queue. And another service will subscribe to this message and perform the get change password ticket + email send. Do you still see the risk that the user won’t be available by the time?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 28, 2021, 5:38pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/15 "2021-05-28T17:38:47Z")

</div>

That sounds like a safe plan. The user should be available by the time the request is made by the second service. You could add a retry if a 404 is returned, but I don’t believe that would occur.

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [May 31, 2021, 8:10am UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/16 "2021-05-31T08:10:25Z")

</div>

Thanks @stephanie.chamblee ! Is it confirmed that Action is not supported by Terraform yet?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [June 1, 2021, 1:03pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/17 "2021-06-01T13:03:52Z")

</div>

Hi @adeliab,

It isn’t supported yet, but I did find an enhancement issue which you can track the progress on: [Support Auth0 Actions · Issue #302 · alexkappa/terraform-provider-auth0 · GitHub](https://github.com/alexkappa/terraform-provider-auth0/issues/302)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 16, 2021, 1:04pm UTC](https://community.auth0.com/t/new-user-via-api-set-password-flow/62654/18 "2021-06-16T13:04:20Z")

</div>

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