Skip to content

Commit d942098

Browse files
committed
fix: github: make read:org conditional (#1)
Signed-off-by: Grant Linville <grant@acorn.io>
1 parent 82cb150 commit d942098

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

providers/github.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ var _ Provider = (*GitHubProvider)(nil)
3232

3333
const (
3434
githubProviderName = "GitHub"
35-
githubDefaultScope = "user:email read:org"
35+
githubDefaultScope = "user:email"
36+
githubReadOrgScope = "read:org"
3637
orgTeamSeparator = ":"
3738
)
3839

@@ -66,13 +67,18 @@ var (
6667

6768
// NewGitHubProvider initiates a new GitHubProvider
6869
func NewGitHubProvider(p *ProviderData, opts options.GitHubOptions) *GitHubProvider {
70+
scope := githubDefaultScope
71+
if opts.Team != "" || opts.Org != "" {
72+
scope += " " + githubReadOrgScope
73+
}
74+
6975
p.setProviderDefaults(providerDefaults{
7076
name: githubProviderName,
7177
loginURL: githubDefaultLoginURL,
7278
redeemURL: githubDefaultRedeemURL,
7379
profileURL: nil,
7480
validateURL: githubDefaultValidateURL,
75-
scope: githubDefaultScope,
81+
scope: scope,
7682
})
7783

7884
provider := &GitHubProvider{ProviderData: p}
@@ -132,8 +138,11 @@ func (p *GitHubProvider) setUsers(users []string) {
132138
// EnrichSession updates the User & Email after the initial Redeem
133139
func (p *GitHubProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
134140
// Construct user info JSON from multiple GitHub API endpoints to have a more detailed session state
135-
if err := p.getOrgAndTeam(ctx, s); err != nil {
136-
return err
141+
142+
if p.Org != "" || p.Team != "" {
143+
if err := p.getOrgAndTeam(ctx, s); err != nil {
144+
return err
145+
}
137146
}
138147

139148
if err := p.checkRestrictions(ctx, s); err != nil {

0 commit comments

Comments
 (0)