PHPoAuthLib icon indicating copy to clipboard operation
PHPoAuthLib copied to clipboard

Added setaccesstoken method

Open simplenotezy opened this issue 11 years ago • 5 comments

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 :))

simplenotezy avatar Oct 15 '14 21:10 simplenotezy

@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).

flavioheleno avatar Oct 16 '14 13:10 flavioheleno

Thanks @flavioheleno! I'll keep this in mind!

simplenotezy avatar Oct 17 '14 09:10 simplenotezy

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.

joe-liquid avatar Feb 17 '15 11:02 joe-liquid

@canfiax did the solution from @flavioheleno resolve your problem?

elliotchance avatar Sep 14 '15 00:09 elliotchance

@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

natsu90 avatar Oct 08 '15 03:10 natsu90