/**
  * Construct an IDToken object from an encoded id_token string.
  *
  * @param string $idtoken An encoded id_token string.
  * @return \remotelearner\aadsample\OIDC\IDTokenInterface An IDToken object.
  */
 protected function constructidtoken($idtoken)
 {
     $httpclient = new \remotelearner\aadsample\HttpClient();
     $keys = IDToken::get_keys($httpclient);
     return \remotelearner\aadsample\AAD\IDToken::instance_from_encoded($idtoken, $keys);
 }
 * @license MIT
 * @copyright (C) 2016 onwards Microsoft Corporation (http://microsoft.com/)
 */
require __DIR__ . '/../../vendor/autoload.php';
// Construct.
$httpclient = new \remotelearner\aadsample\HttpClient();
$storage = new \remotelearner\aadsample\OIDC\StorageProviders\SQLite(__DIR__ . '/storagedb.sqlite');
$client = new \remotelearner\aadsample\AAD\Client($httpclient, $storage);
// Set credentials.
require __DIR__ . '/config.php';
if (!defined('AADSAMPLE_CLIENTID') || empty(AADSAMPLE_CLIENTID)) {
    throw new \Exception('No client ID set - please set in config.php');
}
$client->set_clientid(AADSAMPLE_CLIENTID);
if (!defined('AADSAMPLE_CLIENTSECRET') || empty(AADSAMPLE_CLIENTSECRET)) {
    throw new \Exception('No client secret set - please set in config.php');
}
$client->set_clientsecret(AADSAMPLE_CLIENTSECRET);
if (!defined('AADSAMPLE_CLIENTREDIRECTURI') || empty(AADSAMPLE_CLIENTREDIRECTURI)) {
    throw new \Exception('No redirect URI set - please set in config.php');
}
$client->set_redirecturi(AADSAMPLE_CLIENTREDIRECTURI);
// Make request.
$returned = $client->rocredsrequest($_POST['username'], $_POST['password']);
// Process id token.
$idtoken = \remotelearner\aadsample\AAD\IDToken::instance_from_encoded($returned['id_token']);
// Output.
echo '<h1>Welcome to the PHP Azure AD Demo</h1>';
echo '<h2>Hello, ' . $idtoken->claim('name') . ' (' . $idtoken->claim('upn') . '). </h2>';
echo '<h4>You have successfully authenticated with Azure AD using OpenID Connect. ' . 'This is just a demo, but the libraries contained in this package will provide an OpenID Connect idtoken and an ' . 'oAuth2 access token to use Azure AD APIs</h4>';
echo '<a href="index.php">Click here start again.</a>';