dev-master
9999999-dev https://github.com/ikkez/f3-opauthOpauth Plugin for PHP Fat-Free Framework
GPL-3.0
f3 authentication oauth auth opauth fatfree
Opauth Plugin for PHP Fat-Free Framework
This is a plugin for easy integration of Opauth for PHP Fat-Free Framework., (*1)
composer require ikkez/f3-opauth
// adjust the autoloader $f3->set('AUTOLOAD','lib/opauth/');
// in your index.php $f3 = \Base::instance(); // load opauth config (allow token resolve) $f3->config('lib/opauth/opauth.ini', TRUE); // init with config $opauth = OpauthBridge::instance($f3->opauth); // define login handler $opauth->onSuccess(function($data){ header('Content-Type: text'); echo 'User successfully authenticated.'."\n"; print_r($data['info']); }); // define error handler $opauth->onAbort(function($data){ header('Content-Type: text'); echo 'Auth request was canceled.'."\n"; print_r($data); }); $f3->run();
The event handlers can also be callable string:, (*2)
$opauth->onSuccess('\Controller\User->socialLogin');
To login, call a strategy, i.e.http://domain.com/auth/facebook
., (*3)
http://domain.com/auth/facebook
.onSuccess
handler is called and provides you some data from the given strategy.$f3->hash
on multiple fields like username,token,id) - this way you know who has activated a social auth provider and get the chance to load the user based on this.auth/facebook
- instant redirect after successful activation on most providers), and now you can find him in your user table with activated social auth and login him in directly.This is of course just one idea of implementation. Some providers also return tokens for further communication with their 3rd party API (i.e. to fetch more profile data or renew tokens), but that's something this plugin is not going to handle. Have a look at the strategy docs for more information., (*4)
GPLv3, (*5)
Opauth Plugin for PHP Fat-Free Framework
GPL-3.0
f3 authentication oauth auth opauth fatfree