Skip to content

feat: support GitHub Enterprise Server and GHE.com #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
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
11 changes: 9 additions & 2 deletions src/runtime/server/lib/oauth/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export interface OAuthGitHubConfig {
*/
tokenURL?: string

/**
* GitHub API URL
* @default 'https://api.github.com'
*/
apiURL?: string

/**
* Extra authorization parameters to provide to the authorization URL
* @see https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#1-request-a-users-github-identity
Expand All @@ -62,6 +68,7 @@ export function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OA
config = defu(config, useRuntimeConfig(event).oauth?.github, {
authorizationURL: 'https://github.com/login/oauth/authorize',
tokenURL: 'https://github.com/login/oauth/access_token',
apiURL: 'https://api.github.com',
authorizationParams: {},
}) as OAuthGitHubConfig

Expand Down Expand Up @@ -117,7 +124,7 @@ export function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OA
const accessToken = tokens.access_token
// TODO: improve typing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const user: any = await $fetch('https://api.github.com/user', {
const user: any = await $fetch(`${config.apiURL}/user`, {
headers: {
'User-Agent': `Github-OAuth-${config.clientId}`,
'Authorization': `token ${accessToken}`,
Expand All @@ -128,7 +135,7 @@ export function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OA
if (!user.email && config.emailRequired) {
// TODO: improve typing
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const emails: any[] = await $fetch('https://api.github.com/user/emails', {
const emails: any[] = await $fetch(`${config.apiURL}/user/emails`, {
headers: {
'User-Agent': `Github-OAuth-${config.clientId}`,
'Authorization': `token ${accessToken}`,
Expand Down