forked from go-packages/paypal
Remove unused tokenservice endpoints
This commit is contained in:
parent
9451befb2b
commit
c9c1a38641
4
.github/workflows/lint-test.yaml
vendored
4
.github/workflows/lint-test.yaml
vendored
|
@ -11,7 +11,7 @@ jobs:
|
|||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.21.x"
|
||||
go-version: "1.23"
|
||||
- name: Install dependencies
|
||||
run: go get .
|
||||
- name: Install linters
|
||||
|
@ -33,7 +33,7 @@ jobs:
|
|||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: "1.21.x"
|
||||
go-version: "1.23"
|
||||
- name: Install dependencies
|
||||
run: go get .
|
||||
- name: Run Tests
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
[Docs](https://pkg.go.dev/github.com/plutov/paypal)
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/plutov/paypal/releases"><img src="https://img.shields.io/github/release/plutov/paypal.svg" alt="Latest Release"></a>
|
||||
<a href="https://pkg.go.dev/github.com/plutov/paypal?tab=doc"><img src="https://godoc.org/github.com/golang/gddo?status.svg" alt="GoDoc"></a>
|
||||
</p>
|
||||
|
||||
# Go client for PayPal REST API
|
||||
|
||||
## Paypal REST API Docs
|
||||
|
@ -294,10 +299,10 @@ invoice, err := c.GetInvoiceDetails(ctx, "INV2-XFXV-YW42-ZANU-4F33")
|
|||
- Check that tests are passing
|
||||
- Create PR
|
||||
|
||||
Current contributors:
|
||||
Main contributors:
|
||||
|
||||
- [Roopak Venkatakrishnan](https://github.com/roopakv)
|
||||
- [Alex Pliutau](https://github.com/plutov)
|
||||
- [Roopak Venkatakrishnan](https://github.com/roopakv)
|
||||
|
||||
## Tests
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/plutov/paypal/v4
|
||||
|
||||
go 1.21
|
||||
go 1.23
|
||||
|
||||
require github.com/stretchr/testify v1.9.0
|
||||
|
||||
|
|
49
identity.go
49
identity.go
|
@ -4,59 +4,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GrantNewAccessTokenFromAuthCode - Use this call to grant a new access token, using the previously obtained authorization code.
|
||||
// Endpoint: POST /v1/identity/openidconnect/tokenservice
|
||||
func (c *Client) GrantNewAccessTokenFromAuthCode(ctx context.Context, code, redirectURI string) (*TokenResponse, error) {
|
||||
token := &TokenResponse{}
|
||||
|
||||
q := url.Values{}
|
||||
q.Set("grant_type", "authorization_code")
|
||||
q.Set("code", code)
|
||||
q.Set("redirect_uri", redirectURI)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/identity/openidconnect/tokenservice"), strings.NewReader(q.Encode()))
|
||||
if err != nil {
|
||||
return token, err
|
||||
}
|
||||
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
if err = c.SendWithBasicAuth(req, token); err != nil {
|
||||
return token, err
|
||||
}
|
||||
|
||||
return token, nil
|
||||
}
|
||||
|
||||
// GrantNewAccessTokenFromRefreshToken - Use this call to grant a new access token, using a refresh token.
|
||||
// Endpoint: POST /v1/identity/openidconnect/tokenservice
|
||||
func (c *Client) GrantNewAccessTokenFromRefreshToken(ctx context.Context, refreshToken string) (*TokenResponse, error) {
|
||||
type request struct {
|
||||
GrantType string `json:"grant_type"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
token := &TokenResponse{}
|
||||
|
||||
req, err := c.NewRequest(ctx, "POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/identity/openidconnect/tokenservice"), request{GrantType: "refresh_token", RefreshToken: refreshToken})
|
||||
if err != nil {
|
||||
return token, err
|
||||
}
|
||||
|
||||
if err = c.SendWithAuth(req, token); err != nil {
|
||||
return token, err
|
||||
}
|
||||
|
||||
return token, nil
|
||||
}
|
||||
|
||||
// GetUserInfo - Use this call to retrieve user profile attributes.
|
||||
// Endpoint: GET /v1/identity/openidconnect/userinfo/?schema=<Schema>
|
||||
// Pass the schema that is used to return as per openidconnect protocol. The only supported schema value is openid.
|
||||
func (c *Client) GetUserInfo(ctx context.Context, schema string) (*UserInfo, error) {
|
||||
u := &UserInfo{}
|
||||
|
||||
|
|
4
types.go
4
types.go
|
@ -12,10 +12,10 @@ import (
|
|||
|
||||
const (
|
||||
// APIBaseSandBox points to the sandbox (for testing) version of the API
|
||||
APIBaseSandBox = "https://api.sandbox.paypal.com"
|
||||
APIBaseSandBox = "https://api-m.sandbox.paypal.com"
|
||||
|
||||
// APIBaseLive points to the live version of the API
|
||||
APIBaseLive = "https://api.paypal.com"
|
||||
APIBaseLive = "https://api-m.paypal.com"
|
||||
|
||||
// RequestNewTokenBeforeExpiresIn is used by SendWithAuth and try to get new Token when it's about to expire
|
||||
RequestNewTokenBeforeExpiresIn = time.Duration(60) * time.Second
|
||||
|
|
Loading…
Reference in New Issue
Block a user