forked from grokify/goauth
/
aha_client.go
52 lines (43 loc) · 1.24 KB
/
aha_client.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
52
package aha
import (
"fmt"
"net/http"
"net/url"
"github.com/grokify/goauth/authutil"
"github.com/grokify/mogo/net/http/httputilmore"
"golang.org/x/oauth2"
)
const (
APIMeURL = "https://secure.aha.io/api/v1/me"
AuthURLFormat = "https://%s.aha.io/oauth/authorize"
TokenURLFormat = "https://%s.aha.io/oauth/token" // #nosec G101
AhaAccountHeader = "X-AHA-ACCOUNT"
)
var (
AhaAccountEnv = "AHA_ACCOUNT"
AhaAPIKeyEnv = "AHA_API_KEY" // #nosec G101
)
func NewEndpoint(subdomain string) oauth2.Endpoint {
return oauth2.Endpoint{
AuthURL: fmt.Sprintf(AuthURLFormat, subdomain),
TokenURL: fmt.Sprintf(TokenURLFormat, subdomain)}
}
func NewClient(subdomain, token string) *http.Client {
return authutil.NewClientHeaderQuery(
http.Header{
httputilmore.HeaderAuthorization: []string{authutil.TokenBearer + " " + token},
AhaAccountHeader: []string{subdomain}},
url.Values{},
false)
}
/*
func NewClient(subdomain, token string) *http.Client {
client := authutil.NewClientAuthzTokenSimple(authutil.TokenBearer, token)
header := http.Header{}
header.Add(AhaAccountHeader, subdomain)
client.Transport = httputilmore.TransportRequestModifier{
Transport: client.Transport,
Header: header}
return client
}
*/