oauth2-server-php-docs
oauth2-server-php-docs copied to clipboard
Document OpenID Connect
Document OpenID Connect integration
Hi there,
Is there any documentation about this feature?
Thanks!
I'll wrote a small guide here.
-
Enable OpenID Connect with the option
'use_openid_connect' => true -
Then create a custom
Authorize Controllersimilar to Step-By-Step Walkthrough
// include our OAuth2 Server object
require_once __DIR__.'/server.php';
$request = OAuth2\Request::createFromGlobals();
$response = new OAuth2\Response();
// validate the authorize request
if (!$server->validateAuthorizeRequest($request, $response)) {
$response->send();
die;
}
// display an authorization form
if (empty($_POST)) {
exit('
<form method="post">
**<label>Username <input type="text" name="username" /></label><br />**
**<label>password <input type="password" name="password" /></label><br />**
<label>Do You Authorize TestClient?</label><br />
<input type="submit" name="authorized" value="yes">
<input type="submit" name="authorized" value="no">
</form>');
}
// ** Validate User **
// Clean input from attack threads
$sanitizedUsername = mySatinizeFunction($_POST['username']);
$sanitizedPassword = mySatinizeFunction($_POST['password']);
// A User credentials storage or any other custom class for validate the input pair.
$storage = new OAuth2\Storage\Memory(array('user_credentials' => $users));
if (!$storage->checkUserCredentials($sanitizedUsername, $sanitizedPassword) {
exit("wrong username/password");
}
$userDetails = $storage->getUserDetails($sanitizedUsername);
$user_id = $userDetails['user_id'];
// ** Validate User (END) **
// print the authorization code if the user has authorized your client
$is_authorized = ($_POST['authorized'] === 'yes');
$server->handleAuthorizeRequest($request, $response, $is_authorized, **$user_id**);
if ($is_authorized) {
// this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
exit("SUCCESS! Authorization Code: $code");
}
$response->send();
Note: I've put * around the changes made from the step-by-step guide
Hi,
can somone confirm, that Maks3w approach is correct ? For me it seems like customization on OAuth, not a valid use of OpenID connect.
Don't take me wrong, it took me whilte to understand, that OAuth is for authorization and OpenID connect is for authentication, but i don't know hot to connect these two things.
Is there any tutorial about setting up OpenID Connect on top of OAuth2 ? I will appreciate any help.
OpenID Connect is now documented here