dev-master
9999999-dev
MIT
The Requires
- php >=5.5.9
- league/oauth2-client ~1.4
api oauth oauth2 tibia opentibia pandaac otland
Wallogit.com
2017 © Pedro Peláez
, (*1)
This package allows your site users to authenticate themselves through their OtLand.net account, which in turn returns an object with their OtLand details for you to do which what you see fit., (*2)
composer require pandaac/oauth2-otland
When instantiating the pandaac\OAuth2OtLand\Providers\OtLand object, you may pass an array of options as its first argument., (*3)
clientId key.clientSecret key.redirectUri key.scope key. It defaults to ['read'].The API that OtLand.net uses is bdApi. Please refer to their documentation for anything beyond simple authorization., (*4)
Add the OtLand OAuth2 client service provider to the service providers array in ./config/app.php., (*5)
pandaac\OAuth2OtLand\FrameworkIntegration\Laravel\OtLandOAuth2ServiceProvider::class
You should then publish the package configuration files by running the following artisan command., (*6)
php artisan vendor:publish --provider="pandaac\OAuth2OtLand\FrameworkIntegration\Laravel\OtLandOAuth2ServiceProvider"
You may edit your OAuth2 credentials directly in
./config/oauth2-otland.php, although it is strongly recommended to do so through your.envfile instead (OTLAND_KEY,OTLAND_SECRET&OTLAND_REDIRECT)., (*7)
and finally define a route similiar to that as shown below, (*8)
use Illuminate\Http\Request;
use pandaac\OAuth2OtLand\Providers\OtLand;
$router->get('/otland', function (Request $request) {
try {
$otland = app(OtLand::class);
// Redirect the user to the authorization url if no code was provided
if (! $request->has('code')) {
$url = $otland->getAuthorizationUrl();
$request->session()->put('oauth2state', $otland->getState());
return redirect($url);
}
// If the state is invalid, redirect the user
if (! $request->has('state') or ($request->get('state') !== $request->session()->get('oauth2state'))) {
$request->session()->forget('oauth2state');
return redirect('/');
}
$accessToken = $otland->getAccessToken('authorization_code', [
'code' => $request->get('code')
]);
$owner = $otland->getResourceOwner($accessToken);
dd($owner->toArray());
} catch (Exception $e) {
// Log errors...
}
});
use pandaac\OAuth2OtLand\Providers\OtLand;
session_start();
try {
$otland = new OtLand([
'clientId' => 'MY-CLIENT-ID',
'clientSecret' => 'MY-CLIENT-SECRET',
'redirectUri' => 'MY-REDIRECT-URI',
]);
// Redirect the user to the authorization url if no code was provided
if (! isset($_GET['code'])) {
$url = $otland->getAuthorizationUrl();
$_SESSION['oauth2state'] = $otland->getState();
header('Location: '.$url);
exit;
}
// If the state is invalid, redirect the user
if (! isset($_GET['state']) or ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
header('Location: /');
exit;
}
$accessToken = $otland->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
$owner = $otland->getResourceOwner($accessToken);
var_dump($owner->toArray());
} catch (Exception $e) {
// Log errors...
}
Please refer to the PSR-2 guidelines and squash your commits together into one before submitting a pull request., (*9)
Thank you., (*10)
MIT
api oauth oauth2 tibia opentibia pandaac otland