OAuth providers
Notion
Notion.provider adds Notion public-connection sign-in to an
OAuth strategy. Identity is owner.user on the token response.
/v1/users/me is the bot and is not used. The preset does not retain Notion
API access.
Configure your Notion public connection
Section titled “Configure your Notion public connection”Create a public connection in the Notion developer portal.
Register your exact HTTPS callback, https://app.example.com/auth/notion/callback.
Notion token exchange uses HTTP Basic authentication and a JSON body. The preset
does not send PKCE. Authorize requests set owner=user.
See Notion authorization.
Load the credentials while building the server Layer:
import { Config, Effect, Layer } from "effect";import { Http, Notion } from "@yielded/auth";
import { AppAuth } from "./auth";
export const AuthRoutes = Layer.unwrap( Effect.gen(function* () { return Http.layer(AppAuth, { origin: yield* Config.String("APP_ORIGIN"), oauth: { providers: { notion: Notion.provider({ clientId: yield* Config.String("NOTION_CLIENT_ID"), clientSecret: yield* Config.Redacted("NOTION_CLIENT_SECRET"), }), }, }, }); }),);Supply HTTP, crypto, persistence and application services
to this Layer. Keep it alive for the server’s lifetime. Start with
auth.signIn({ provider: "notion", returnTarget: "/account" }) and redirect to
the returned authorization URL. The callback completes sign-in.
Identity
Section titled “Identity”The durable identity is (provider key, "https://api.notion.com", owner.user.id).
Keep that user id unchanged. Never link accounts merely because profile emails
match. A bot owner.user is rejected.
The decoder copies user and workspace display fields into providerData. It
does not copy access or refresh tokens from the receipt.
The preset carries NotionUserProfile. Declare the same schema on the strategy
to get typed providerData in SessionClaims.resolve:
const social = OAuth.make({ profiles: { notion: Notion.NotionUserProfile } });Notion does not advertise RFC 9207 iss; use a distinct callback URL.
Run the example
Section titled “Run the example”The Notion application uses the shared Atom browser client, SQL identity storage, and stateless sessions. It provisions one explicitly configured Notion user.
- Forward an HTTPS development origin to
127.0.0.1:3000. SetAPP_ORIGINto that public origin and register its/auth/notion/callbackURL on the public connection. - Set
NOTION_CLIENT_ID,NOTION_CLIENT_SECRET, andNOTION_USER_ID(the authorizing user’s id fromowner.user.id). - Set
SESSION_KEYandOAUTH_TRANSACTION_KEYto distinct base64url encodings of 32 random bytes. For example, runopenssl rand -base64 32 | tr '+/' '-_' | tr -d '=\n'separately for each key. Preserve these keys across restarts. - Run
vp run @yielded/example-auth#example:notionfrom the repository root and openAPP_ORIGIN/login. Sign in with the configured Notion account. - After the callback,
/accountreturns the localsubjectIdandrole: "owner". A different subject must not receive a session.
The example stores development state in examples/auth/notion-auth.sqlite. To
start over, stop the example, remove only that database and its SQLite sidecar
files, and clear cookies for the development origin.
Protocol profile
Section titled “Protocol profile”| Concern | Behavior |
|---|---|
| Issuer | Exact https://api.notion.com |
| Authorization / callback | /v1/oauth/authorize with owner=user, authorization code, query response |
| Token exchange | /v1/oauth/token, HTTP Basic, JSON body |
| Identity | owner.user on the token response; /v1/users/me is not used |
| PKCE | Not sent |
| Response issuer | Notion does not advertise RFC 9207 iss; use a distinct callback URL |
| Access | Sign-in only; no retained access in this preset |
Use registrations with one active generation and retired previous generations
for credential rotation.