This guide is meant for developers that are NOT using Descope Flows to design login screens and authentication methods.
If you'd like to use Descope Flows, Quick Start should be your starting point.
A one-time password (OTP) is an automatically generated string sent to the user during the
onboarding (sign-up or sign-in) process to authenticate that user. The OTP can be sent to an email
address or a mobile phone as a voice call or SMS (text message). A typical method for implementing OTP has two
sets of functionality you need to program: user interaction and session verification.
Sign-Up or Sign-In (Signs up a new user or signs in an existing user): The following actions must be completed, first User Sign-Up or Sign-In then User Verification
baseUrl: Custom domain that must be configured to manage token response in cookies. This makes sure every request to our service is through your custom domain, preventing accidental domain blockages.
baseStaticUrl: Custom domain to override the base URL that is used to fetch static files.
For registering a new user, your application client should accept user information, including an email or
phone number used for verification. In this sample code, the OTP verification will be sent by email
to email@company.com. To change the delivery method to send the OTP verification as a Text Message (SMS), you would
change the deliveryMethod to sms within the below example.
Note
Note that signup is not complete without the user verification step below.
For authenticating a user, your application client should accept the user's identity (typically an email address or phone
number). In this sample code, the OTP verification will be sent by email to email@company.com.
Note
Note that signin is not complete without the user verification step below.
For signing up a new user or signing in an existing user, you can utilize the signUpOrIn functionality.
Only user loginId is necessary for this function. In this sample code, the OTP verification will be
sent by email to email@company.com. To change the delivery method to send the OTP verification as a Text Message (SMS), you would
change the deliveryMethod to sms within the below example.
Note
Note that signUpOrIn is not complete without the user verification step below.
The next step in authenticating the user is to verify the code entered by the user, using OTP verify code
function. The function will return all the necessary JWT tokens,
claims and user information. You can use the JWT tokens for session validation in your application middleware or app
server for every route needs an authenticated user.
This function allows you to update the user's email address via email. This requires a valid refresh token. Once the user has
received the OTP Code, you will need to host a page to verify the OTP code using the OTP Verify Function.
This function allows you to update the user's phone number address via SMS. This requires a valid refresh token. Once the user has
received the OTP Code, you will need to host a page to verify the OTP code using the OTP Verify Function.
The final step of completing the authentication with Descope is to validate the user session. Descope provides rich session management capabilities, including configurable session timeouts and
logout functions. You can find the details and sample code for client session validation here.
Checkpoint
Your application is now integrated with Descope. Please test with sign-up or sign-in use case.