oauth-4-laravel icon indicating copy to clipboard operation
oauth-4-laravel copied to clipboard

Examples for requests with stored tokens

Open GamalTawaf opened this issue 11 years ago • 9 comments

I have tried extending the service libraries so I can make calls to the service api with tokens stored in the database but I have had no luck getting them to work. I have tried Facebook, LinkedIn , Twitter and Google so far. For all of them I get failed to request resource. can you please provide examples of how to use twitter and LinkedIn stored tokens to make calls to the API ?

Thanks

GamalTawaf avatar Dec 30 '13 17:12 GamalTawaf

+1

renege avatar Jan 03 '14 23:01 renege

+1

jayeshcp avatar Jan 29 '14 23:01 jayeshcp

You can get tokens like in following example

$linkedinService = OAuth::consumer('Linkedin');
$linkedinService->getStorage()->retrieveAccessToken('Linkedin')->getAccessToken()

azimgd avatar Jan 30 '14 20:01 azimgd

That's not what I meant. That is using the session token. I want to use to the token I after I store it in my database. So it would be assigning all the request parameters without using session variables.

Thanks

GamalTawaf avatar Jan 31 '14 18:01 GamalTawaf

Well, so you can assign token to selected service using this method

$linkedinService->getStorage()->storeAccessToken('Linkedin', $token);

azimgd avatar Feb 01 '14 20:02 azimgd

Yes, but anyway the $token must be an instance of OAuth\Common\Token\TokenInterface

asmerkin avatar Apr 03 '14 17:04 asmerkin

This worked for me. $access_token should be the string you have stored:

use OAuth\OAuth2\Token\StdOAuth2Token;

$token_interface = new StdOAuth2Token($access_token);

$service = OAuth::consumer('Facebook');
$token = $service->getStorage()->storeAccessToken('Facebook', $token_interface);

tomasescobar avatar May 08 '14 02:05 tomasescobar

It is possible to get google contacts ?

nlemsieh avatar Jul 10 '14 14:07 nlemsieh

If you are building an OAuth service which synchronizes user's data to a custom vendor API which implement OAuth, there is no session there. We could store access_token as suggested by @tomasescobar but it seems a bit of a hack and also ineffective - with each communication with the vendor API there is one extra call for getting the token.

An alternative package madewithlove/laravel-oauth2 was clear enough to make that differentiation: "Note that this package ONLY provides the authorization mechanism."

That should be clearly mentioned with this package also.

ux-engineer avatar Jul 29 '14 17:07 ux-engineer