SSO with Google and GitHub
Single sign-on (SSO): let people sign in with Google or GitHub, with PKCE, and link those sign-ins to an existing account.
On this page
SSO (single sign-on): people sign in with an account they already have, so your project does not have to send e-mails at all: the provider has already checked the person. The providers are Google (OpenID Connect) and GitHub (OAuth 2.0).
Set it up
- Create an OAuth app at the provider:
- Google: Google Cloud console → APIs & Services → Credentials → OAuth client ID (Web application).
- GitHub: Settings → Developer settings → OAuth Apps → New.
- As the callback (redirect) URL, use
https://<ref>.data.sypnia.com/auth/v1/callback(self-hosted: your engine’s address). - In the console → Auth → Providers (or
PATCH /auth/v1/admin/settings), paste the client id and secret. The secret is stored encrypted.
The flow (PKCE)
await sypnia.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: 'https://myapp.com/auth/done' } });
// on /auth/done:
await sypnia.auth.exchangeCodeForSession(new URL(location.href).searchParams.get('code')!);- The SDK makes a random code verifier, keeps it, and opens
/auth/v1/authorize?provider=google&code_challenge=…&code_challenge_method=S256. - The engine sends the person to Google, with its own
stateandnonce. - Google returns to
/auth/v1/callback; the engine checksstate, exchanges the code with Google and reads the verified e-mail. - The engine redirects to your
redirectTowith a one-time?code=. - Your app exchanges that code and the verifier for a session. Someone who steals the code cannot use it without the verifier.
Identities and linking
A sign-in with a provider is an identity (sypnia_auth.identities). One user can have several: e-mail, Google and GitHub.
- If the provider gives a verified e-mail that matches an existing user, the identity is linked to that user.
- An unverified e-mail is never linked; a new user is created instead.
- A signed-in user can link another provider with
linkIdentity({ provider })and unlink it, as long as one way to sign in remains.