@@ -659,6 +659,11 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
659
659
AvatarURL : ghUser .GetAvatarURL (),
660
660
Name : normName ,
661
661
DebugContext : OauthDebugContext {},
662
+ OrganizationSync : idpsync.OrganizationParams {
663
+ SyncEnabled : false ,
664
+ IncludeDefault : true ,
665
+ Organizations : []uuid.UUID {},
666
+ },
662
667
}).SetInitAuditRequest (func (params * audit.RequestParams ) (* audit.Request [database.User ], func ()) {
663
668
return audit .InitRequest [database.User ](rw , params )
664
669
})
@@ -1411,14 +1416,19 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
1411
1416
}
1412
1417
}
1413
1418
1419
+ // Even if org sync is disabled, single org deployments will always
1420
+ // have this set to true.
1421
+ orgIDs := []uuid.UUID {}
1422
+ if params .OrganizationSync .IncludeDefault {
1423
+ orgIDs = append (orgIDs , defaultOrganization .ID )
1424
+ }
1425
+
1414
1426
//nolint:gocritic
1415
1427
user , err = api .CreateUser (dbauthz .AsSystemRestricted (ctx ), tx , CreateUserRequest {
1416
1428
CreateUserRequestWithOrgs : codersdk.CreateUserRequestWithOrgs {
1417
- Email : params .Email ,
1418
- Username : params .Username ,
1419
- // TODO: Remove this, and only use organization sync from
1420
- // params
1421
- OrganizationIDs : []uuid.UUID {defaultOrganization .ID },
1429
+ Email : params .Email ,
1430
+ Username : params .Username ,
1431
+ OrganizationIDs : orgIDs ,
1422
1432
},
1423
1433
LoginType : params .LoginType ,
1424
1434
})
@@ -1481,6 +1491,13 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C
1481
1491
}
1482
1492
}
1483
1493
1494
+ // Only OIDC really supports syncing like this. At some point, we might
1495
+ // want to move this configuration and allow github to allow do org syncing.
1496
+ err = api .OIDCConfig .IDPSync .SyncOrganizations (ctx , tx , user , params .OrganizationSync )
1497
+ if err != nil {
1498
+ return xerrors .Errorf ("sync organizations: %w" , err )
1499
+ }
1500
+
1484
1501
// Ensure groups are correct.
1485
1502
// This places all groups into the default organization.
1486
1503
// To go multi-org, we need to add a mapping feature here to know which
0 commit comments