Crear sesión con token de ID
Allow the user to login to their account using an OpenID Connect ID token obtained natively from the OAuth2 provider, for example via Google Credential Manager on Android or Sign in with Apple on iOS.
/account/sessions/id-tokenAlcance sessions.writeAllow the user to login to their account using an OpenID Connect ID token obtained natively from the OAuth2 provider, for example via Google Credential Manager on Android or Sign in with Apple on iOS. No browser or redirect is involved: the ID token is verified against the provider’s published signing keys and a session is created in a single request.
Native sign-in is switched on per provider with its nativeEnabled setting. It is independent of the browser-based flow’s enabled setting, which has no effect on this endpoint. The token’s audience must match the provider’s configured client ID or one of its native client IDs; tokens issued for any other client ID are rejected. For Sign in with Apple, register your app’s bundle ID as a native client ID. For Google, the web client ID used by Credential Manager is usually the configured client ID; add your Android and iOS client IDs as native client IDs if your app requests tokens for them.
Pass the raw nonce used when requesting the ID token so it can be validated against the token’s nonce claim. When signing in with Apple, the nonce is required: hash it with SHA-256 before passing it to the Apple SDK, and send the raw value here - Apple tokens requested without a nonce are rejected. For Google the nonce is optional: it is validated whenever the token carries one, and ignored when the provider issued the token without one. Apple only returns the user’s name on the first authorization, and never inside the ID token - capture it on the client and pass it via the name parameter.
If there is already an active session, the new session will be attached to the logged-in account. If there are no active sessions, the server will attempt to look for a user with the same email address as the verified email received from the provider and attach the new session to the existing user. If no matching user is found - the server will create a new user.
This flow does not return provider refresh tokens. You may pass an access token the provider handed your client, along with its lifetime, to store it on the session - but Owbase cannot renew it once it expires. If your app needs long-lived access to provider APIs, use the browser-based OAuth2 flow instead.
A user is limited to 10 active sessions at a time by default. Learn more about session limits.
Parámetros
Sección titulada «Parámetros»provider IdTokenProvider obligatorio
OAuth2 provider that issued the ID token. Currently, supported providers are: apple, google. Valores: apple, google.
idToken string obligatorio
OpenID Connect ID token (JWT) obtained natively from the provider, for example via Google Credential Manager or Sign in with Apple.
nonce string
Raw nonce used when requesting the ID token. Required for Apple, and whenever the token carries a nonce claim, which must match it. Ignored when the provider issued the token without a nonce.
accessToken string
Provider access token to store alongside the session for calling provider APIs. Never used for authentication.
accessTokenExpiry number
Seconds until the provider access token expires, as reported by the provider. Stored so clients can tell when the stored token goes stale.
name string
User name. Only used when creating a new user and the ID token has no name claim, such as on the first Sign in with Apple authorization.
Acceso: sin clave ni sesión: basta el ID del proyecto.
Respuestas
Sección titulada «Respuestas»201Éxito400Parámetro inválido o faltante401Sin sesión, sin permiso en el recurso o clave sin el alcance429Límite de peticionesTodo error llega como JSON con code, type y message: consulta Errores.
import { Client, Account, IdTokenProvider } from '@owbase/web';
const client = new Client() .setEndpoint('https://cloud.owbase.dev/v1') // Your API Endpoint .setProject('<YOUR_PROJECT_ID>'); // Your project ID
const account = new Account(client);
const result = await account.createIdTokenSession({ provider: IdTokenProvider.Apple, idToken: '<ID_TOKEN>', nonce: '<NONCE>', // optional accessToken: '<ACCESS_TOKEN>', // optional accessTokenExpiry: 0, // optional name: '<NAME>', // optional});
console.log(result);import { Client, Account, IdTokenProvider } from '@owbase/node';
const client = new Client() .setEndpoint('https://cloud.owbase.dev/v1') // Your API Endpoint .setProject('<YOUR_PROJECT_ID>') // Your project ID .setSession(''); // The user session to authenticate with
const account = new Account(client);
const result = await account.createIdTokenSession({ provider: IdTokenProvider.Apple, idToken: '<ID_TOKEN>', nonce: '<NONCE>', // optional accessToken: '<ACCESS_TOKEN>', // optional accessTokenExpiry: 0, // optional name: '<NAME>', // optional});curl -X POST "https://cloud.owbase.dev/v1/account/sessions/id-token" \ -H "X-Owbase-Project: <PROJECT_ID>" \ -H "X-Owbase-Session: <SESSION>" \ -H "Content-Type: application/json" \ -d '{"provider":"apple","idToken":"<ID_TOKEN>"}'{ "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", "$updatedAt": "2020-10-15T06:38:00.000+00:00", "userId": "5e5bb8c16897e", "expire": "2020-10-15T06:38:00.000+00:00", "provider": "email", "providerAccessToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", "providerAccessTokenExpiry": "2020-10-15T06:38:00.000+00:00", "providerRefreshToken": "MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3", "ip": "127.0.0.1", "osCode": "Mac", "osName": "Mac", "osVersion": "Mac", "clientType": "browser", "clientCode": "CM", "clientName": "Chrome Mobile iOS", "clientVersion": "84.0", "clientEngine": "WebKit", "clientEngineVersion": "605.1.15", "deviceName": "smartphone", "deviceBrand": "Google", "deviceModel": "Nexus 5", "countryCode": "US", "countryName": "United States", "current": true, "factors": [ "email" ], "secret": "5e5bb8c16897e", "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00"}Las descripciones de esta página vienen de la especificación de la API del servidor (licencia BSD-3-Clause), en inglés, y los ejemplos vienen del generador de SDKs (licencia MIT). Los avisos completos están en el archivo NOTICE de los paquetes @owbase/web y @owbase/node.