oauth2-client
oauth2-client copied to clipboard
Set custom User-Agent for requests
I'm using a GenericProvider and when my application attempts to request the access token from my company's SSO, it hits an error that it's been blocked. Upon further investigation with the SSO team, they determined that this is due to the application being hosted in AWS and has a generic User-Agent, GuzzleHTTP/
Is there a way to set a custom User-Agent for the getAccessToken request? Looking at getAccessTokenOptions method, looks like you can only set the body and can't change any other headers.
Do I need to make my own provider? Seems a bit heavy to do for just a small thing piece that would useful to be able to customize?
This is still very relevant as Apple Signin requires a proper User-Agent to be passed.
Any updates on this? I'm facing this same issue myself with Basecamp's API.
Possibly related to or solved through #863
(I posted this on the wrong issue, now moved here)
The solution I have found, using the Xero provider, is to create my own Guzzle instance outside the provider.
So instead of this:
$provider = new \Calcinai\OAuth2\Client\Provider\Xero([
'clientId' => 'my-client-id',
'clientSecret' => 'my-client-secret',
]};
I have this:
$httpClient = new \GuzzleHttp\Client([
'headers' => [
'User-Agent' => 'My Xero Application name',
],
]);
$provider = new \Calcinai\OAuth2\Client\Provider\Xero([
'clientId' => 'my-client-id',
'clientSecret' => 'my-client-secret',
], [
'httpClient' => $httpClient,
]};
Even though the message is a PSR-7 message that should contain everything, Guzzle still slips in some headers on top of that, and the User-Agent
is one of them. Xero in particular is very keen on the correct User-Agent
being used, to help with support issues that may arise.
Note that these header parameters are for Guzzle 7. The format is slightly different on Guzzle 6 (wrapped in a defaults
array) and different again on Guzzle 5.