Example: email OTP backend auth flow
This example shows the backend email OTP verification flow that uses the new init_otp, verify_otp and otp_login endpoints.
Notes:
- This example mocks a client-side public key generated by the user to demo the
otpLogin returned jwt user session.
- These are all activities that should be initiated by the parent oeganization key, the specific organization id is targeted within the
otp_login activity. For details, check out our documentation.
1/ Setting up Turnkey
The first step is to set up your Turnkey organization and account. By following the Quickstart guide, you should have:
- A public/private API key pair for Turnkey parent organization
- An organization ID
Once you've gathered these values, update them in the main.go scripts, you'll see placeholders like this <parent_org_id>.
2/ Running the scripts
cd go-sdk/examples/email_otp
# Run the script
go run init_otp/main.go
The script with do the following:
- Send the OTP code to the specified email address
- Wait for you to input the OTP code
- Verify the OTP code and generate the verification token
- Login into a suborganization using the verification token, client side API key and issue the user session jwt