Skip to content

saltukalakus/auth0-custom-password-reset-link

Repository files navigation

What it does?

In Password Flow 2 option enabled accounts, with this simple project running on Webtask.io you could replace the password reset email view of your Lock. With Webtask hosted reset email view, you could set different redirect to URLs for your applications even they are using the same client ID in the Auth0 dashboard which is currently not possible to setup from the management dashboard.

To make this possible, spin up a new instance of this project for each different redirect to URLs and in Lock configuration of your application set the forgot password link to this instance.

Note that, your Lock version should be 10 or newer.

How it works?

1- User clicks on Lock password reset link.
2- Browser navigates to the instance of this project in webtask.io
2.1- Webtask instance provides it's own user interface to get the user email.
2.2- Webtask instance makes a Management v2 API call to get the customised password reset link.
2.3- Webtask instance sends the received email link in 2.2 to user's email address provided in step 2.1
3- User clicks on the link.
4- User updates the password with Auht0 hosted page.
5- After the password update, user is redirected to the customised redirect to path configured in step 2.

Prerequisites

  • Install Node.js and Npm

Setup

  • Setup a new client for management v2 API calls in Auth0 management dashboard
    Follow this link to make the setup. While creating the client, select Auth0 Management API in your authorized API dropdown. In the next window enable your new client and select create:user_tickets scope.

  • Install libraries

npm install
npm install -g wt-cli webtask-bundle
wt init
  • Copy the sample_config.json as config.json in the same folder.

  • Get the Webtask token for your Webtask.io account. You can find the token with below command line call.

wt profile ls --show-token
  • Paste your Webtask token to config.json
    "webtaskToken":"YOUR_WEBTASK_TOKEN"

  • Fill the other required parameters in config.json.

    • Project name in the webtask link created. For each different redirect to update this setting.
      "webtaskName": "custom-password-reset"

    • ID of your Auth0 client created in setup
      "AUTH0_APIv2_CLIENT_ID":"YOUR_AUTH0_API_CLIENT_ID"

    • Secret of your Auth0 client created in setup
      "AUTH0_APIv2_CLIENT_SECRET":"YOUR_AUTH0_API_CLIENT_SECRET"

    • This project currently uses SendGrid for sending emails.
      "SENDGRID_KEY": "YOUR_SENDGRID_KEY"

    • Sender email
      "fromEmail" : "YOUR@EMAIL"

    • resultUrl is to configure the path to redirect to after password update. Check the API for more details.
      "resultUrl" : "YOUR_REDIRECT_TO_URL_AFTER_PASSWORD_UPDATE"

    • connectionId should be the database connection id where user email is available.  It starts with con_ and this id is available in the URL when you click on a connection in management dashboard.
      "connectionId" : "YOUR_AUTH0_DB_CONNECTION"

    • Your auth0 domain like MY_DOMAIN.auth0.com or MY_DOMAIN.aut0.au.com etc.
      "auth0Domain": "YOUR_AUTH0_DOMAIN"

  • Bundle the project and upload to Webtask.io

npm run bundle
npm run deploy

How to test

Click on the created webtask link
https://webtask.it.auth0.com/api/run/YOUR_ACCOUNT/webtaskName

Demo

2 SPA's with Lock are currently hosted in now.sh with the below links. Both have the same client id in Auth0 dashboard. I have started a webtask for each so that when an email reset update completes in Auth0 hosted page user is returned to the correct app. Please try yourself with your email in both of the apps. Note that as both Apps use the same connection/db you need to create an account only once. Also notice that webtask urls for both apps are different.

Useful links

License

MIT

About

Auth0 custom password reset link with Webtask

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published