Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -31,6 +33,7 @@ export const builtInOAuthProviders = {
spotify,
x,
strava,
notion,
}

const defineOAuthEnvironment = (oauth: string) => {
Expand Down
63 changes: 63 additions & 0 deletions packages/core/src/oauth/notion.ts
Original file line number Diff line number Diff line change
@@ -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<NotionProfile> = {
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,
}
},
}