Skip to content

OAuth providers

GitHub

Sign in with a GitHub OAuth App. Start with OAuth setup.

Create an OAuth App in GitHub developer settings. Set its callback URL to https://app.example.com/auth/github/callback.

apps/server/github.ts
import { Redacted } from "effect";
import * as GitHub from "@yielded/auth/GitHub";
import { Http } from "@yielded/auth";
import { AppAuth } from "./auth";
import { config } from "./config";
export const AuthRoutes = Http.layer(AppAuth, {
origin: config.AUTH_ORIGIN,
oauth: {
providers: {
github: GitHub.provider({
clientId: config.GITHUB_CLIENT_ID,
clientSecret: Redacted.make(config.GITHUB_CLIENT_SECRET),
}),
},
},
});

Supply your services and keep the Layer alive for the server’s lifetime. AuthRoutes derives the callback URL from origin. GitHub sign-in requests read:user by default.

Set verifiedPrimaryEmail: true on the provider registration to request user:email. A verified primary address becomes profile.email with profile.emailVerified: true. If none is available, your application decides whether to request an email separately or decline registration.

The numeric GitHub ID identifies the account. Email is profile data and must not be used to automatically link accounts. When retaining API access, also include user:email in the connected profile’s scopes. See email permission for the options and limits.

const auth = yield* AppAuth;
const started = yield* auth.signIn({
provider: "github",
returnTarget: "/account",
});

Redirect to Redacted.value(started.authorizationUrl). The callback signs in an existing account and returns to returnTarget. Use the registration flow for new accounts.

The browser example shows the client and Atom workflow. To retain provider tokens, configure OAuth with an access profile.