Configure hosted sign-in
Register the exact callback URL and your web origin for your sandbox application. Obtain its runtime URL as described in the overview. This example uses the browser’s cryptography APIs and requires HTTPS, or localhost in sandbox. The application ownsstate and the PKCE verifier. Hosted sign-in owns password, email, passkey, phone, SSO and required MFA screens. No API key belongs in this code.
auth.js
signIn() from your sign-in button. On the registered callback page, call handleCallback() once, render a loading state, and show its error if it fails. Use getSession() for the current user and signOut() for logout. The callback removes its code from the address bar before making a request.
This minimal example keeps tokens in memory and signs in again after a page reload or access-token expiry. For persistent sessions, use your backend and secure cookies or implement serialized refresh rotation. Never put refresh tokens in URLs or logs. A frontend session check controls presentation only; your backend must validate the caller on every protected request.
Authentication SDK release preview
The planned@didit-protocol/auth core exposes createDiditAuth({publishableKey}), signIn(), handleRedirectCallback(), getSession(), getToken(), onAuthStateChange and signOut(), with vendorData on the identity. It is intended to add automatic device signals and a server entry point with verifyToken().
Do not install a guessed version or write against guessed callback options. Confirm the published package exports, issuer and key configuration before replacing the hosted example. Password, email code, magic link, passkey, phone, MFA, social sign-in, step-up and agent methods will depend on that release’s supported API.
Add other products
Your backend maps the verified Authenticationsub to its stable person reference. Use it as vendor_data when creating a verification session or minting a transaction token. A successful sign-in does not imply either product approved the user.
Before shipping, exercise sign-up, returning sign-in, cancellation, mismatched state, reused code, forgot password, MFA, expiry and logout against your enabled sandbox application.