OAuth
OAuth sign-in with Google, Auth0, Okta, and Microsoft Entra ID.
Klai Studio currently supports OAuth login with:
googleauth0oktamicrosoft
Use OAuth when you want the provider to authenticate the user while Klai Studio still creates or updates the app user and signs them into the app.
What You Need
OAuth credentials configured for the app or tenant
A
Users.oauthIdfield in your helper file, available on theUserslayoutA callback page with the navigation slug
auth/oauthauthLoginOauthon that page'sonFormLoad
If you want Klai Studio to create users who do not already exist, you also need the onBeforeRegistration server hook. The same hook can also gate password signup; see onBeforeRegistration.
Provider Callback URL
In your OAuth provider settings, use this callback pattern:
https://your.domain.com/oauth/{provider}/callbackExamples:
https://your.domain.com/oauth/google/callbackhttps://your.domain.com/oauth/auth0/callbackhttps://your.domain.com/oauth/okta/callbackhttps://your.domain.com/oauth/microsoft/callback
Typical Flow
Add a button or link that navigates to
/oauth/{provider}.The provider authenticates the user and returns to Klai Studio.
Klai Studio redirects the browser to your
auth/oauthpage.Your
auth/oauthpage runsauthLoginOauth.Klai Studio stores the token and continues through the normal login flow.
Callback Page
Add authLoginOauth to the page's onFormLoad action:
oauthLoginHook is a legacy alias and is still supported, but authLoginOauth is the preferred name.
How User Matching Works
Klai Studio looks up users by email from the provider response.
If the user already exists, Klai Studio updates
oauthIdwhen needed and signs the user in.If the user does not exist, Klai Studio calls
onBeforeRegistration.New user creation only continues when that hook returns
model.createUser = true(OAuth is fail-closed; a missing hook blocks creation).New users created through OAuth are automatically verified.
Minimal Login Example
Start the flow with a path action:
Notes
If OAuth login fails, Klai Studio returns an
errorMessageto the callback page andauthLoginOauthsends it through the normal Klai Studio error pipeline.Any query params you append to the initial OAuth URL are also available to
onBeforeRegistrationif you need them for registration logic.For an Auth0-specific walkthrough, see Setting Up Auth0.
For Microsoft Entra ID (Office 365), see Setting Up Microsoft Entra ID.
Last updated
Was this helpful?