@@ -29,7 +29,7 @@ type GithubOAuth2Config struct {
29
29
AuthenticatedUser func (ctx context.Context , client * http.Client ) (* github.User , error )
30
30
ListEmails func (ctx context.Context , client * http.Client ) ([]* github.UserEmail , error )
31
31
ListOrganizationMemberships func (ctx context.Context , client * http.Client ) ([]* github.Membership , error )
32
- ListTeams func (ctx context.Context , client * http.Client , org string ) ([] * github.Team , error )
32
+ Team func (ctx context.Context , client * http.Client , org , team string ) (* github.Team , error )
33
33
34
34
AllowSignups bool
35
35
AllowOrganizations []string
@@ -74,31 +74,20 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
74
74
75
75
// The default if no teams are specified is to allow all.
76
76
if len (api .GithubOAuth2Config .AllowTeams ) > 0 {
77
- teams , err := api .GithubOAuth2Config .ListTeams (r .Context (), oauthClient , * selectedMembership .Organization .Login )
78
- if err != nil {
79
- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
80
- Message : "Failed to fetch teams from GitHub." ,
81
- Detail : err .Error (),
82
- })
83
- return
84
- }
85
-
86
77
var allowedTeam * github.Team
87
- for _ , team := range teams {
88
- for _ , allowTeam := range api .GithubOAuth2Config .AllowTeams {
89
- if allowTeam .Organization != * selectedMembership .Organization .Login {
90
- // This needs to continue because multiple organizations
91
- // could exist in the allow/team listings.
92
- continue
93
- }
94
- if allowTeam .Slug != * team .Slug {
95
- continue
96
- }
97
- allowedTeam = team
98
- break
78
+ for _ , allowTeam := range api .GithubOAuth2Config .AllowTeams {
79
+ if allowTeam .Organization != * selectedMembership .Organization .Login {
80
+ // This needs to continue because multiple organizations
81
+ // could exist in the allow/team listings.
82
+ continue
99
83
}
100
- }
101
84
85
+ allowedTeam , err = api .GithubOAuth2Config .Team (r .Context (), oauthClient , allowTeam .Organization , allowTeam .Slug )
86
+ // The calling user may not have permission to the requested team!
87
+ if err != nil {
88
+ continue
89
+ }
90
+ }
102
91
if allowedTeam == nil {
103
92
httpapi .Write (rw , http .StatusUnauthorized , codersdk.Response {
104
93
Message : fmt .Sprintf ("You aren't a member of an authorized team in the %s Github organization!" , * selectedMembership .Organization .Login ),
0 commit comments