Skip to content

ralucas/go-ebay-oauth2

Repository files navigation

Ebay OAuth2 for Go

Go Go Reference

Introduction

A library for handling OAuth2 for making eBay REST requests.

Getting Started

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:

Authorization Code Flow

Example:

myscopes := []string{"offer"}
ac := client.AuthorizationCode(myscopes)

Options

Additional options are available:

  • prompt - to indicate whether or not to prompt the user to login
    • WithPrompt(string)
  • state - a token created by your application to manage the state
    • WithState(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 token

Client Credentials Flow

Example:

myscopes := []string{"offer"}
cc := client.ClientCredentials(myscopes)

Get the access token:

token, err := cc.AccessToken()
// do something with the token

AccessToken

type 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"`
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published