prratek_ramchandani
11/01/2021, 7:21 PMOAuthAuthenticator
to authenticate with the PayPal API and am running into some trouble. The API expects a request for an access token that looks like this if using curl
curl -v <https://api-m.sandbox.paypal.com/v1/oauth2/token> \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "client_id:secret" \
-d "grant_type=client_credentials"
How do I replicate that with the oauth authenticator class? I tried using the client_id
and client_secret
properties and also tried setting the client ID and secret in the username
and password
params in oauth_request_body()
but both returned a forbidden errorprratek_ramchandani
11/01/2021, 7:32 PM<http://requests.post|requests.post>(URL, auth=("<client_id>", "<client_secret>"), data={"grant_type": "client_credentials"})
stephen_bailey
11/01/2021, 7:37 PMoauth_request_body
property to return `{"grant_type": "client_credentials"}`and perahps overwrite the auth_header
property to get what you need?
https://gitlab.com/meltano/sdk/-/blob/main/singer_sdk/authenticators.py#L422stephen_bailey
11/01/2021, 7:37 PMclient_id:secret
?stephen_bailey
11/01/2021, 7:38 PMprratek_ramchandani
11/01/2021, 7:56 PMstephen_bailey
11/01/2021, 9:21 PMprratek_ramchandani
11/01/2021, 9:42 PMaaron_phethean
11/02/2021, 10:33 AM-H "Authorization: Bearer [your token]" \
https://developer.paypal.com/docs/api/reference/get-an-access-token/
As you also pointed out, to get the Bearer access token requires Basic Auth request:
curl -v <https://api-m.sandbox.paypal.com/v1/oauth2/token> \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "client_id:secret" \
-d "grant_type=client_credentials"
However, the Singer SDK base class for OAuthAuthenticator expects to help you construct an unauthenticated POST request - which would be similar to the following in curl
curl -v <https://api-m.sandbox.paypal.com/v1/oauth2/token> \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-d "{'grant_type':[your client_credentials], 'client_id':[your client id], 'secret': [your secret]}"
https://gitlab.com/meltano/sdk/-/blob/main/singer_sdk/authenticators.py#L351
I think this means you need to roll your own Authenticator, or create a MR to get this into the SDK!
For your own Authenticator you will extend what you started with
<http://requests.post|requests.post>(URL, auth=("<client_id>", "<client_secret>"), data={"grant_type": "client_credentials"})
The Basic Authorization header is 'Basic ' followed by a BASE64 encoded string e.g.
-H "Authorization: Basic [base64 encoded 'client_id:secret']" \
prratek_ramchandani
11/02/2021, 4:09 PM