Skip to main content
Link OAuth Provider
Initiates an OAuth 2.0 flow to link an additional provider to the currently authenticated user’s account. Requires the user’s own access token; a service key is refused (403 oauth/user-token-required). The flow and callback behavior are identical to the Authorize OAuth endpoint. The authenticated user’s ID is taken from the access token — it cannot be specified in the request body.

Headers

string
required
Bearer {accessToken} — a valid access token for the user linking the provider.

Body Parameters

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

Response

string
The URL to send the user’s browser to. It is a one-time Sublay URL; it expires after 10 minutes if it isn’t opened. Once opened, the user has 10 minutes for each step, and at most 30 minutes from this call.
Before going to the provider, Sublay shows the user a page naming the account the provider will be connected to (its verified email, or else its username), with Continue and Cancel. Continue goes on to the provider; Cancel returns to redirectAfterAuth with error=access_denied. The page only works in the browser that opened authorizationUrl, where it can be reloaded; anywhere else it shows that the link has expired, and so does an older link page once a newer one was opened in the same browser. The page is in English.
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 (new tokens are issued for the linked account):
On error — Error details in query parameters:
error=account_email_not_confirmed and error=email_not_verified can come back from a link too; see Authorize OAuth. error=link_needs_confirmed_email means the account’s email isn’t confirmed yet and the provider’s email is different from it, or isn’t verified by the provider. Nothing is linked. error_description: “Confirm your email before connecting a sign-in that uses a different email.” An account whose email isn’t confirmed can only link a provider whose verified email is the same as the account’s email (linking it then confirms the account’s email); a provider with any other email needs the account’s email confirmed first. Accounts with no email aren’t affected.
This rule fully protects only projects that require email verification before sign-in (Dashboard → Settings → SDK). With that setting off, a link started through the v7 API isn’t held to it.

Error Responses

The access token is still valid, but its session no longer exists (signed out, password reset, or the account was claimed by a provider sign-in after its email went unverified). Adding a provider needs a live session, so sign in again.
A service key called this endpoint, with or without actingUserId. It needs the signed-in user’s own access token.
A user token, or a request with no credentials, sent actingUserId, even naming its own user. A user token always acts as its own user. (A service key gets the 403 above instead.)

See Also