@@ -82,6 +82,7 @@ func server() *cobra.Command {
82
82
oauth2GithubClientID string
83
83
oauth2GithubClientSecret string
84
84
oauth2GithubAllowedOrganizations []string
85
+ oauth2GithubAllowedTeams []string
85
86
oauth2GithubAllowSignups bool
86
87
telemetryEnable bool
87
88
telemetryURL string
@@ -264,7 +265,7 @@ func server() *cobra.Command {
264
265
}
265
266
266
267
if oauth2GithubClientSecret != "" {
267
- options .GithubOAuth2Config , err = configureGithubOAuth2 (accessURLParsed , oauth2GithubClientID , oauth2GithubClientSecret , oauth2GithubAllowSignups , oauth2GithubAllowedOrganizations )
268
+ options .GithubOAuth2Config , err = configureGithubOAuth2 (accessURLParsed , oauth2GithubClientID , oauth2GithubClientSecret , oauth2GithubAllowSignups , oauth2GithubAllowedOrganizations , oauth2GithubAllowedTeams )
268
269
if err != nil {
269
270
return xerrors .Errorf ("configure github oauth2: %w" , err )
270
271
}
@@ -535,6 +536,8 @@ func server() *cobra.Command {
535
536
"Specifies a client secret to use for oauth2 with GitHub." )
536
537
cliflag .StringArrayVarP (root .Flags (), & oauth2GithubAllowedOrganizations , "oauth2-github-allowed-orgs" , "" , "CODER_OAUTH2_GITHUB_ALLOWED_ORGS" , nil ,
537
538
"Specifies organizations the user must be a member of to authenticate with GitHub." )
539
+ cliflag .StringArrayVarP (root .Flags (), & oauth2GithubAllowedTeams , "oauth2-github-allowed-teams" , "" , "CODER_OAUTH2_GITHUB_ALLOWED_TEAMS" , nil ,
540
+ "Specifies teams inside organizations the user must be a member of to authenticate with GitHub. Formatted as: <organization-name>/<team-slug>." )
538
541
cliflag .BoolVarP (root .Flags (), & oauth2GithubAllowSignups , "oauth2-github-allow-signups" , "" , "CODER_OAUTH2_GITHUB_ALLOW_SIGNUPS" , false ,
539
542
"Specifies whether new users can sign up with GitHub." )
540
543
cliflag .BoolVarP (root .Flags (), & telemetryEnable , "telemetry" , "" , "CODER_TELEMETRY" , true , "Specifies whether telemetry is enabled or not. Coder collects anonymized usage data to help improve our product." )
@@ -719,7 +722,7 @@ func configureTLS(listener net.Listener, tlsMinVersion, tlsClientAuth, tlsCertFi
719
722
return tls .NewListener (listener , tlsConfig ), nil
720
723
}
721
724
722
- func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string , allowSignups bool , allowOrgs []string ) (* coderd.GithubOAuth2Config , error ) {
725
+ func configureGithubOAuth2 (accessURL * url.URL , clientID , clientSecret string , allowSignups bool , allowOrgs []string , allowTeams [] string ) (* coderd.GithubOAuth2Config , error ) {
723
726
redirectURL , err := accessURL .Parse ("/api/v2/users/oauth2/github/callback" )
724
727
if err != nil {
725
728
return nil , xerrors .Errorf ("parse github oauth callback url: %w" , err )
@@ -738,6 +741,7 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
738
741
},
739
742
AllowSignups : allowSignups ,
740
743
AllowOrganizations : allowOrgs ,
744
+ AllowTeams : allowTeams ,
741
745
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
742
746
user , _ , err := github .NewClient (client ).Users .Get (ctx , "" )
743
747
return user , err
@@ -749,9 +753,18 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
749
753
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
750
754
memberships , _ , err := github .NewClient (client ).Organizations .ListOrgMemberships (ctx , & github.ListOrgMembershipsOptions {
751
755
State : "active" ,
756
+ ListOptions : github.ListOptions {
757
+ PerPage : 100 ,
758
+ },
752
759
})
753
760
return memberships , err
754
761
},
762
+ ListTeams : func (ctx context.Context , client * http.Client , org string ) ([]* github.Team , error ) {
763
+ teams , _ , err := github .NewClient (client ).Teams .ListTeams (ctx , org , & github.ListOptions {
764
+ PerPage : 100 ,
765
+ })
766
+ return teams , err
767
+ },
755
768
}, nil
756
769
}
757
770
0 commit comments