Skip to content
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

Handle 'scope' for Twitter Oauth1 #548

Merged
merged 2 commits into from
Aug 5, 2021
Merged

Handle 'scope' for Twitter Oauth1 #548

merged 2 commits into from
Aug 5, 2021

Conversation

Diegslapasteque
Copy link
Contributor

Hey,
I recently made a pull request in the thephpleague/oauth1-client repository to handle the scope for Twitter Oauth1 (with the parameter x_auth_access_type).
I use socialite in my app and I need to be able to set this scope manually, so I added a new method in the TwitterProvider.php to handle it.

@ZekLouis
Copy link

ZekLouis commented Aug 4, 2021

Same issue here, this fix would be really useful ! Thanks @Diegslapasteque

@taylorotwell
Copy link
Member

taylorotwell commented Aug 4, 2021

Can you provide a code example of how it would be used?

@Diegslapasteque
Copy link
Contributor Author

I will take the use case for our app as an example

For all our users, we just need to get a Twitter oauth token with the default read access. We prefer not to use the write access by default to ask the minimum permissions to avoid scaring our users on the Twitter oauth page (permission to publish tweets, etc.).

So in our config/services.php, we have this :

'twitter' => [
    'client_id' => env('TWITTER_CLIENT_ID'),
    'client_secret' => env('TWITTER_CLIENT_SECRET'),
    'redirect' => env('TWITTER_REDIRECT'),
    'scope' => 'read'
]

But we have some features in our app that require a write access from the Twitter API. When a user try to access one of them, he is going to be redirected to the Twitter oauth again, this time with a write access.
In this case, the method setApplicationScope() that I added will be useful to change the access level.

/** @var TwitterProvider $driver */
$driver = Socialite::driver('twitter');
$driver->setApplicationScope('write');
$driver->redirect();

Is it okay for you?

@taylorotwell taylorotwell merged commit 9253850 into laravel:5.x Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants