GitHub sign-in
Set up GitHub sign-in end to end — provider console, backend config, frontend wiring.
The oauth/github adapter implements Signet's public OAuthProvider interface. It uses PKCE,
requests the user:email scope, and reads the User ID from /user plus the primary email from
/user/emails.
1. Create the GitHub OAuth app
- On GitHub, open Settings → Developer settings → OAuth Apps → New OAuth App.
- Fill in an Application name and the Homepage URL (your app origin, e.g.
https://app.example.com). - Set the Authorization callback URL to
https://api.example.com/auth/oauth/callback(adjust for yourPathPrefix). - Register the app, then Generate a new client secret. Copy the Client ID and the
secret into
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETon the backend.
2. Configure the backend
import (
"encoding/base64"
"os"
"github.com/shakibdshy/signet-auth"
"github.com/shakibdshy/signet-auth/oauth/github"
)
stateKey, err := base64.StdEncoding.DecodeString(os.Getenv("SIGNET_OAUTH_STATE_KEY"))
cfg.OAuth = &signet.OAuthConfig{
Providers: []signet.OAuthProvider{
github.Provider{
ClientID: os.Getenv("GITHUB_CLIENT_ID"),
ClientSecret: os.Getenv("GITHUB_CLIENT_SECRET"),
},
},
RedirectBaseURL: "https://app.example.com",
AllowedRedirects: []string{"https://app.example.com/auth/callback"},
StateKey: stateKey, // exactly 32 bytes
}RedirectBaseURL is the origin GitHub is redirected back to; Signet builds the callback URL
from it and your PathPrefix. AllowedRedirects is an exact-match allowlist (optionally
extended with validated redirect patterns) of where users may land afterwards.
Generate the state key once with openssl rand -base64 32 and keep it stable: it is the
AES-GCM key for the sealed OAuth state, so rotating it breaks every in-flight sign-in, and
every replica serving the callback must share the same value.
The example above keeps the app and the API on one origin — Signet issues SameSite=Lax
cookies and no CORS headers, so a split browser/backend deployment needs a reverse proxy on a
single origin. See Security.
3. The browser flow
- The frontend asks the backend to start sign-in:
POST /auth/oauth/startwith{"provider": "github", "redirect": "https://app.example.com/auth/callback"}. The endpoint is anonymous and returns{"url": "..."}— the GitHub authorization URL with PKCE and a sealed, single-use state (AES-GCM underStateKey, 10-minute expiry). - Redirect the browser to that
url. GitHub authenticates the User and calls the registered callback. Signet owns that endpoint — you never implement it. - On success Signet sets the Session cookie and redirects (302) to your
redirectURL. The landing page then reads the session like any other sign-in —useSession()in a React app,GET /auth/sessionotherwise. - On failure — expired state, provider error, account conflict — the callback answers with a
JSON error body (
{"error": ..., "message": ...}) instead of a redirect, so a stale start URL simply shows that error; have the User start over.
4. Linking when the email is unverified
Signet auto-links a provider identity only when the email is verified. If GitHub reports the
primary address unverified, the callback still redirects to your redirect URL but appends
?link_token=... instead of setting a Session. Your backend consumes it with the Go API —
client.LinkOAuthAccount(ctx, signet.LinkOAuthAccountInput{UserID: ..., LinkToken: ...}),
which links the provider Account to that User after explicit consent — and the User signs in
again through GitHub, now auto-linked.
Identity details
- Provider name stored on the Account:
github(also the value the frontend passes tooauthStart). - Provider user ID: GitHub's numeric user ID, stored as a string.
- Email and verification flag come from the primary entry in
/user/emails; a primary but unverified address is not auto-linked. - A provider Account owned by another User is rejected with an account-conflict error.
Endpoints
AuthEndpoint, TokenURL, UserInfoURL and EmailsURL override the defaults. They exist for
tests; leave them empty in production.
See OAuth sign-in for the shared flow, state encryption and redirect rules.