Code samples
Copy-paste integrations for the tasks every LoginSeal-enabled app needs. For the full narrative walkthrough, see the Third-party API docs.
Sign in (Authorization Code + PKCE)
Start a sign-in by redirecting the user to the authorize endpoint with a PKCE code challenge. Save the verifier server-side keyed by state.
// @loginseal/node
import { LoginSeal } from '@loginseal/node';
const ls = new LoginSeal({ clientId: process.env.LS_CLIENT_ID });
const { url, state, verifier } = await ls.beginSignIn({ redirectUri: 'https://example.com/cb' });
session.set('ls.verifier:' + state, verifier);
res.redirect(url);# pip install loginseal
from loginseal import LoginSeal
ls = LoginSeal(client_id=os.environ['LS_CLIENT_ID'])
url, state, verifier = ls.begin_signin(redirect_uri='https://example.com/cb')
session[f'ls.verifier:{state}'] = verifier
return redirect(url)Read the signed-in user
After exchanging the code for tokens, fetch user claims with the access token. The scopes you requested determine which fields come back.
// Node.js
const { tokens } = await ls.exchange({ code, state, verifier });
const user = await ls.userInfo(tokens.access_token);
// { sub: 'u_marina_42', name: 'Marina', email_verified: true }
Age gate a flow
Request the over-18 scope as part of the authorize URL. Your callback receives a signed boolean inside the ID token, never a date of birth.
// Node.js
const { url } = await ls.beginSignIn({
redirectUri: 'https://example.com/cb',
scopes: ['openid', 'age.over_18'],
});
Anonymous session
Mint a guest session without asking for credentials. Promote it later when the user is ready.
// Unity C#
using LoginSeal;
var session = await LoginSeal.Guest.StartAsync();
await session.Storage.SetAsync("slot.1", saveData);
session.OnPromoted += (account) => Debug.Log($"Welcome, {account.DisplayName}");
Verify a webhook signature
Every webhook is signed with HMAC-SHA256. Reject the request if the signature does not match the body and your endpoint secret.
// PHP
$expected = hash_hmac('sha256', $rawBody, $endpointSecret);
if (! hash_equals($expected, $request->header('X-LoginSeal-Signature'))) {
abort(401);
}
More samples on GitHub. For full integration walkthroughs, see Third-party API.