11import type { IdentityProvider } from "@/auth" ;
22import { onCreateUser } from "@/lib/authUtils" ;
3+ import { getRequiredScopes } from "@/lib/oauthScopes" ;
34import { prisma } from "@/prisma" ;
45import { AuthentikIdentityProviderConfig , GCPIAPIdentityProviderConfig , GitHubIdentityProviderConfig , GitLabIdentityProviderConfig , GoogleIdentityProviderConfig , KeycloakIdentityProviderConfig , MicrosoftEntraIDIdentityProviderConfig , OktaIdentityProviderConfig } from "@sourcebot/schemas/v3/index.type" ;
5- import { createLogger , env , getTokenFromConfig , hasEntitlement , loadConfig } from "@sourcebot/shared" ;
6+ import { createLogger , env , getTokenFromConfig , loadConfig } from "@sourcebot/shared" ;
67import { OAuth2Client } from "google-auth-library" ;
78import type { User as AuthJsUser } from "next-auth" ;
89import type { Provider } from "next-auth/providers" ;
@@ -126,19 +127,10 @@ const createGitHubProvider = (clientId: string, clientSecret: string, baseUrl?:
126127 ...( hostname === GITHUB_CLOUD_HOSTNAME ? { enterprise : { baseUrl : baseUrl } } : { } ) , // if this is set the provider expects GHE so we need this check
127128 authorization : {
128129 params : {
129- scope : [
130- 'read:user' ,
131- 'user:email' ,
132- // Permission syncing requires the `repo` scope in order to fetch repositories
133- // for the authenticated user.
134- // @see : https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repositories-for-the-authenticated-user
135- ...( env . EXPERIMENT_EE_PERMISSION_SYNC_ENABLED === 'true' && hasEntitlement ( 'permission-syncing' ) ?
136- [ 'repo' ] :
137- [ ]
138- ) ,
139- ] . join ( ' ' ) ,
130+ scope : getRequiredScopes ( 'github' ) ,
140131 } ,
141132 } ,
133+ allowDangerousEmailAccountLinking : true ,
142134 } ) ;
143135}
144136
@@ -150,16 +142,7 @@ const createGitLabProvider = (clientId: string, clientSecret: string, baseUrl?:
150142 authorization : {
151143 url : `${ url } /oauth/authorize` ,
152144 params : {
153- scope : [
154- "read_user" ,
155- // Permission syncing requires the `read_api` scope in order to fetch projects
156- // for the authenticated user and project members.
157- // @see : https://docs.gitlab.com/ee/api/projects.html#list-all-projects
158- ...( env . EXPERIMENT_EE_PERMISSION_SYNC_ENABLED === 'true' && hasEntitlement ( 'permission-syncing' ) ?
159- [ 'read_api' ] :
160- [ ]
161- ) ,
162- ] . join ( ' ' ) ,
145+ scope : getRequiredScopes ( 'gitlab' ) ,
163146 } ,
164147 } ,
165148 token : {
@@ -168,13 +151,15 @@ const createGitLabProvider = (clientId: string, clientSecret: string, baseUrl?:
168151 userinfo : {
169152 url : `${ url } /api/v4/user` ,
170153 } ,
154+ allowDangerousEmailAccountLinking : true ,
171155 } ) ;
172156}
173157
174158const createGoogleProvider = ( clientId : string , clientSecret : string ) : Provider => {
175159 return Google ( {
176160 clientId : clientId ,
177161 clientSecret : clientSecret ,
162+ allowDangerousEmailAccountLinking : true ,
178163 } ) ;
179164}
180165
@@ -183,6 +168,7 @@ const createOktaProvider = (clientId: string, clientSecret: string, issuer: stri
183168 clientId : clientId ,
184169 clientSecret : clientSecret ,
185170 issuer : issuer ,
171+ allowDangerousEmailAccountLinking : true ,
186172 } ) ;
187173}
188174
@@ -191,6 +177,7 @@ const createKeycloakProvider = (clientId: string, clientSecret: string, issuer:
191177 clientId : clientId ,
192178 clientSecret : clientSecret ,
193179 issuer : issuer ,
180+ allowDangerousEmailAccountLinking : true ,
194181 } ) ;
195182}
196183
@@ -199,6 +186,7 @@ const createMicrosoftEntraIDProvider = (clientId: string, clientSecret: string,
199186 clientId : clientId ,
200187 clientSecret : clientSecret ,
201188 issuer : issuer ,
189+ allowDangerousEmailAccountLinking : true ,
202190 } ) ;
203191}
204192
@@ -283,5 +271,6 @@ export const createAuthentikProvider = (clientId: string, clientSecret: string,
283271 clientId : clientId ,
284272 clientSecret : clientSecret ,
285273 issuer : issuer ,
274+ allowDangerousEmailAccountLinking : true ,
286275 } ) ;
287276}
0 commit comments