PHPoAuthLib
PHPoAuthLib copied to clipboard
Added setaccesstoken method
Hi there! Great package - really good job. :+1:
This is my first pull request to the open source community - now you're warned! :)
I use your package through https://github.com/artdarek/oauth-4-laravel and have had some troubles getting started.
The issues is finding out a way to manually setting the access_token for the client (in my case Facebook). I am developing an API for an iOS app. The iOS app will send a facebook access token to my API, and I'll have to attach it manually.
This is my way of doing it. If you have another preferred way, that I'd not know of, please let me know :))
@canfiax here's how I do it:
//generate an OAuth2 Token instance (as Facebook uses OAuth2)
$token = new \OAuth\OAuth2\Token\StdOAuth2Token;
$token->setAccessToken($access_token);
//generate a Storage instance (using session here but could be anything else)
$storage = new \OAuth\Common\Storage\Session;
$storage->storeAccessToken('Facebook', $token);
After that, you can use $storage during createService call (serviceFactory method).
Thanks @flavioheleno! I'll keep this in mind!
This works great for the OAuth2 services but not for Yahoo and Twitter which are using the OAuth1 classes in the vendor. Do you have an example of how to do this with OAuth1? I get a 401 unauthorized when making a request in a different method after storing the token like you suggested. In my code, I store the access token like you suggest then redirect to a different URL to make more calls with the stored token.
@canfiax did the solution from @flavioheleno resolve your problem?
@joe-liquid Did you find the solution? I'm getting the same error when using QuickBooks. https://github.com/Lusitanian/PHPoAuthLib/pull/360#issuecomment-144664818