-
Notifications
You must be signed in to change notification settings - Fork 4
/
oauth.go
46 lines (39 loc) · 1.36 KB
/
oauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package disguard // import "go.zeta.pm/disguard"
import (
"fmt"
"net/url"
)
var (
oauthScope = url.QueryEscape("identify guilds")
authorizationURL = "https://discordapp.com/oauth2/authorize?response_type=code&client_id=%s&scope=%s&redirect_uri=%s"
tokenURL = "https://discordapp.com/api/oauth2/token?client_id=%s&client_secret=%s&grant_type=authorization_code&scope=%s&code=%s&redirect_uri=%s"
)
// TokenResponse contains response from OAuth
type TokenResponse struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope"`
}
func (conf *OAuthSection) getRedirectURL() string {
if conf.redirectURL != nil {
return *conf.redirectURL
}
temp := url.QueryEscape(conf.RedirectURL)
conf.redirectURL = &temp
return temp
}
// GetAuthorizationURL returns blah
func (conf *OAuthSection) GetAuthorizationURL() string {
if conf.authorizationURL != nil {
return *conf.authorizationURL
}
temp := fmt.Sprintf(authorizationURL, conf.ClientID, oauthScope, conf.getRedirectURL())
conf.authorizationURL = &temp
return temp
}
// GetTokenURL returns blah
func (conf *OAuthSection) GetTokenURL(code string) string {
return fmt.Sprintf(tokenURL, conf.ClientID, conf.ClientSecret, oauthScope, code, conf.getRedirectURL())
}