Contents:
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)
"require": {
"aboutyou/auth-sdk": "~0.3.6"
}
If you just want to run the examples now, please refer to the "Examples" section.
./examples/basic.php$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)
$parsed = $authSDK->parseRedirectResponse();
$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/*php composer.phar install.
./run.sh (as root/sudo) in the ./examples folder. Keep an eye on the console messages (it will complain about the /etc/hosts config, add it). If everything works, you should be able to open the (local) url shown in the console afterwards.
php -S mytestserver.local:8080 in the ./examples folder (as root/sudo on linux/osx). Notice you have to add 127.0.0.1 mytestserver.local to your /etc/hosts for this to work. (Windows: system32\drivers\etc\hosts)
./examples folder../examples/basic.php:
./examples/parent_page.php & ./examples/result_page.php:
./example/common_params.php to ./example/common_params.local.php