Skip to main content

oauth

Register and authenticate a user via OAuth.

Description​

Exchanges the authorization code your app received from the OAuth provider for OneEntry tokens. Resolves to an IAuthEntity with the user's accessToken and refreshToken.

Pass the code and the same redirect_uri you used to request it. OneEntry exchanges the code using the client ID and secret stored in the auth provider settings in the admin panel, and ignores client_id, client_secret and grant_type sent in the body, so never put the client secret in browser code. The marker must belong to a provider of type oauth with an OAuth auth URL configured; otherwise the API returns 400.

Unlike auth(), oauth() does not store the returned tokens in the SDK and does not call saveFunction. To sign the user in, pass response.refreshToken to refresh(), which stores the new pair and calls saveFunction.

.oauth(

, ,

);

Parameters schema​

Schema

marker(required): string
Marker of the auth provider.
example: "email"

body(required): IOauthData
OAuth data for registration.
example:

{
"client_id": "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com",
"client_secret": "43434343434",
"code": "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g",
"grant_type": "authorization_code",
"redirect_uri": "http://localhost:3000"
}

body.client_id(required): string
The client ID for the OAuth application.
example: "34346983-luuct343473qdkqidjopdfp3eb3k4thp.apps.googleusercontent.com"

body.client_secret(required): string
The client secret for the OAuth application.
example: "43434343434"

body.code(required): string
The authorization code received from the OAuth provider.
example: "4/0AVMBsJgwewewewewewei4D7T6E_fbswxnL3g"

body.grant_type(required): string
OAuth grant type.
example: "authorization_code"

body.redirect_uri(required): string
The redirect URI for the OAuth application.
example: "http://localhost:3000"

langCode: string
Language code. Default: the langCode passed to defineOneEntry ("en_US" if none).
example: "en_US"

Examples​

Minimal example​


const body = {
,
};

const response = await AuthProvider.('google', body);

The IOauthData type in SDK 1.0.175 still requires client_id, client_secret and grant_type, so TypeScript flags this body. The platform doesn't use those fields.

Example response​

{
"userIdentifier": "john@example.com",
"authProviderIdentifier": "google",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX...",
"refreshToken": "1793092445696-10324d05-566d-4fb7..."
}

Response schema​

Schema: IAuthEntity

userIdentifier: string
User identifier (login), for example the email address.
example: "john@example.com"

authProviderIdentifier: string
Marker of the authentication provider.
example: "google"

accessToken: string
The access token for the user session.
example: "abcdef123456"

refreshToken: string
The refresh token for renewing the access token.
example: "ghijkl789012"


Try it live​

Run this method in the JS SDK sandbox. Connect your Project URL and App Token on first visit, then open:

  • OAuth: register and authenticate a user via an OAuth provider.