OAuth providers
OAuth
An app session identifies your signed-in user. A provider grant lets your server call a provider’s API. Your application owns accounts, claims, and permission policy; an OAuth strategy connects provider verification to that policy.
| Your app needs | Strategy |
|---|---|
| Sign in with an existing account link | OAuth.make() |
| Sign in and retain API access | OAuth.make({ access: profile }) |
| Register an account after provider verification | OAuth.makeRegistration({ registration, registrationPolicy }) |
| List, link, and unlink login methods | OAuth.makeAccounts({ policy }) |
| Connect an API for a signed-in account | OAuth.makeConnected({ policy }) |
Sign in and retain provider access
Section titled “Sign in and retain provider access”import { Auth, Sessions } from "@yielded/auth";import { OAuth } from "@yielded/auth/strategies";import * as GitHub from "@yielded/auth/GitHub";import { AuthApi } from "@app/domain/auth-contract";import { clientId } from "./config";
const profile = GitHub.accessProfile({ clientId, scopes: ["read:user"] });
export const AppAuth = Auth.make(AuthApi, { sessions: Sessions.stateful(), strategies: { social: OAuth.make({ access: profile }) }, defaultStrategy: "social",});Omit access for sign-in only. With it, the strategy encrypts and saves the provider
grant before completing authentication through your configured session authority.
Browser
Start sign-in
Provider
Authenticate and approve access
Yielded Auth
Verify the callback and exchange the code
Your storage
Resolve the account and save the encrypted grant
Yielded Auth
Complete authentication and deliver the session
Declare the OAuth actions, then configure
Http.make with GitHub.provider({ clientId, clientSecret, access: [profile] }).
Supply persistence, claims, crypto and keys
through Layers. AuthPersistence.make(AppAuth).managed({ prefix, subjects }) supplies
OAuth storage and shared authentication authority on composed SQL and Drizzle
drivers, including D1. Export its tables and apply migrations as shown in the
storage guide.
The runnable explicit composition
shows provider configuration and application-owned services.
Retained sign-in requires an existing account link. Register new users first, then connect provider access after authentication. After a failed or uncertain callback, start a fresh sign-in; authorization codes are single-use.
Import existing identities
Section titled “Import existing identities”When moving existing users from another auth provider, create their application
subjects first, then import each verified provider identity. Composed
AuthPersistence.layer supplies OAuthPersistence.IdentityImports for configured
OAuth sign-in strategies with managed or mapped tables, including D1:
import { OAuthPersistence } from "@yielded/auth-persistence";import { Effect, Schema } from "effect";
const importGitHub = Effect.gen(function* () { const imports = yield* OAuthPersistence.IdentityImports; const identity = yield* Schema.decodeEffect(OAuthPersistence.IdentityImport)({ moduleId: AppAuth.strategies.social.persistence.moduleId, subjectId: "existing-user", provider: "github", issuer: "https://github.com/login/oauth", subject: "12345678", });
return yield* imports.importIdentity(identity);});Run this in your trusted migration job with the same persistence Layer as sign-in.
Use the exact provider key, issuer and durable subject emitted by your configured
adapter: GitHub’s numeric user ID as a string with https://github.com/login/oauth,
or Google’s sub with https://accounts.google.com. Email and display names do not establish
ownership. Keep this service outside public routes.
The import atomically stores ownership, the login credential and shared authority.
The next sign-in returns the existing subject through the normal session flow.
An exact retry returns the same credential; conflicting ownership, inactive or
missing subjects, and inconsistent records fail with OAuthUnavailable.
See the import contract for commit and key details.
Use the session and provider access
Section titled “Use the session and provider access”Under the HTTP middleware, use the regular Auth API:
const auth = yield* AppAuth;const session = yield* auth.requireSession;const connections = yield* auth.listAccountConnections({ limit: 20 });Use the connected service for server-side API calls:
const access = yield* AppAuth.strategies.social.access.ConnectedAccess;yield* access.withAccessToken(invocation, { grantId, profileKey: profile.key }, readProfile);Provide AppAuth.strategies.social.access.accessLayer with the connected services.
invocation comes from a verified session or trusted job authority. The service checks access and refreshes
when supported; readProfile receives a redacted token. Keep provider tokens on the
server and handle retries of your API work explicitly.
auth.disconnectAccount stops future local use. Provider revocation depends on the
profile and its maintenance worker. See retained access
for configuration and recovery.
Register new users
Section titled “Register new users”Use OAuth.makeRegistration({ registration, registrationPolicy }) with your
application’s registration Schema. An unknown provider identity returns
RegistrationRequired. Collect the application details and call register using
the returned flow and reference.
Registration returns RegistrationAccepted by default; start a fresh auth.signIn
to establish a session. To continue authentication immediately, set authenticate: true
on the strategy and its AuthContract.oauthRegister action. Replays remain
credential-free. See registration
for configuration and recovery, and GitHub email
when account provisioning requires an address.
Show linked login methods
Section titled “Show linked login methods”Add OAuth.makeAccounts({ policy }) under an accounts strategy with the same
namespace and login persistence as sign-in:
const page = yield* auth.listLinkedAccounts("accounts", { limit: 20 });// page.items: { credentialId, provider, issuer, subject }[]Use an item’s credentialId with unlinkAccount. Linking preserves the session;
unlinking applies the configured invalidation policy. listAccountConnections
lists retained API grants separately.
Expose the query to HTTP and Effect Atom through your shared contract:
listLinkedAccounts: AuthContract.oauthListLinkedAccounts({ strategy: "accounts" })Named mutations refresh named queries automatically. The client guide covers custom invalidation, and the account reference covers pagination.
Shared sign-in across applications
Section titled “Shared sign-in across applications”Use OAuthServer.makeOpenId("identity") when one service owns identity and several
applications consume it. Each application registers an exact callback, verifies the
OpenID exchange, and creates its own local session and permissions.
- External: Provider
- Your code: Identity service
- Yielded Auth: OpenID + consent
OAuthServer.makeOpenId( …) - Your code: Your applicationIts own account and session
- Provider to Identity service: Provider sign-in
- Identity service to OpenID + consent: Verified session
- OpenID + consent to Your application: Code + PKCE
Provide Identity.current, Identity.active, and Identity.profile, durable grant
storage, signing keys, and client registrations. An optional OpenIdConsent service
recognizes application-approved consent. Each application’s local session has its
own logout policy. See the OpenID reference
and hosted example.
Local and preview environments
Section titled “Local and preview environments”OAuthProxy lets localhost and preview deployments share one provider callback.
The callback server holds provider credentials; each application keeps its own
accounts, cookies, and sessions.
Register each application’s exact completion URL and a separate secret on the callback server, then configure the application provider:
import { OAuthProxy } from "@yielded/auth";import { proxySecret } from "./config";
export const github = OAuthProxy.provider({ url: "https://auth.example.com/oauth-proxy", environment: "local", secret: proxySecret, issuer: "https://github.com/login/oauth",});Pass this provider to Http.layer. The proxy supports sign-in and registration;
use native providers for account linking or retained API access. See the
callback proxy reference and
runnable composition.
Authorize MCP clients
Section titled “Authorize MCP clients”OAuthServer lets a signed-in user grant a Model Context Protocol (MCP) client
access to your application. Your app session identifies the user, the MCP grant
authorizes the client, and any upstream provider grant stays on your server.
import { OAuthScope, OAuthServer } from "@yielded/auth";
const ReadAthlete = OAuthScope.make("athlete:read");const oauth = OAuthServer.make("mcp", { scopes: [ReadAthlete] });
const protectedMcp = McpServer.toolkit(toolkit).pipe( Layer.provide(handlers), Layer.provide( McpServer.layerHttp({ name: "Athlete tools", version: "1.0.0", path: "/mcp", protocols: [McpProtocol.v2026_07_28], }), ), Layer.provide(oauth.middleware([ReadAthlete]).layer),);Mount the authorization routes beside the protected MCP routes. Supply a service
that verifies your existing session, grant storage, signing keys, and an HTTP client.
Inside handlers, require oauth.CurrentAccess and apply your application
permissions. Resolve provider connections from trusted storage when tools need
upstream API access.
An HttpApi resource annotates its shared groups with OAuthScope.Required, attaches
OAuthScope.RequireAccess, and provides oauth.securityLayer(Api) on the server; see
protecting resources.
Clients can be pre-registered, stored by your application behind oauth.Clients,
or use a Client ID Metadata Document.
For metadata discovery, configure clientMetadata.allowedOrigins and an HTTP client
that restricts network destinations. See the server reference
for options and supported protocol behavior, and the
Strava MCP example
for complete Layer construction.
Other providers
Section titled “Other providers”First-party OpenID presets share discovery and ID-token verification:
- Apple
- Okta, Auth0, Keycloak, Zitadel, and Cognito
- Discord
- GitLab, including self-hosted issuers
- Hugging Face
- LINE
- Linear, Dropbox, and Notion
- Microsoft Entra ID
- Railway
- Roblox
- Slack
- Vercel
- Zoom
Atlassian, Figma, Kick, and X sign in with authorization-code PKCE and one identity GET.
Use OpenIdConnect.provider for other OIDC issuers or plain OAuth endpoints.
Configure identity decoding, scopes, and any retained-access contract explicitly;
see provider configuration. OpenID Connect
providers resolve discovery lazily on first use so server startup succeeds while
an identity provider is unavailable. Call ready?.() on OAuthProtocol (and
OAuthConnectedProtocol for retained access) during startup when you want
fail-fast metadata validation:
const warmUp = Effect.gen(function* () { const protocol = yield* OAuthProtocol; yield* protocol.ready?.() ?? Effect.void;});Declare a profiles schema map on the strategy for typed providerData in
SessionClaims.resolve. Provider display data never authorizes account linking by
email. See provider profiles and the
combined login example.