Skip to main content
Authorize OAuth
Initiates an OAuth 2.0 authorization flow for unauthenticated users (sign-in or sign-up). Returns an authorization URL that the client should redirect the browser to. Sublay sends the browser on to the provider, and after the user authenticates there, back to the redirectAfterAuth URL with tokens in the URL fragment.
The OAuth provider must be configured and enabled in the Sublay dashboard before this endpoint can be used. The redirectAfterAuth URL must be in the provider’s allowed redirect URI list.

Body Parameters

string
required
The OAuth provider to use. Must be one of: "google", "github", "apple", "facebook".
string
required
The URL to redirect the user to after authentication. Must be a valid URL and must be present in the provider’s configured allowed redirect URIs.

Response

string
The URL to send the user’s browser to, to begin the OAuth flow. It is a one-time Sublay URL that redirects to the provider; it expires after 10 minutes.
Open authorizationUrl as-is, in the browser (or auth session) that should end up signed in. It points to Sublay first, which ties the sign-in to that browser and then sends it on to the provider. A sign-in that returns to a different browser is refused with error=state_mismatch, and so is the older of two sign-ins started at the same time in one browser (in any app that uses Sublay). An Apple sign-in doesn’t affect one with another provider, or the other way round.

Callback

After the user authorizes with the provider, they are redirected to redirectAfterAuth with one of: On success — Tokens in the URL fragment:
On error — Error details in query parameters:
error=state_mismatch means the browser that returned from the provider isn’t the one that opened authorizationUrl (for example, the return link was opened somewhere else), so the sign-in is refused. Start the sign-in again. error=state_expired means the sign-in took too long (10 minutes at the provider; for a link, at most 30 minutes in all). error=email_not_verified means the provider’s email belongs to an existing user but the provider hasn’t verified it, so the sign-in can’t be connected to that account. error_description says so in words you can show the user: verify the email with the provider, or sign in the way they originally signed up. error=account_email_not_confirmed means the project requires email verification before sign-in and the Sublay account this sign-in leads to has a password and an email that isn’t confirmed yet (the REST equivalent is 403 auth/email-not-verified). No session is created. A confirmation link is emailed to the address on the account (unless one went out in the last 10 minutes), and error_description says so: “Confirm your email to sign in. We’ve sent a confirmation link to the email on this account.” The two are different: email_not_verified is about the provider’s email, account_email_not_confirmed about the Sublay account’s own email. error=link_needs_confirmed_email comes from linking a provider, not from a sign-in; see that page.

Error Responses

See Also