Skip to content

Commit bb02f4a

Browse files
authored
feat: support GitHub Enterprise Server and GHE.com (#383)
1 parent 34227d8 commit bb02f4a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/runtime/server/lib/oauth/github.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export interface OAuthGitHubConfig {
4242
*/
4343
tokenURL?: string
4444

45+
/**
46+
* GitHub API URL
47+
* @default 'https://api.github.com'
48+
*/
49+
apiURL?: string
50+
4551
/**
4652
* Extra authorization parameters to provide to the authorization URL
4753
* @see https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#1-request-a-users-github-identity
@@ -62,6 +68,7 @@ export function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OA
6268
config = defu(config, useRuntimeConfig(event).oauth?.github, {
6369
authorizationURL: 'https://github.com/login/oauth/authorize',
6470
tokenURL: 'https://github.com/login/oauth/access_token',
71+
apiURL: 'https://api.github.com',
6572
authorizationParams: {},
6673
}) as OAuthGitHubConfig
6774

@@ -117,7 +124,7 @@ export function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OA
117124
const accessToken = tokens.access_token
118125
// TODO: improve typing
119126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120-
const user: any = await $fetch('https://api.github.com/user', {
127+
const user: any = await $fetch(`${config.apiURL}/user`, {
121128
headers: {
122129
'User-Agent': `Github-OAuth-${config.clientId}`,
123130
'Authorization': `token ${accessToken}`,
@@ -128,7 +135,7 @@ export function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OA
128135
if (!user.email && config.emailRequired) {
129136
// TODO: improve typing
130137
// eslint-disable-next-line @typescript-eslint/no-explicit-any
131-
const emails: any[] = await $fetch('https://api.github.com/user/emails', {
138+
const emails: any[] = await $fetch(`${config.apiURL}/user/emails`, {
132139
headers: {
133140
'User-Agent': `Github-OAuth-${config.clientId}`,
134141
'Authorization': `token ${accessToken}`,

0 commit comments

Comments
 (0)