-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.go
51 lines (42 loc) · 1.02 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
47
48
49
50
51
package minox
import (
"net/url"
"strings"
"time"
"golang.org/x/oauth2"
)
const (
scope = "*"
oauthStateString = ""
authorizationTimeout = 60 * time.Second
tokenTimeout = 5 * time.Second
)
type Oauth2Config struct {
oauth2.Config
}
func NewOauth2Config() *Oauth2Config {
config := &Oauth2Config{
Config: oauth2.Config{
RedirectURL: "",
ClientID: "",
ClientSecret: "",
Scopes: []string{scope},
Endpoint: oauth2.Endpoint{
AuthURL: BaseURL.String() + "/oauth2/auth",
TokenURL: BaseURL.String() + "/oauth2/token",
},
},
}
config.SetBaseURL(&BaseURL)
return config
}
func (c *Oauth2Config) SetBaseURL(baseURL *url.URL) {
// Strip trailing slash
baseURL.Path = strings.TrimSuffix(baseURL.Path, "/")
// These are not registered in the oauth library by default
oauth2.RegisterBrokenAuthHeaderProvider(baseURL.String())
c.Config.Endpoint = oauth2.Endpoint{
AuthURL: baseURL.String() + "/oauth2/auth",
TokenURL: baseURL.String() + "/oauth2/token",
}
}