A library for handling OAuth2 for making eBay REST requests.
Import the module:
import oauth2 "github.com/ralucas/go-ebay-oauth2"Create the client with your appropriate credentials:
client := oauth2.NewClient(
baseUrl, // oauth2.ProductionBaseUrl or oauth2.SandboxBaseUrl constants are available
clientId, // your eBay application clientId
clientSecret, // your eBay application clientSecret
redirectUri, // your application redirectUri
)Then, create the flow you wish to pursue:
Example:
myscopes := []string{"offer"}
ac := client.AuthorizationCode(myscopes)Additional options are available:
prompt- to indicate whether or not to prompt the user to loginWithPrompt(string)
state- a token created by your application to manage the stateWithState(string)
Example usage:
myscopes := []string{"offer"}
var opts []AuthorizationCodeOption
opts = opts.append(WithPrompt("login"))
opts = opts.append(WithState("my-state-token"))
ac := client.AuthorizationCode(config, myscopes, opts...)Get the request url for application access:
url, err := ac.GrantApplicationAccessUrl()Next, in your redirect route handler, get the access token:
token, err := ac.ExchangeAuthorizationForToken(req.redirectURI)
// do something with the tokenExample:
myscopes := []string{"offer"}
cc := client.ClientCredentials(myscopes)Get the access token:
token, err := cc.AccessToken()
// do something with the tokentype AccessToken struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
RefreshTokenExpiresIn int `json:"refresh_token_expires_in"`
TokenType string `json:"token_type"`
}