Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions providers/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ const (
)

const (
// allows /users/@me without email
// ScopeIdentify allows /users/@me without email
ScopeIdentify string = "identify"
// enables /users/@me to return an email
// ScopeEmail enables /users/@me to return an email
ScopeEmail string = "email"
// allows /users/@me/connections to return linked Twitch and YouTube accounts
// ScopeConnections allows /users/@me/connections to return linked Twitch and YouTube accounts
ScopeConnections string = "connections"
// allows /users/@me/guilds to return basic information about all of a user's guilds
// ScopeGuilds allows /users/@me/guilds to return basic information about all of a user's guilds
ScopeGuilds string = "guilds"
// allows /invites/{invite.id} to be used for joining a user's guild
// ScopeJoinGuild allows /invites/{invite.id} to be used for joining a user's guild
ScopeJoinGuild string = "guilds.join"
// allows your app to join users to a group dm
// ScopeGroupDMjoin allows your app to join users to a group dm
ScopeGroupDMjoin string = "gdm.join"
// for oauth2 bots, this puts the bot in the user's selected guild by default
// ScopeBot is for oauth2 bots, this puts the bot in the user's selected guild by default
ScopeBot string = "bot"
// this generates a webhook that is returned in the oauth token response for authorization code grants
// ScopeWebhook generates a webhook that is returned in the oauth token response for authorization code grants
ScopeWebhook string = "webhook.incoming"
// allows /users/@me/guilds/{guild.id}/member to return a user's member information in a guild
// ScopeReadGuilds allows /users/@me/guilds/{guild.id}/member to return a user's member information in a guild
ScopeReadGuilds string = "guilds.members.read"
)

Expand All @@ -63,6 +63,7 @@ type Provider struct {
HTTPClient *http.Client
config *oauth2.Config
providerName string
permissions string
}

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

// SetPermissions is to update the bot permissions (used for when ScopeBot is set)
func (p *Provider) SetPermissions(permissions string) {
p.permissions = permissions
}

func (p *Provider) Client() *http.Client {
return goth.HTTPClientWithFallBack(p.HTTPClient)
}
Expand All @@ -84,11 +90,17 @@ func (p *Provider) Debug(debug bool) {}

// BeginAuth asks Discord for an authentication end-point.
func (p *Provider) BeginAuth(state string) (goth.Session, error) {
url := p.config.AuthCodeURL(
state,

opts := []oauth2.AuthCodeOption{
oauth2.AccessTypeOnline,
oauth2.SetAuthURLParam("prompt", "none"),
)
}

if p.permissions != "" {
opts = append(opts, oauth2.SetAuthURLParam("permissions", p.permissions))
}

url := p.config.AuthCodeURL(state, opts...)

s := &Session{
AuthURL: url,
Expand Down