logical-and / php-oauth

Support for authenticating users (without dep from any framework) using both OAuth1 and OAuth2 methods
https://packagist.org/packages/and/oauth
MIT License
43 stars 13 forks source link

Simple entry point to your package #24

Open ivanvermeyen opened 9 years ago

ivanvermeyen commented 9 years ago

Hello!

First of all, your package is awesome! I love it :)

For my own site, I created a small package that allows me to do something as simple as:

$details = $auth->request('facebook');

and this will then depend upon your repo to do its magic :)

I still need to add some unit tests (it's just an initial version), but maybe this can be of use to anyone else... Feedback is always appreciated.

If you're interested, just take a look at https://github.com/codezero-be/oauth

ivanvermeyen commented 9 years ago

I was digging a bit deeper into your code, trying to do some custom requests and figuring out how the access tokens come into play... But I'm not so familiar with the best practices.

Should I redirect the user and get a new access token for every request? Or can I reuse an access token (during a login session for example) and catch some exception in case it expired?

I was trying to do something like this...

When the user logs in:

// ... Create service...

$service->redirectToAuthorizationUri();

Then in a seperate callback method:

// ... Create service...

if ( ! $service->isGlobalRequestArgumentsPassed()) {
    return false; // User declined authorization
}

$token = $service->retrieveAccessTokenByGlobReqArgs()->getAccessToken()->getAccessToken();

// Do whatever...

I would then store the token and use it elsewhere:

// ... Create service...

$service->getAccessToken()->setAccessToken($token);
$result = $service->requestJSON($uri, $body, $method, $extraHeaders);

// Do whatever...

It did work this way until I went AFK and my session expired... setAccessToken() doesn't reregister it in the session it seems.

But I'm not sure if I'm doing it right this way...

logical-and commented 9 years ago

Hey @ivanvermeyen. Thank you at first for you work and interest. :) Look please on the example with google offline, does it make any sense for your question?