forked from go-packages/paypal
GET /v1/identity/openidconnect/userinfo/?schema=openid
This commit is contained in:
parent
2a864f6dac
commit
2f9803548f
|
@ -19,6 +19,8 @@
|
|||
* POST /v1/payments/orders/**ID**/authorize
|
||||
* POST /v1/payments/orders/**ID**/capture
|
||||
* POST /v1/payments/orders/**ID**/do-void
|
||||
* POST /v1/identity/openidconnect/tokenservice
|
||||
* GET /v1/identity/openidconnect/userinfo/?schema=**SCHEMA**
|
||||
|
||||
#### Missing endpoints
|
||||
It is possible that some endpoints are missing in this SDK Client, but you can use built-in **paypalsdk** functions to perform a request: **NewClient -> NewRequest -> SendWithAuth**
|
||||
|
@ -198,6 +200,12 @@ token, err := c.GrantNewAccessTokenFromAuthCode("<Authorization-Code>", "http://
|
|||
token, err := c.GrantNewAccessTokenFromRefreshToken("<Refresh-Token>")
|
||||
```
|
||||
|
||||
#### Retreive user information
|
||||
|
||||
```go
|
||||
userInfo, err := c.GetUserInfo("openid")
|
||||
```
|
||||
|
||||
#### How to Contribute
|
||||
|
||||
* Fork a repository
|
||||
|
|
|
@ -15,6 +15,7 @@ var testFakeOrderID = "FAKE-O-4J082351X3132253H"
|
|||
var testSaleID = "4CF18861HF410323U"
|
||||
var testPaymentID = "PAY-5YK922393D847794YKER7MUI"
|
||||
var testPayerID = "CR87QHB7JTRSC"
|
||||
var testUserID = "https://www.paypal.com/webapps/auth/identity/user/WEssgRpQij92sE99_F9MImvQ8FPYgUEjrvCja2qH2H8"
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
_, err := NewClient("", "", "")
|
||||
|
|
|
@ -137,4 +137,11 @@ func main() {
|
|||
} else {
|
||||
fmt.Println("ERROR: " + err.Error())
|
||||
}
|
||||
|
||||
u, err := c.GetUserInfo("openid")
|
||||
if err == nil {
|
||||
fmt.Println("DEBUG: UserID=" + u.ID)
|
||||
} else {
|
||||
fmt.Println("ERROR: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
|
24
identity.go
24
identity.go
|
@ -1,6 +1,9 @@
|
|||
package paypalsdk
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GrantNewAccessTokenFromAuthCode - Use this call to grant a new access token, using the previously obtained authorization code.
|
||||
// Endpoint: POST /v1/identity/openidconnect/tokenservice
|
||||
|
@ -48,3 +51,22 @@ func (c *Client) GrantNewAccessTokenFromRefreshToken(refreshToken string) (*Toke
|
|||
|
||||
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(schema string) (*UserInfo, error) {
|
||||
u := UserInfo{}
|
||||
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v1/identity/openidconnect/userinfo/?schema=", schema), nil)
|
||||
if err != nil {
|
||||
return &u, err
|
||||
}
|
||||
|
||||
err = c.SendWithAuth(req, &u)
|
||||
if err != nil {
|
||||
return &u, err
|
||||
}
|
||||
|
||||
return &u, nil
|
||||
}
|
||||
|
|
|
@ -5,17 +5,27 @@ import "testing"
|
|||
func TestGrantNewAccessTokenFromAuthCode(t *testing.T) {
|
||||
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
||||
|
||||
token, _ := c.GrantNewAccessTokenFromAuthCode("123", "http://example.com/myapp/return.php")
|
||||
if token.Token != "" {
|
||||
t.Errorf("Empty token must be returned for invalid code")
|
||||
_, err := c.GrantNewAccessTokenFromAuthCode("123", "http://example.com/myapp/return.php")
|
||||
if err == nil {
|
||||
t.Errorf("GrantNewAccessTokenFromAuthCode must return error for invalid code")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrantNewAccessTokenFromRefreshToken(t *testing.T) {
|
||||
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
||||
|
||||
token, _ := c.GrantNewAccessTokenFromRefreshToken("123")
|
||||
if token.Token != "" {
|
||||
t.Errorf("Empty token must be returned for invalid refresh token")
|
||||
_, err := c.GrantNewAccessTokenFromRefreshToken("123")
|
||||
if err == nil {
|
||||
t.Errorf("GrantNewAccessTokenFromRefreshToken must return error for invalid refresh token")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUserInfo(t *testing.T) {
|
||||
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
||||
c.GetAccessToken()
|
||||
|
||||
u, err := c.GetUserInfo("openid")
|
||||
if u.ID != testUserID || err != nil {
|
||||
t.Errorf("GetUserInfo must return valid test ID=" + testUserID)
|
||||
}
|
||||
}
|
||||
|
|
20
types.go
20
types.go
|
@ -275,6 +275,26 @@ type (
|
|||
Custom string `json:"custom,omitempty"`
|
||||
SoftDescriptor string `json:"soft_descriptor,omitempty"`
|
||||
}
|
||||
|
||||
// UserInfo https://developer.paypal.com/webapps/developer/docs/api/#userinfo-object
|
||||
UserInfo struct {
|
||||
ID string `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
GivenName string `json:"given_name"`
|
||||
FamilyName string `json:"family_name"`
|
||||
Email string `json:"email"`
|
||||
Verified bool `json:"verified,omitempty"`
|
||||
Gender string `json:"gender,omitempty"`
|
||||
BirthDate string `json:"birthdate,omitempty"`
|
||||
ZoneInfo string `json:"zoneinfo,omitempty"`
|
||||
Locale string `json:"locale,omitempty"`
|
||||
Phone string `json:"phone_number,omitempty"`
|
||||
Address *Address `json:"address,omitempty"`
|
||||
VerifiedAccount bool `json:"verified_account,omitempty"`
|
||||
AccountType string `json:"account_type,omitempty"`
|
||||
AgeRange string `json:"age_range,omitempty"`
|
||||
PayerID string `json:"payer_id,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// Error method implementation for ErrorResponse struct
|
||||
|
|
Loading…
Reference in New Issue
Block a user