From 7484ba3df65e3a1275fd8f95e1ff8e7a3cb52751 Mon Sep 17 00:00:00 2001 From: JBP <2850825+jybp@users.noreply.github.com> Date: Sat, 17 Aug 2019 19:19:15 +0200 Subject: [PATCH] Add scopes --- ebay.go | 8 ++++++++ test/integration/auction_test.go | 19 +++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ebay.go b/ebay.go index 7c5e383..812a9c7 100644 --- a/ebay.go +++ b/ebay.go @@ -19,6 +19,14 @@ const ( 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. // // eBay API docs: https://developer.ebay.com/api-docs/buy/static/buy-landing.html diff --git a/test/integration/auction_test.go b/test/integration/auction_test.go index c50eec5..08dadef 100644 --- a/test/integration/auction_test.go +++ b/test/integration/auction_test.go @@ -25,6 +25,7 @@ var ( clientID string clientSecret string auctionURL string + redirectURL string ) func init() { @@ -35,8 +36,9 @@ func init() { } clientID = os.Getenv("SANDBOX_CLIENT_ID") clientSecret = os.Getenv("SANDBOX_CLIENT_SECRET") - if clientID == "" || clientSecret == "" { - panic("Please set SANDBOX_CLIENT_ID and SANDBOX_CLIENT_SECRET.") + redirectURL = os.Getenv("SANDBOX_REDIRECT_URL") + 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{ ClientID: clientID, ClientSecret: clientSecret, - TokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token", - Scopes: []string{"https://api.ebay.com/oauth/api_scope"}, + TokenURL: ebay.OAuth20SandboxEndpoint.TokenURL, + Scopes: []string{ebay.ScopeRoot}, } client := ebay.NewSandboxClient(oauth2.NewClient(ctx, ebay.TokenSource(conf.TokenSource(ctx)))) @@ -114,12 +116,9 @@ func TestAuction(t *testing.T) { oauthConf := oauth2.Config{ ClientID: clientID, ClientSecret: clientSecret, - Endpoint: oauth2.Endpoint{ - AuthURL: "https://auth.sandbox.ebay.com/oauth2/authorize", - TokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token", - }, - RedirectURL: "Jean-Baptiste_P-JeanBapt-testgo-cowrprk", - Scopes: []string{"https://api.ebay.com/oauth/api_scope/buy.offer.auction"}, + Endpoint: ebay.OAuth20SandboxEndpoint, + RedirectURL: redirectURL, + Scopes: []string{ebay.ScopeBuyOfferAuction}, } url := oauthConf.AuthCodeURL(state)