diff --git a/packages/core/src/oauth/index.ts b/packages/core/src/oauth/index.ts index 64e0397..96d751e 100644 --- a/packages/core/src/oauth/index.ts +++ b/packages/core/src/oauth/index.ts @@ -12,6 +12,7 @@ import { gitlab } from "./gitlab.js" import { spotify } from "./spotify.js" import { x } from "./x.js" import { strava } from "./strava.js" +import { notion } from "./notion.js" export { github, type GitHubProfile } from "./github.js" export { bitbucket, type BitbucketProfile } from "./bitbucket.js" @@ -21,6 +22,7 @@ export { gitlab, type GitLabProfile } from "./gitlab.js" export { spotify, type SpotifyProfile } from "./spotify.js" export { x, type XProfile } from "./x.js" export { strava, type StravaProfile, type SummaryClub, type SummaryGear } from "./strava.js" +export { notion, type NotionProfile, type Bot, type Owner, type Person, type User } from "./notion.js" export const builtInOAuthProviders = { github, @@ -31,6 +33,7 @@ export const builtInOAuthProviders = { spotify, x, strava, + notion, } const defineOAuthEnvironment = (oauth: string) => { diff --git a/packages/core/src/oauth/notion.ts b/packages/core/src/oauth/notion.ts new file mode 100644 index 0000000..9a9c1b8 --- /dev/null +++ b/packages/core/src/oauth/notion.ts @@ -0,0 +1,63 @@ +import { OAuthProviderConfig } from "@/@types/index.js" + +export interface Person { + email: string +} + +export interface User { + object: "user" + id: string + name: string + avatar_url: string | null + type: "person" + person: Person +} + +export interface Owner { + type: "user" + user: User +} + +export interface Bot { + owner: Owner +} + +/** + * @see [Notion - Retrieve your token's bot user](https://developers.notion.com/reference/get-self) + */ +export interface NotionProfile { + object: "user" + id: string + name: string + avatar_url: string | null + type: "bot" + bot: Bot +} + +/** + * @see [Notion - Developer Documentation](https://developers.notion.com/) + * @see [Notion - Authorization](https://developers.notion.com/docs/authorization) + * @see [Notion - Authentication](https://developers.notion.com/reference/authentication) + * @see [Notion - Retrieve your token's bot user](https://developers.notion.com/reference/get-self) + * @todo: It's required to pass the Notion-Version header to access the user info endpoint. + * headers: { Notion-Version: "2022-06-28" } + * @todo: It's required to add Basic headers for access token request. + * headers: { Authorization: "Basic base64(client_id:client_secret)" } + */ +export const notion: OAuthProviderConfig = { + id: "notion", + name: "Notion", + authorizeURL: "https://api.notion.com/v1/oauth/authorize?owner=user", + accessToken: "https://api.notion.com/v1/oauth/token", + userInfo: "https://api.notion.com/v1/users/me", + scope: "user:read", + responseType: "code", + profile(profile) { + return { + sub: profile.id, + name: profile.name, + image: profile.avatar_url ?? "", + email: profile?.bot?.owner?.user?.person?.email, + } + }, +}