Add scopes

This commit is contained in:
JBP
2019-08-17 19:19:15 +02:00
parent 6fb68652e0
commit 7484ba3df6
2 changed files with 17 additions and 10 deletions
+8
View File
@@ -19,6 +19,14 @@ const (
sandboxBaseURL = "https://api.sandbox.ebay.com/" sandboxBaseURL = "https://api.sandbox.ebay.com/"
) )
// Some eBay API scopes.
//
// eBay API docs: https://developer.ebay.com/api-docs/static/oauth-scopes.html
const (
ScopeRoot = "https://api.ebay.com/oauth/api_scope"
ScopeBuyOfferAuction = "https://api.ebay.com/oauth/api_scope/buy.offer.auction"
)
// BuyAPI regroups the eBay Buy APIs. // BuyAPI regroups the eBay Buy APIs.
// //
// eBay API docs: https://developer.ebay.com/api-docs/buy/static/buy-landing.html // eBay API docs: https://developer.ebay.com/api-docs/buy/static/buy-landing.html
+9 -10
View File
@@ -25,6 +25,7 @@ var (
clientID string clientID string
clientSecret string clientSecret string
auctionURL string auctionURL string
redirectURL string
) )
func init() { func init() {
@@ -35,8 +36,9 @@ func init() {
} }
clientID = os.Getenv("SANDBOX_CLIENT_ID") clientID = os.Getenv("SANDBOX_CLIENT_ID")
clientSecret = os.Getenv("SANDBOX_CLIENT_SECRET") clientSecret = os.Getenv("SANDBOX_CLIENT_SECRET")
if clientID == "" || clientSecret == "" { redirectURL = os.Getenv("SANDBOX_REDIRECT_URL")
panic("Please set SANDBOX_CLIENT_ID and SANDBOX_CLIENT_SECRET.") if clientID == "" || clientSecret == "" || redirectURL == "" {
panic("Please set SANDBOX_CLIENT_ID, SANDBOX_CLIENT_SECRET and SANDBOX_REDIRECT_URL.")
} }
} }
@@ -53,8 +55,8 @@ func TestAuction(t *testing.T) {
conf := clientcredentials.Config{ conf := clientcredentials.Config{
ClientID: clientID, ClientID: clientID,
ClientSecret: clientSecret, ClientSecret: clientSecret,
TokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token", TokenURL: ebay.OAuth20SandboxEndpoint.TokenURL,
Scopes: []string{"https://api.ebay.com/oauth/api_scope"}, Scopes: []string{ebay.ScopeRoot},
} }
client := ebay.NewSandboxClient(oauth2.NewClient(ctx, ebay.TokenSource(conf.TokenSource(ctx)))) client := ebay.NewSandboxClient(oauth2.NewClient(ctx, ebay.TokenSource(conf.TokenSource(ctx))))
@@ -114,12 +116,9 @@ func TestAuction(t *testing.T) {
oauthConf := oauth2.Config{ oauthConf := oauth2.Config{
ClientID: clientID, ClientID: clientID,
ClientSecret: clientSecret, ClientSecret: clientSecret,
Endpoint: oauth2.Endpoint{ Endpoint: ebay.OAuth20SandboxEndpoint,
AuthURL: "https://auth.sandbox.ebay.com/oauth2/authorize", RedirectURL: redirectURL,
TokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token", Scopes: []string{ebay.ScopeBuyOfferAuction},
},
RedirectURL: "Jean-Baptiste_P-JeanBapt-testgo-cowrprk",
Scopes: []string{"https://api.ebay.com/oauth/api_scope/buy.offer.auction"},
} }
url := oauthConf.AuthCodeURL(state) url := oauthConf.AuthCodeURL(state)