oauth-4-laravel
oauth-4-laravel copied to clipboard
Examples for requests with stored tokens
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
+1
+1
You can get tokens like in following example
$linkedinService = OAuth::consumer('Linkedin'); $linkedinService->getStorage()->retrieveAccessToken('Linkedin')->getAccessToken()
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
Well, so you can assign token to selected service using this method
$linkedinService->getStorage()->storeAccessToken('Linkedin', $token);
Yes, but anyway the $token must be an instance of OAuth\Common\Token\TokenInterface
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);
It is possible to get google contacts ?
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.