@@ -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
- Team func (ctx context.Context , client * http.Client , org , team string ) (* github.Team , error )
32
+ TeamMembership func (ctx context.Context , client * http.Client , org , team , username string ) (* github.Membership , error )
33
33
34
34
AllowSignups bool
35
35
AllowOrganizations []string
@@ -72,17 +72,26 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
72
72
return
73
73
}
74
74
75
+ ghUser , err := api .GithubOAuth2Config .AuthenticatedUser (r .Context (), oauthClient )
76
+ if err != nil {
77
+ httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
78
+ Message : "Internal error fetching authenticated Github user." ,
79
+ Detail : err .Error (),
80
+ })
81
+ return
82
+ }
83
+
75
84
// The default if no teams are specified is to allow all.
76
85
if len (api .GithubOAuth2Config .AllowTeams ) > 0 {
77
- var allowedTeam * github.Team
86
+ var allowedTeam * github.Membership
78
87
for _ , allowTeam := range api .GithubOAuth2Config .AllowTeams {
79
88
if allowTeam .Organization != * selectedMembership .Organization .Login {
80
89
// This needs to continue because multiple organizations
81
90
// could exist in the allow/team listings.
82
91
continue
83
92
}
84
93
85
- allowedTeam , err = api .GithubOAuth2Config .Team (r .Context (), oauthClient , allowTeam .Organization , allowTeam .Slug )
94
+ allowedTeam , err = api .GithubOAuth2Config .TeamMembership (r .Context (), oauthClient , allowTeam .Organization , allowTeam .Slug , * ghUser . Login )
86
95
// The calling user may not have permission to the requested team!
87
96
if err != nil {
88
97
continue
@@ -151,14 +160,6 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
151
160
// email to organization.
152
161
organizationID = organizations [0 ].ID
153
162
}
154
- ghUser , err := api .GithubOAuth2Config .AuthenticatedUser (r .Context (), oauthClient )
155
- if err != nil {
156
- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
157
- Message : "Internal error fetching authenticated Github user." ,
158
- Detail : err .Error (),
159
- })
160
- return
161
- }
162
163
var verifiedEmail * github.UserEmail
163
164
for _ , email := range emails {
164
165
if ! email .GetPrimary () || ! email .GetVerified () {
0 commit comments