-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoauth2.go
36 lines (31 loc) · 1.07 KB
/
oauth2.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
package ebay
import "golang.org/x/oauth2"
// eBay OAuth 2.0 endpoints.
var (
OAuth20Endpoint = oauth2.Endpoint{
AuthURL: "https://auth.ebay.com/oauth2/authorize",
TokenURL: "https://api.ebay.com/identity/v1/oauth2/token",
}
OAuth20SandboxEndpoint = oauth2.Endpoint{
AuthURL: "https://auth.sandbox.ebay.com/oauth2/authorize",
TokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token",
}
)
// BearerTokenSource forces the type of the token returned by the 'base' TokenSource to 'Bearer'.
// The eBay API will return "Application Access Token" or "User Access Token" as token_type but
// it must be set to 'Bearer' for subsequent requests.
type BearerTokenSource struct {
base oauth2.TokenSource
}
// TokenSource returns a new BearerTokenSource.
func TokenSource(base oauth2.TokenSource) *BearerTokenSource {
return &BearerTokenSource{base: base}
}
// Token allows BearerTokenSource to implement oauth2.TokenSource.
func (ts *BearerTokenSource) Token() (*oauth2.Token, error) {
t, err := ts.base.Token()
if t != nil {
t.TokenType = "Bearer"
}
return t, err
}