@@ -1140,17 +1140,7 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
1140
1140
}
1141
1141
1142
1142
if user .ID != uuid .Nil && user .LoginType != params .LoginType {
1143
- addedMsg := ""
1144
- if user .LoginType == database .LoginTypePassword {
1145
- addedMsg = " You can convert your account to use this login type by visiting your account settings."
1146
- }
1147
- return httpError {
1148
- code : http .StatusForbidden ,
1149
- renderStaticPage : true ,
1150
- msg : "Incorrect login type" ,
1151
- detail : fmt .Sprintf ("Attempting to use login type %q, but the user has the login type %q.%s" ,
1152
- params .LoginType , user .LoginType , addedMsg ),
1153
- }
1143
+ return wrongLoginTypeHTTPError (user .LoginType , params .LoginType )
1154
1144
}
1155
1145
1156
1146
// This can happen if a user is a built-in user but is signing in
@@ -1373,17 +1363,7 @@ func (api *API) convertUserToOauth(ctx context.Context, r *http.Request, db data
1373
1363
1374
1364
// If we do not allow converting to oauth, return an error.
1375
1365
if ! api .Experiments .Enabled (codersdk .ExperimentConvertToOIDC ) {
1376
- addedMsg := ""
1377
- if user .LoginType == database .LoginTypePassword {
1378
- addedMsg = " You can convert your account to use this login type by visiting your account settings."
1379
- }
1380
- return database.User {}, httpError {
1381
- code : http .StatusForbidden ,
1382
- renderStaticPage : true ,
1383
- msg : "Incorrect login type" ,
1384
- detail : fmt .Sprintf ("Attempting to use login type %q, but the user has the login type %q.%s" ,
1385
- params .LoginType , user .LoginType , addedMsg ),
1386
- }
1366
+ return database.User {}, wrongLoginTypeHTTPError (user .LoginType , params .LoginType )
1387
1367
}
1388
1368
1389
1369
if claims .RegisteredClaims .Issuer != api .DeploymentID {
@@ -1509,3 +1489,17 @@ func clearOAuthConvertCookie() *http.Cookie {
1509
1489
MaxAge : - 1 ,
1510
1490
}
1511
1491
}
1492
+
1493
+ func wrongLoginTypeHTTPError (user database.LoginType , params database.LoginType ) httpError {
1494
+ addedMsg := ""
1495
+ if user == database .LoginTypePassword {
1496
+ addedMsg = " You can convert your account to use this login type by visiting your account settings."
1497
+ }
1498
+ return httpError {
1499
+ code : http .StatusForbidden ,
1500
+ renderStaticPage : true ,
1501
+ msg : "Incorrect login type" ,
1502
+ detail : fmt .Sprintf ("Attempting to use login type %q, but the user has the login type %q.%s" ,
1503
+ params , user , addedMsg ),
1504
+ }
1505
+ }
0 commit comments