Php Samples
This tutorial assumes you already have:
- PHP 5.4 or greater
- CURL extension
- JSON extension
Install library using composer
composer require jumbojett/openid-connect-php
Include composer autoloader
require __DIR__ . '/vendor/autoload.php';
use Jumbojett\OpenIDConnectClient;
$oidc = new OpenIDConnectClient('https://hmcopenidserver.azurewebsites.net',
'Test',
'Test');
$oidc->providerConfigParam(array('token_endpoint'=>'https://hmcopenidserver.azurewebsites.net/connect/token'));
$oidc->addScope('OperationTimes'); // name of api -> change it according to the API accessed
// this assumes success (to validate check if the access_token property is there and a valid JWT) :
$clientCredentialsToken = $oidc->requestClientCredentialsToken()->access_token;
More info at : https://github.com/jumbojett/OpenID-Connect-PHP
//API Url
$url = 'https://hmcoperationtimesapi.azurewebsites.net/ServerConfiguration';
$authorization = "Authorization: Bearer ";
$authorization .= $clientCredentialsToken;
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$fields = array(
'email' => 'test@example.com',
'grouphunt1' => '222' // see the api page for further fields information
);
$jsonData = array(
'DataName' => 'ext',
'DataValue' => '111',
'Fields' => $fields
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',$authorization));
//Execute the request
$result = curl_exec($ch);