Skip to main content

Overview

Doshi webview authentication uses a secure two-step process:
  1. Generate a custom token by calling the Doshi API with your API key
  2. Pass the token to the iframe using postMessage or query parameters
IP Whitelisting Required: Your server’s IP address must be whitelisted to access the Doshi API. Contact hello@doshi.app with your server IP addresses to get started.
1

Get API Key & Whitelist IP

Contact hello@doshi.app to:
  • Receive your API key
  • Whitelist your server IP address(es)
2

Generate Custom Token

Call the authentication endpoint with your API key from your whitelisted server
3

Embed Webview

Pass the custom token to the Doshi Frontend using postMessage or query parameters
4

User Signs In

Doshi handles the sign-in process, including 2FA if enabled
These examples use the production hosts. To test against sandbox, use https://sandbox.embed.doshi.app (and https://sandbox.api.doshi.app for the API) — your client token works in both. See Environments.

Authentication Flow

Step 1: Generate Custom Token

Call the authentication endpoint with your API key:
Required Headers:
  • Authorization: Bearer YOUR_API_KEY
  • Access-Type: client
  • Content-Type: application/json

API Parameters

Required (at least one):
  • email - User’s email address
  • partnerUserId - Your internal user ID
Optional:
  • firstName - User’s first name
  • lastName - User’s last name
  • branchId - Branch or location identifier
You must provide either email OR partnerUserId (or both). All other fields are optional.
Response:
See the full API reference for details.

Setting the Starting Learning Path

By default, a new user picks their own learning path the first time they open Doshi. To skip that screen and drop them straight into a specific set of lessons, pass a pathId when you mint the token.
pathId is only accepted by /client/auth/tokennot by /client/auth/custom-token, which ignores it. Use /client/auth/token when you need a starting path.
1

Create the path

In the dashboard, go to PathsCreate, then add the courses and lessons you want the user to see.
2

Copy the path ID

On the path’s card, open the menu and choose Copy ID. The ID is also the last segment of the path’s URL (/paths/<pathId>).
3

Pass it when generating the token

Include the ID as pathId in the token request.
The user now lands directly in the lessons on that path, with no path-selection screen.

Behaviour and limits

  • Sets the initial path only. If the user already has a path, pathId is ignored — existing users are never moved. It is not a way to switch someone’s path later.
  • Don’t combine it with segment. The two write to different places, so sending both leaves the path-selection screen in place. Use one or the other.
  • The ID isn’t validated. An incorrect ID is accepted without an error and leaves the user without usable content, so confirm the flow on sandbox before going live.
  • Must be 2–50 characters.
  • Works with the 2FA flow.
pathId decides which lessons the user starts on. segment is different — it narrows which paths a user is offered when you run several paths under one organization, and still lets them choose.

Step 2: Pass Token to Doshi Frontend

Pass the nonce token to the Doshi Frontend using one of two methods:

postMessage (Recommended)

Secure, real-time communication for sensitive data

Query Parameters

Simple URL-based authentication

Frontend Parameters

Required:
  • token - The nonce token from the API
Optional:
  • email - User’s email address
  • segment - For handling multiple learning paths
  • branchId - Branch or location identifier

2FA Parameters (Optional)

When 2FA is enabled, pass these additional parameters: All 2FA fields are required when is2FaEnabled is true:
  • is2FaEnabled - Set to true
  • dob - Date of birth (YYYY-MM-DD)
  • organizationId - Your organization ID
  • partnerUserId - Your internal user ID
  • firstName - User’s first name
  • lastName - User’s last name
string
required
The nonce token received from the API
string
User’s email address (optional)
string
Used for handling multiple learning paths under the same organization (optional)
string
Branch or location identifier (optional)
boolean
Set to true to enable 2FA flow (optional, but if true, all 2FA fields below are required)
string
User’s date of birth - YYYY-MM-DD format (required when is2FaEnabled is true)
string
Your organization ID (required when is2FaEnabled is true)
string
Your internal user ID (required when is2FaEnabled is true)
string
User’s first name (required when is2FaEnabled is true)
string
User’s last name (required when is2FaEnabled is true)
When 2FA is enabled, the Doshi Frontend automatically handles the OTP send and verification flow. You don’t need to call the OTP endpoints separately.

Step 3: Session Management

Once authenticated, the Doshi Frontend automatically manages the session:
  • ID Token TTL: 1 hour
  • Refresh Token TTL: 12 hours
  • Auto-refresh: Tokens are refreshed automatically
No additional action required from your application!

Quick Example

React with postMessage

React with Query Parameters

With 2FA Enabled

Next Steps

postMessage Method

Detailed postMessage implementation

Query Parameters

URL-based authentication guide

Security

Security best practices

Need Help?

Contact Support

Get your API key or ask questions: hello@doshi.app