1. Go to this page and download the library: Download ash-rain/oauth2-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ash-rain / oauth2-server example snippets
$storage = new Dingo\OAuth2\Storage\MySqlAdapter(new PDO('mysql:host=localhost;dbname=oauth', 'root'));
$storage = new Dingo\OAuth2\Storage\MySqlAdapter(new PDO('mysql:host=localhost;dbname=oauth', 'root'));
$server = new Dingo\OAuth2\Server\Authorization($storage);
$server->setAuthorizedCallback(function($token, $client)
{
// Insert a record into your database showing that $token->getUserId() has authorized
// $client->getId() with $token->getScopes() and that in the future the server
// can skip the prompt.
});
$storage = new Dingo\OAuth2\Storage\MySqlAdapter(new PDO('mysql:host=localhost;dbname=oauth', 'root'));
$server = new Dingo\OAuth2\Server\Resource($storage);
html+php
// If the user is not logged in we'll redirect them to the login form
// with the query string that was sent with the initial request.
// The login form is not within the scope of this guide.
if ( ! isset($_SESSION['user_id']))
{
header("Location: /login?{$_SERVER['QUERY_STRING']}");
}
else
{
try
{
$payload = $server->validateAuthorizationRequest();
}
catch (Dingo\OAuth2\Exception\ClientException $exception)
{
echo $exception->getMessage();
exit;
}
if (isset($_POST['submit']) or $payload['client']->isTrusted())
{
$response = $server->handleAuthorizationRequest($payload['client_id'], $_SESSION['user_id'], $payload['redirect_uri'], $payload['scopes']);
header("Location: {$server->makeRedirectUri($response)}");
}
else
{
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.