@@ -35,7 +35,7 @@ type Config struct {
35
35
// ID is a unique identifier for the authenticator.
36
36
ID string
37
37
// Type is the type of provider.
38
- Type codersdk. ExternalAuthProvider
38
+ Type string
39
39
// DeviceAuth is set if the provider uses the device flow.
40
40
DeviceAuth * DeviceAuth
41
41
// DisplayName is the name of the provider to display to the user.
@@ -117,7 +117,7 @@ validate:
117
117
// to the read replica in time.
118
118
//
119
119
// We do an exponential backoff here to give the write time to propagate.
120
- if c .Type == codersdk .ExternalAuthProviderGitHub && r .Wait (retryCtx ) {
120
+ if c .Type == string ( codersdk .EnhancedExternalAuthProviderGitHub ) && r .Wait (retryCtx ) {
121
121
goto validate
122
122
}
123
123
// The token is no longer valid!
@@ -173,7 +173,7 @@ func (c *Config) ValidateToken(ctx context.Context, token string) (bool, *coders
173
173
}
174
174
175
175
var user * codersdk.ExternalAuthUser
176
- if c .Type == codersdk .ExternalAuthProviderGitHub {
176
+ if c .Type == string ( codersdk .EnhancedExternalAuthProviderGitHub ) {
177
177
var ghUser github.User
178
178
err = json .NewDecoder (res .Body ).Decode (& ghUser )
179
179
if err == nil {
@@ -219,7 +219,7 @@ func (c *Config) AppInstallations(ctx context.Context, token string) ([]codersdk
219
219
return nil , false , nil
220
220
}
221
221
installs := []codersdk.ExternalAuthAppInstallation {}
222
- if c .Type == codersdk .ExternalAuthProviderGitHub {
222
+ if c .Type == string ( codersdk .EnhancedExternalAuthProviderGitHub ) {
223
223
var ghInstalls struct {
224
224
Installations []* github.Installation `json:"installations"`
225
225
}
@@ -368,24 +368,10 @@ func ConvertConfig(entries []codersdk.ExternalAuthConfig, accessURL *url.URL) ([
368
368
for _ , entry := range entries {
369
369
entry := entry
370
370
371
- var typ codersdk.ExternalAuthProvider
372
- switch codersdk .ExternalAuthProvider (entry .Type ) {
373
- case codersdk .ExternalAuthProviderAzureDevops :
374
- typ = codersdk .ExternalAuthProviderAzureDevops
375
- case codersdk .ExternalAuthProviderBitBucket :
376
- typ = codersdk .ExternalAuthProviderBitBucket
377
- case codersdk .ExternalAuthProviderGitHub :
378
- typ = codersdk .ExternalAuthProviderGitHub
379
- case codersdk .ExternalAuthProviderGitLab :
380
- typ = codersdk .ExternalAuthProviderGitLab
381
- default :
382
- typ = codersdk .ExternalAuthProvider (entry .Type )
383
- }
384
-
385
371
// Applies defaults to the config entry.
386
372
// This allows users to very simply state that they type is "GitHub",
387
373
// apply their client secret and ID, and have the UI appear nicely.
388
- applyDefaultsToConfig (typ , & entry )
374
+ applyDefaultsToConfig (& entry )
389
375
390
376
valid := httpapi .NameValid (entry .ID )
391
377
if valid != nil {
@@ -400,8 +386,8 @@ func ConvertConfig(entries []codersdk.ExternalAuthConfig, accessURL *url.URL) ([
400
386
401
387
_ , exists := ids [entry .ID ]
402
388
if exists {
403
- if entry .ID == string ( typ ) {
404
- return nil , xerrors .Errorf ("multiple %s external auth providers provided. you must specify a unique id for each" , typ )
389
+ if entry .ID == entry . Type {
390
+ return nil , xerrors .Errorf ("multiple %s external auth providers provided. you must specify a unique id for each" , entry . Type )
405
391
}
406
392
return nil , xerrors .Errorf ("multiple external auth providers exist with the id %q. specify a unique id for each" , entry .ID )
407
393
}
@@ -433,15 +419,15 @@ func ConvertConfig(entries []codersdk.ExternalAuthConfig, accessURL *url.URL) ([
433
419
434
420
var oauthConfig OAuth2Config = oc
435
421
// Azure DevOps uses JWT token authentication!
436
- if typ == codersdk .ExternalAuthProviderAzureDevops {
422
+ if entry . Type == string ( codersdk .EnhancedExternalAuthProviderAzureDevops ) {
437
423
oauthConfig = & jwtConfig {oc }
438
424
}
439
425
440
426
cfg := & Config {
441
427
OAuth2Config : oauthConfig ,
442
428
ID : entry .ID ,
443
429
Regex : regex ,
444
- Type : typ ,
430
+ Type : entry . Type ,
445
431
NoRefresh : entry .NoRefresh ,
446
432
ValidateURL : entry .ValidateURL ,
447
433
AppInstallationsURL : entry .AppInstallationsURL ,
@@ -468,8 +454,8 @@ func ConvertConfig(entries []codersdk.ExternalAuthConfig, accessURL *url.URL) ([
468
454
}
469
455
470
456
// applyDefaultsToConfig applies defaults to the config entry.
471
- func applyDefaultsToConfig (typ codersdk. ExternalAuthProvider , config * codersdk.ExternalAuthConfig ) {
472
- defaults := defaults [typ ]
457
+ func applyDefaultsToConfig (config * codersdk.ExternalAuthConfig ) {
458
+ defaults := defaults [codersdk . EnhancedExternalAuthProvider ( config . Type ) ]
473
459
if config .AuthURL == "" {
474
460
config .AuthURL = defaults .AuthURL
475
461
}
@@ -503,27 +489,27 @@ func applyDefaultsToConfig(typ codersdk.ExternalAuthProvider, config *codersdk.E
503
489
504
490
// Apply defaults if it's still empty...
505
491
if config .ID == "" {
506
- config .ID = string ( typ )
492
+ config .ID = config . Type
507
493
}
508
494
if config .DisplayName == "" {
509
- config .DisplayName = string ( typ )
495
+ config .DisplayName = config . Type
510
496
}
511
497
if config .DisplayIcon == "" {
512
498
// This is a key emoji.
513
499
config .DisplayIcon = "/emojis/1f511.png"
514
500
}
515
501
}
516
502
517
- var defaults = map [codersdk.ExternalAuthProvider ]codersdk.ExternalAuthConfig {
518
- codersdk .ExternalAuthProviderAzureDevops : {
503
+ var defaults = map [codersdk.EnhancedExternalAuthProvider ]codersdk.ExternalAuthConfig {
504
+ codersdk .EnhancedExternalAuthProviderAzureDevops : {
519
505
AuthURL : "https://app.vssps.visualstudio.com/oauth2/authorize" ,
520
506
TokenURL : "https://app.vssps.visualstudio.com/oauth2/token" ,
521
507
DisplayName : "Azure DevOps" ,
522
508
DisplayIcon : "/icon/azure-devops.svg" ,
523
509
Regex : `^(https?://)?dev\.azure\.com(/.*)?$` ,
524
510
Scopes : []string {"vso.code_write" },
525
511
},
526
- codersdk .ExternalAuthProviderBitBucket : {
512
+ codersdk .EnhancedExternalAuthProviderBitBucket : {
527
513
AuthURL : "https://bitbucket.org/site/oauth2/authorize" ,
528
514
TokenURL : "https://bitbucket.org/site/oauth2/access_token" ,
529
515
ValidateURL : "https://api.bitbucket.org/2.0/user" ,
@@ -532,7 +518,7 @@ var defaults = map[codersdk.ExternalAuthProvider]codersdk.ExternalAuthConfig{
532
518
Regex : `^(https?://)?bitbucket\.org(/.*)?$` ,
533
519
Scopes : []string {"account" , "repository:write" },
534
520
},
535
- codersdk .ExternalAuthProviderGitLab : {
521
+ codersdk .EnhancedExternalAuthProviderGitLab : {
536
522
AuthURL : "https://gitlab.com/oauth/authorize" ,
537
523
TokenURL : "https://gitlab.com/oauth/token" ,
538
524
ValidateURL : "https://gitlab.com/oauth/token/info" ,
@@ -541,7 +527,7 @@ var defaults = map[codersdk.ExternalAuthProvider]codersdk.ExternalAuthConfig{
541
527
Regex : `^(https?://)?gitlab\.com(/.*)?$` ,
542
528
Scopes : []string {"write_repository" },
543
529
},
544
- codersdk .ExternalAuthProviderGitHub : {
530
+ codersdk .EnhancedExternalAuthProviderGitHub : {
545
531
AuthURL : xgithub .Endpoint .AuthURL ,
546
532
TokenURL : xgithub .Endpoint .TokenURL ,
547
533
ValidateURL : "https://api.github.com/user" ,
0 commit comments