/
config.go
48 lines (39 loc) · 1.07 KB
/
config.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
package config
import (
"fmt"
"time"
"golang.org/x/oauth2"
)
type Config struct {
Auth AuthConfig `json:"auth"`
}
type AuthConfig struct {
ActiveProfile ProfileName `json:"active_profile"`
Profiles map[ProfileName]SessionConfig `json:"profiles"`
}
type ProfileName string
type SessionConfig struct {
ClientID string `json:"client_id"`
ApiURL string `json:"api_url"`
AppURL string `json:"app_url"`
AccountID string `json:"account_id"`
UserID string `json:"user_id"`
Token oauth2.Token `json:"token"`
CreatedAt time.Time `json:"created_at"`
}
func (c SessionConfig) GetOAuth2Config() oauth2.Config {
return oauth2.Config{
ClientID: c.ClientID,
Endpoint: oauth2.Endpoint{
AuthURL: GetOAuthTokenURL(c.AppURL),
TokenURL: GetOAuthTokenURL(c.AppURL),
AuthStyle: oauth2.AuthStyleInParams,
},
}
}
func GetOAuthAuthURL(appURL string) string {
return fmt.Sprintf("%s/oauth/authorize", appURL)
}
func GetOAuthTokenURL(appURL string) string {
return fmt.Sprintf("%s/oauth/token", appURL)
}