Passwordless quickstart
This guide explains how you can implement passwordless authentication using Scalekit’s APIs to send either verification codes or magic links to your user’s email address and verify their identity.
Prerequisites
Section titled “Prerequisites”Before you begin, ensure you have:
-
Access to your Scalekit Account and the API credentials. If you don’t have a Scalekit account yet, you can signup here.
-
Installed Scalekit SDK into your project
Terminal window npm install @scalekit/sdkimport { Scalekit } from '@scalekit-sdk/node';const scalekit = new Scalekit('<SCALEKIT_ENVIRONMENT_URL>','<SCALEKIT_CLIENT_ID>','<SCALEKIT_CLIENT_SECRET>',);
Implementation guide
Section titled “Implementation guide”-
Configure settings
Section titled “Configure settings”Before implementing the code, ensure passwordless authentication is properly configured in your Scalekit dashboard:
- Navigate to Authentication > Auth Methods
- Locate the Passwordless section
- Choose the type of passwordless authentication to use.
- Save your changes
-
Send verification email
Section titled “Send verification email”The first step in the passwordless flow is to send a verification email to the user’s email. This verification email contains either a one-time passcode or a magic link or both based on your selection in the Scalekit dashboard (earlier step).
Follow these steps to implement the verification email flow:
- Create a form to collect the user’s email address
- Call the passwordless API when the form is submitted
- Handle the response to provide feedback to the user
API endpoint POST /api/v1/passwordless/email/sendExample implementation
Request # Send a passwordless verification code to user's emailcurl -L '<SCALEKIT_ENVIRONMENT_URL>/api/v1/passwordless/email/send' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer eyJh..' \--data-raw '{"email": "john.doe@example.com","expires_in": 3600,"state": "jAy-state1-gM4fdZ...2nqm6Q","template": "SIGNIN","magiclink_auth_uri": "https://yourapp.com/passwordless/verify"}'# Response# {# "auth_request_id": "jAy-state1-gM4fdZ...2nqm6Q"# "expires_at": "1748696575"# "expires_in": 100# "passwordless_type": "OTP" | "LINK" | "LINK_OTP"# }Request parameters
Parameter Required Description email
Yes Recipient’s email address string expires_in
No Code expiration time in seconds (default: 300) number state
No OIDC state parameter for request validation string template
No Email template to use ( SIGNIN
orSIGNUP
) stringmagiclink_auth_uri
No Magic Link URI that will be sent to your user to complete the authentication flow. If the URL is of the format https://yourapp.com/passwordless/verify
, the magic link sent to your user via email will behttps://yourapp.com/passwordless/verify?link_token=<link_token>
. Required if you selected Link or Link + OTP as the passwordless option.stringResponse parameters
Parameters Description auth_request_id
A unique identifier for the authentication request that can be used to verify the code string expires_at
Unix timestamp indicating when the verification code will expire string expires_in
The time in seconds after which the verification code will expire. Default is 100 seconds number passwordless_type
The type of passwordless authentication to use. Currently supports OTP
,LINK
andLINK_OTP
stringconst options = {template: "SIGNIN",state: "jAy-state1-...2nqm6Q",expiresIn: 3600,// Required if you selected Link or Link+OTP as passwordless optionmagiclinkAuthUri: "https://yourapp.com/passwordless/verify"};const sendResponse = await scalekit.passwordless.sendPasswordlessEmail("<john.doe@example.com>",options);// sendResponse = {// authRequestId: string,// expiresAt: number, // seconds since epoch// expiresIn: number, // seconds// passwordlessType: string // "OTP" | "LINK" | "LINK_OTP"// }Request parameters
Parameter Required Description email
Yes The email address to send the passwordless link to string template
No The template type ( SIGNIN
/SIGNUP
) stringstate
No Optional state parameter to maintain state between request and callback string expiresIn
No Optional expiration time in seconds (default: 3600) number magiclinkAuthUri
No Magic Link URI that will be sent to your user to complete the authentication flow. If the URL is of the format https://yourapp.com/passwordless/verify
, the magic link sent to your user via email will behttps://yourapp.com/passwordless/verify?link_token=<link_token>
. Required if you selected Link or Link + OTP as the passwordless option.stringResponse parameters
Parameters Description authRequestId
Unique identifier for the passwordless authentication request string expiresAt
Expiration time in seconds since epoch number expiresIn
Expiration time in seconds number passwordlessType
Type of passwordless authentication ( OTP
,LINK
orLINK_OTP
) string -
Resend a verification email
Section titled “Resend a verification email”Users can request a new verification email if they need one. Use the following endpoint to send a fresh email to verify using OTP or Magic Link.
Request curl -L '<SCALEKIT_ENVIRONMENT_URL>/api/v1/passwordless/email/resend' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsIm..' \-d '{"auth_request_id": "jAy-state1-gM4fdZ...2nqm6Q"}'# Response# {# "auth_request_id": "jAy-state1-gM4fdZ...2nqm6Q"# "expires_at": "1748696575"# "expires_in": 3600# "passwordless_type": "OTP" | "LINK" | "LINK_OTP"# }Request parameters
Parameters Required Description auth_request_id
Yes The unique identifier for the authentication request that was sent earlier string Response parameters
Parameters Description auth_request_id
A unique identifier for the authentication request that can be used to verify the code string expires_at
Unix timestamp indicating when the verification code will expire string expires_in
The time in seconds after which the verification code will expire. Default is 3600 seconds number passwordless_type
The type of passwordless authentication to use. Currently supports OTP
,LINK
andLINK_OTP
stringconst { authRequestId } = sendResponse;const resendResponse = await scalekit.passwordless.resendPasswordlessEmail(authRequestId);// resendResponse = {// authRequestId: "jAy-state1-gM4fdZ...2nqm6Q",// expiresAt: "1748696575",// expiresIn: "3600",// passwordlessType: "OTP" | "LINK" | "LINK_OTP"// }Request parameters
Parameters Required Description authRequestId
Yes The unique identifier for the authentication request that was sent earlier string Response parameters
Parameters Description authRequestId
Unique identifier for the passwordless authentication request string expiresAt
Expiration time in seconds since epoch number expiresIn
Expiration time in seconds. Default is 3600 seconds number passwordlessType
OTP
,LINK
orLINK_OTP
string -
Verify the user’s identity
Section titled “Verify the user’s identity”Once the user receives the verification email,
- If it’s Verification code, they’ll enter it in your application. Use the following endpoint to validate the code and complete the authentication process.
- If it’s Magic Link, they’ll click the link in the email to verify their email address. Capture the
link_token
request parameter from the URL and use it to verify the user’s email address. - For additional security with magic links, if you enabled the option “Enforce same browser origin”, you are required to send the
auth_request_id
to the verification endpoint.
- Create a form to collect the verification code
- Call the verification API when the form is submitted to verify the code
- Handle the response to either grant access or show an error
API endpoint POST /api/v1/passwordless/email/verifyExample implementation
Request curl -L '<SCALEKIT_ENVIRONMENT_URL>/api/v1/passwordless/email/verify' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsIm..' \-d '{"code": "123456","auth_request_id": "YC4QR-dVZVtNNVHcHwrnHNDV..."}'Request parameters
Parameters Required Description code
Yes The verification code entered by the user string auth_request_id
Yes The request ID from the response when the verification email was sent string Response parameters
Parameters Description email
The email address of the user string state
The state parameter that was passed in the original request string template
The template that was used for the verification code string passwordless_type
The type of passwordless authentication to use. Currently supports OTP
,LINK
andLINK_OTP
stringconst { authRequestId } = sendResponse;const verifyResponse = await scalekit.passwordless.verifyPasswordlessEmail({ code: "123456"},authRequestId);// verifyResponse = {// "email": "saifshine7@gmail.com",// "state": "jAy-state1-gM4fdZdV22nqm6Q_j..",// "template": "SIGNIN",// "passwordless_type": "OTP" | "LINK" | "LINK_OTP"// }Request parameters
Parameters Required Description options.code
Yes The verification code received by the user string authRequestId
Yes The unique identifier for the authentication request that was sent earlier string Response parameters
Parameters Description email
The email address of the user string state
The state parameter that was passed in the original request string template
The template that was used for the verification code string passwordlessType
The type of passwordless authentication to use. Currently supports OTP
,LINK
andLINK_OTP
string- Create a verification endpoint in your application to handle the magic link verification. This is the endpoint that the user lands in when they click the link in the email.
- Capture the magic link token from the
link_token
request parameter from the URL. - Call the verification API when the user clicks the link in the email.
- Based on token verification, complete the authentication process or show an error with an appropriate error message.
API endpoint POST /api/v1/passwordless/email/verifyExample implementation
Request curl -L '<SCALEKIT_ENVIRONMENT_URL>/api/v1/passwordless/email/verify' \-H 'Content-Type: application/json' \-H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsIm..' \-d '{"link_token": "a4143d8f-...c846ed91e_l","auth_request_id": "YC4QR-dVZVtNNVHcHwrnHNDV..." // (optional)}'Request parameters
Parameters Required Description link_token
Yes The link token received by the user string auth_request_id
No The request ID you received when the verification email was sent. string Response parameters
Parameters Description email
The email address of the user string state
The state parameter that was passed in the original request string template
The template that was used for the verification code string passwordless_type
The type of passwordless authentication to use. Currently supports OTP
,LINK
andLINK_OTP
string// User clicks the magic link in their email// Example magic link: https://yourapp.com/passwordless/verify?link_token=a4143d8f-d13d-415c-8f5a-5a5c846ed91e_l// 2. Express endpoint to handle the magic link verificationapp.get('/passwordless/verify', async (req, res) => {const { link_token } = req.query;try {// 3. Verify the magic link token with Scalekitconst verifyResponse = await scalekit.passwordless.verifyPasswordlessEmail({ linkToken: link_token },authRequestId // (optional) sendResponse.authRequestId);7 collapsed lines// 4. Successfully log the user in// Set session/token and redirect to dashboardres.redirect('/dashboard');} catch (error) {res.status(400).json({error: 'The magic link is invalid or has expired. Please request a new verification link.'});}});// verifyResponse = {// "email": "saifshine7@gmail.com",// "state": "jAy-state1-gM4fdZdV22nqm6Q_j..",// "template": "SIGNIN",// "passwordless_type": "OTP" | "LINK" | "LINK_OTP"// }Request parameters
Parameters Required Description options.linkToken
Yes The link token received by the user string authRequestId
No The unique identifier for the authentication request that was sent earlier. string Response parameters
Parameters Description email
The email address of the user string state
The state parameter that was passed in the original request string template
The template that was used for the verification code string passwordlessType
The type of passwordless authentication to use. Currently supports OTP
,LINK
andLINK_OTP
string
Congratulations! You’ve successfully implemented passwordless authentication in your application. Users can now sign in securely without passwords by entering a verification code or clicking a magic link sent to their email.
Next steps
Section titled “Next steps”- Test your implementation: Try the complete authentication flow to ensure everything works as expected
- Enhance security: Consider implementing rate limiting and suspicious activity monitoring
- Customize emails: Update the email templates to match your brand Coming soon