Closed marcin86mak closed 8 months ago
You can also create the entire configuration for PayPal
{ // return (bool) $this->isSandbox ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; // return (bool) $this->isSandbox ? 'https://api-m.sandbox.paypal.com' : 'https://api-m.paypal.com'; config: { thirdPartyId: "paypal", clients: [ { clientType: "web-and-android", clientId: "xxxx", clientSecret: "xxxx", }, ], authorizationEndpoint: "https://www.sandbox.paypal.com/signin/authorize", authorizationEndpointQueryParams: {}, tokenEndpoint: "https://api-m.sandbox.paypal.com/v1/oauth2/token", tokenEndpointBodyParams:{}, userInfoEndpoint: "https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo?schema=openid", userInfoMap: { fromUserInfoAPI: { userId: "user_id", email: "email", emailVerified: "email_verified", } } }, },
Please try the following snippet for login with paypal:
{
config: {
thirdPartyId: "paypal",
name: "Paypal",
clients: [
{
clientId: "...",
clientSecret: "...",
scope: ["openid", "email"]
},
],
authorizationEndpoint: "https://www.sandbox.paypal.com/signin/authorize",
tokenEndpoint: "https://api-m.sandbox.paypal.com/v1/oauth2/token",
userInfoEndpoint: "https://api.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1",
userInfoMap: {
fromUserInfoAPI: {
userId: "user_id"
}
}
},
override: (oI) => {
oI.exchangeAuthCodeForOAuthTokens = async (input) => {
const clientId = oI.config.clientId;
const clientSecret = oI.config.clientSecret;
const basicAuthToken = Buffer.from(
`${clientId}:${clientSecret}`,
"utf8"
).toString("base64");
const paypalOauthParams = {
grant_type: "authorization_code",
code: input.redirectURIInfo.redirectURIQueryParams.code,
};
const querystring = require('querystring');
const formData = querystring.stringify(paypalOauthParams);
const headers = {
'Authorization': `Basic ${basicAuthToken}`,
'Content-Type': 'application/x-www-form-urlencoded'
};
const resp = await axios.post(oI.config.tokenEndpoint!, formData, { headers });
console.log(resp);
return resp.data;
}
return oI;
}
}
The problem is logging client_id and client_secret in PayPal. This process is done by Heders curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" -u "CLIENT_ID:CLIENT_SECRET"
Note: Encode CLIENT_ID:CLIENT_SECRET in Base64 before sending it in the API call.
What is needed is access to the Request Headers: tokenEndpointBodyParams => OK tokenEndpointHeaders -> None, please add it, it will solve the problem it describes.
Thank you in advance. And I'm looking forward to seeing this fix implemented as soon as possible. Best regards, Marcin....