Skip to content

Set custom User-Agent for requests #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
abodnar opened this issue Mar 20, 2018 · 4 comments
Closed

Set custom User-Agent for requests #698

abodnar opened this issue Mar 20, 2018 · 4 comments
Milestone

Comments

@abodnar
Copy link

abodnar commented Mar 20, 2018

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/ Curl/ PHP/.

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?

@isakrubin
Copy link

This is still very relevant as Apple Signin requires a proper User-Agent to be passed.

@sabs21
Copy link

sabs21 commented Jun 19, 2020

Any updates on this? I'm facing this same issue myself with Basecamp's API.

@ramsey ramsey changed the title Ability to set User-Agent when requesting access token Set custom User-Agent for requests Oct 28, 2020
@ramsey
Copy link
Contributor

ramsey commented Oct 28, 2020

Possibly related to or solved through #863

@ramsey ramsey added this to the v3 milestone Oct 28, 2020
@judgej
Copy link
Member

judgej commented Feb 15, 2021

(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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants