Skip to content

Commit 4b70e9c

Browse files
committed
Option to set permissions
1 parent aab36d0 commit 4b70e9c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

providers/discord/discord.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Provider struct {
6363
HTTPClient *http.Client
6464
config *oauth2.Config
6565
providerName string
66+
permissions string
6667
}
6768

6869
// Name gets the name used to retrieve this provider.
@@ -75,6 +76,11 @@ func (p *Provider) SetName(name string) {
7576
p.providerName = name
7677
}
7778

79+
// SetPermissions is to update the bot permissions (used for when ScopeBot is set)
80+
func (p *Provider) SetPermissions(permissions string) {
81+
p.permissions = permissions
82+
}
83+
7884
func (p *Provider) Client() *http.Client {
7985
return goth.HTTPClientWithFallBack(p.HTTPClient)
8086
}
@@ -84,11 +90,17 @@ func (p *Provider) Debug(debug bool) {}
8490

8591
// BeginAuth asks Discord for an authentication end-point.
8692
func (p *Provider) BeginAuth(state string) (goth.Session, error) {
87-
url := p.config.AuthCodeURL(
88-
state,
93+
94+
opts := []oauth2.AuthCodeOption{
8995
oauth2.AccessTypeOnline,
9096
oauth2.SetAuthURLParam("prompt", "none"),
91-
)
97+
}
98+
99+
if p.permissions != "" {
100+
opts = append(opts, oauth2.SetAuthURLParam("permissions", p.permissions))
101+
}
102+
103+
url := p.config.AuthCodeURL(state, opts...)
92104

93105
s := &Session{
94106
AuthURL: url,

0 commit comments

Comments
 (0)