@@ -120,19 +120,30 @@ export interface GitHubProfile {
120
120
* :::
121
121
*/
122
122
export default function GitHub (
123
- config : OAuthUserConfig < GitHubProfile >
123
+ config : OAuthUserConfig < GitHubProfile > & {
124
+ /** Configuration for usage with [GitHub Enterprise Server](https://docs.github.com/en/enterprise-server/get-started). */
125
+ enterprise ?: {
126
+ /** The base URL of your GitHub Enterprise Server instance. */
127
+ baseUrl ?: string
128
+ }
129
+ }
124
130
) : OAuthConfig < GitHubProfile > {
131
+ const baseUrl = config . enterprise ?. baseUrl ?? "https://github.com"
132
+ const apiBaseUrl = config . enterprise ?. baseUrl
133
+ ? `${ config . enterprise ?. baseUrl } /api/v3`
134
+ : "https://api.github.com"
135
+
125
136
return {
126
137
id : "github" ,
127
138
name : "GitHub" ,
128
139
type : "oauth" ,
129
140
authorization : {
130
- url : "https://github.com/ login/oauth/authorize" ,
141
+ url : ` ${ baseUrl } / login/oauth/authorize` ,
131
142
params : { scope : "read:user user:email" } ,
132
143
} ,
133
- token : "https://github.com/ login/oauth/access_token" ,
144
+ token : ` ${ baseUrl } / login/oauth/access_token` ,
134
145
userinfo : {
135
- url : "https://api.github.com/ user" ,
146
+ url : ` ${ apiBaseUrl } / user` ,
136
147
async request ( { tokens, provider } ) {
137
148
const profile = await fetch ( provider . userinfo ?. url as URL , {
138
149
headers : {
@@ -144,7 +155,7 @@ export default function GitHub(
144
155
if ( ! profile . email ) {
145
156
// If the user does not have a public email, get another via the GitHub API
146
157
// See https://docs.github.com/en/rest/users/emails#list-public-email-addresses-for-the-authenticated-user
147
- const res = await fetch ( "https://api.github.com/ user/emails" , {
158
+ const res = await fetch ( ` ${ apiBaseUrl } / user/emails` , {
148
159
headers : {
149
160
Authorization : `Bearer ${ tokens . access_token } ` ,
150
161
"User-Agent" : "authjs" ,
0 commit comments