Contents:

auth-sdk

The auth-sdk is just a simple wrapper around persistent state storage and redirect response parsing for the OAuth2 web grant type.

A simpler explanation is given http://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified. You should read it at least once, to have a basic understanding of OAuth2. This sdk covers the "Web Server Apps" part mentioned there.

The auth-sdk hides most of the OAuth2 stuff, so you'll basically have to do 3 things (in this order):

Your app now should have permissions to make an api call on behalf of the user. Take a look at: ./examples/basic.php

You can use the acces token then stored in the auth-sdk for subsequent api calls until the token expires. (Server-side or until the user logs out)

Include with composer


    "require": {
    "aboutyou/auth-sdk": "~0.3.6"
    }

If you just want to run the examples now, please refer to the "Examples" section.

Oauth2 web grant type usage

Create the sdk object

$authSDK = new AuthSDK(array(
    'clientId'=>'from_dev_center',
    'clientToken'=>'from_dev_center',
    'clientSecret' => 'from_dev_center',
    'redirectUri'=>'entered_in_dev_center',
    'scope'=>'firstname',  //optional. the only valid value is firstname at the moment
    'popup'=>'true|false', //optional. true will render a small login, false the login webpage
    ),new SessionStorage());

(There are two optional parameters that can be "overwritten" 'loginUrl' and 'resourceUrl'. But usually there is no need for that)

Parse the response (login redirected back to your site)

$parsed = $authSDK->parseRedirectResponse();

Check user status. Show login or logout

$authResult = $authSDK->getUser();
    if($authResult->hasErrors()){
    //optional, add values you want to get back on your redirect endpoint
    //but do this before getLoginUrl()
    $authSDK->setState('someKey','someVal');

    renderLoginButton( $authSDK->getLoginUrl() ); //renderLoginButton: your render method
    var_dump($authResult->getErrors());

    }else{
    renderLogoutButton( $authSDK->getLogoutUrl() ); //renderLogoutButton: your render method
    var_dump($authResult->getResult()->response);
    var_dump($authSDK->getState('someKey'));

    }

Examples

Running

Files

Config


    • If the user is not logged in there, it will grant the user for its username and password and then redirect back to your site with an access token.
    • If your user however already is logged in, it will just redirect back to your site with an access token.
    • There is one more authorization flow step after those possible grants from the user and really fetching the access token, but the auth-sdk will gently hide that from you

    ↩