mirror of
https://github.com/SkillDisplay/PHPToolKit.git
synced 2024-11-21 23:46:09 +01:00
Initial commit
This commit is contained in:
commit
50f06d3aa2
7 changed files with 476 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.idea/
|
||||||
|
vendor/
|
12
composer.json
Normal file
12
composer.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"guzzlehttp/guzzle": "^6.5",
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [ "src/Constants/VerificationTypes.php" ],
|
||||||
|
"psr-4": {
|
||||||
|
"SkillDisplay\\APIToolKit\\": "src/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
299
composer.lock
generated
Normal file
299
composer.lock
generated
Normal file
|
@ -0,0 +1,299 @@
|
||||||
|
{
|
||||||
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
|
"This file is @generated automatically"
|
||||||
|
],
|
||||||
|
"content-hash": "26bc3fcd8e6773b5e967b4f19db19768",
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "guzzlehttp/guzzle",
|
||||||
|
"version": "6.5.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/guzzle/guzzle.git",
|
||||||
|
"reference": "43ece0e75098b7ecd8d13918293029e555a50f82"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/43ece0e75098b7ecd8d13918293029e555a50f82",
|
||||||
|
"reference": "43ece0e75098b7ecd8d13918293029e555a50f82",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-json": "*",
|
||||||
|
"guzzlehttp/promises": "^1.0",
|
||||||
|
"guzzlehttp/psr7": "^1.6.1",
|
||||||
|
"php": ">=5.5"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"ext-curl": "*",
|
||||||
|
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
|
||||||
|
"psr/log": "^1.1"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
|
||||||
|
"psr/log": "Required for using the Log middleware"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "6.5-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"GuzzleHttp\\": "src/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/functions_include.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Michael Dowling",
|
||||||
|
"email": "mtdowling@gmail.com",
|
||||||
|
"homepage": "https://github.com/mtdowling"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Guzzle is a PHP HTTP client library",
|
||||||
|
"homepage": "http://guzzlephp.org/",
|
||||||
|
"keywords": [
|
||||||
|
"client",
|
||||||
|
"curl",
|
||||||
|
"framework",
|
||||||
|
"http",
|
||||||
|
"http client",
|
||||||
|
"rest",
|
||||||
|
"web service"
|
||||||
|
],
|
||||||
|
"time": "2019-12-23T11:57:10+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "guzzlehttp/promises",
|
||||||
|
"version": "v1.3.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/guzzle/promises.git",
|
||||||
|
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||||
|
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.5.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^4.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.4-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"GuzzleHttp\\Promise\\": "src/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/functions_include.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Michael Dowling",
|
||||||
|
"email": "mtdowling@gmail.com",
|
||||||
|
"homepage": "https://github.com/mtdowling"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Guzzle promises library",
|
||||||
|
"keywords": [
|
||||||
|
"promise"
|
||||||
|
],
|
||||||
|
"time": "2016-12-20T10:07:11+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "guzzlehttp/psr7",
|
||||||
|
"version": "1.6.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/guzzle/psr7.git",
|
||||||
|
"reference": "239400de7a173fe9901b9ac7c06497751f00727a"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a",
|
||||||
|
"reference": "239400de7a173fe9901b9ac7c06497751f00727a",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.4.0",
|
||||||
|
"psr/http-message": "~1.0",
|
||||||
|
"ralouphie/getallheaders": "^2.0.5 || ^3.0.0"
|
||||||
|
},
|
||||||
|
"provide": {
|
||||||
|
"psr/http-message-implementation": "1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"ext-zlib": "*",
|
||||||
|
"phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"zendframework/zend-httphandlerrunner": "Emit PSR-7 responses"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.6-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"GuzzleHttp\\Psr7\\": "src/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/functions_include.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Michael Dowling",
|
||||||
|
"email": "mtdowling@gmail.com",
|
||||||
|
"homepage": "https://github.com/mtdowling"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Tobias Schultze",
|
||||||
|
"homepage": "https://github.com/Tobion"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||||
|
"keywords": [
|
||||||
|
"http",
|
||||||
|
"message",
|
||||||
|
"psr-7",
|
||||||
|
"request",
|
||||||
|
"response",
|
||||||
|
"stream",
|
||||||
|
"uri",
|
||||||
|
"url"
|
||||||
|
],
|
||||||
|
"time": "2019-07-01T23:21:34+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "psr/http-message",
|
||||||
|
"version": "1.0.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-fig/http-message.git",
|
||||||
|
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||||
|
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Psr\\Http\\Message\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "PHP-FIG",
|
||||||
|
"homepage": "http://www.php-fig.org/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Common interface for HTTP messages",
|
||||||
|
"homepage": "https://github.com/php-fig/http-message",
|
||||||
|
"keywords": [
|
||||||
|
"http",
|
||||||
|
"http-message",
|
||||||
|
"psr",
|
||||||
|
"psr-7",
|
||||||
|
"request",
|
||||||
|
"response"
|
||||||
|
],
|
||||||
|
"time": "2016-08-06T14:39:51+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ralouphie/getallheaders",
|
||||||
|
"version": "3.0.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/ralouphie/getallheaders.git",
|
||||||
|
"reference": "120b605dfeb996808c31b6477290a714d356e822"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
|
||||||
|
"reference": "120b605dfeb996808c31b6477290a714d356e822",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.6"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"php-coveralls/php-coveralls": "^2.1",
|
||||||
|
"phpunit/phpunit": "^5 || ^6.5"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/getallheaders.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Ralph Khattar",
|
||||||
|
"email": "ralph.khattar@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A polyfill for getallheaders.",
|
||||||
|
"time": "2019-03-08T08:55:37+00:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": [],
|
||||||
|
"aliases": [],
|
||||||
|
"minimum-stability": "stable",
|
||||||
|
"stability-flags": [],
|
||||||
|
"prefer-stable": false,
|
||||||
|
"prefer-lowest": false,
|
||||||
|
"platform": {
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"platform-dev": []
|
||||||
|
}
|
59
src/Configuration/Settings.php
Normal file
59
src/Configuration/Settings.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SkillDisplay\APIToolKit\Configuration;
|
||||||
|
|
||||||
|
class Settings{
|
||||||
|
|
||||||
|
private string $user_secret = '';
|
||||||
|
private string $apiKey = '';
|
||||||
|
private int $verifierID = 0;
|
||||||
|
private string $verificationURL = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getVerifierID(): int
|
||||||
|
{
|
||||||
|
return $this->verifierID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUserSecret(): string
|
||||||
|
{
|
||||||
|
return $this->user_secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getApiKey(): string
|
||||||
|
{
|
||||||
|
return $this->apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getVerificationURL(): string
|
||||||
|
{
|
||||||
|
return $this->verificationURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings constructor.
|
||||||
|
* @param string $apiKey API Key to allow the application to use the endpoint
|
||||||
|
* @param int $verifierID ID of the Verifier entry, necessary for Educational-Verification, Business-Verification or Certification
|
||||||
|
* @param string $user_secret Secret Key of the Verifier - necessary for Educational-Verification, Business-Verification or Certification
|
||||||
|
* @param string|null $verificationURL URL of the SkillDisplay instance - usually this will be the public one on skilldisplay.eu
|
||||||
|
*/
|
||||||
|
public function __construct(string $apiKey, int $verifierID = 0, string $user_secret = '', string $verificationURL = null)
|
||||||
|
{
|
||||||
|
$this->apiKey = $apiKey;
|
||||||
|
$this->verifierID = $verifierID;
|
||||||
|
$this->user_secret = $user_secret;
|
||||||
|
$this->verificationURL = (is_null($verificationURL)) ? 'https://dev.skilldisplay.eu/api/v1/verification/create' : $verificationURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
6
src/Constants/VerificationTypes.php
Normal file
6
src/Constants/VerificationTypes.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
define('VERIFICATION_SELF', 'self');
|
||||||
|
define('VERIFICATION_EDUCATIONAL', 'educational');
|
||||||
|
define('VERIFICATION_BUSINESS', 'business');
|
||||||
|
define('VERIFICATION_CERTIFICATION', 'certification');
|
18
src/Example/VerificationGrantExample.php
Normal file
18
src/Example/VerificationGrantExample.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SkillDisplay\APIToolKit\Example;
|
||||||
|
|
||||||
|
require '../../vendor/autoload.php';
|
||||||
|
|
||||||
|
use SkillDisplay\APIToolKit\Configuration\Settings;
|
||||||
|
use SkillDisplay\APIToolKit\Verification\Issuer;
|
||||||
|
|
||||||
|
$mySettings = new Settings(
|
||||||
|
'---YOUR-API-KEY---',
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
$myVerificationTool = new Issuer($mySettings);
|
||||||
|
$myVerificationTool->issueVerification(193,'--skilldisplay-user-email--', VERIFICATION_SELF);
|
80
src/Verification/Issuer.php
Normal file
80
src/Verification/Issuer.php
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SkillDisplay\APIToolKit\Verification;
|
||||||
|
|
||||||
|
use GuzzleHttp\Psr7\Request;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use SkillDisplay\APIToolKit\Configuration\Settings;
|
||||||
|
|
||||||
|
class Issuer {
|
||||||
|
private Settings $settings;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @param int $skillID ID of the Skill or SkillSet
|
||||||
|
* @param string $useremail E-Mail of the User who should receive the verification
|
||||||
|
* @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function generateSignedRequestData(int $skillID, string $useremail, string $vtype) : array {
|
||||||
|
$requestData = [
|
||||||
|
"SkillId" => $skillID,
|
||||||
|
"Level" => $vtype,
|
||||||
|
"VerifierId" => $this->settings->getVerifierID(),
|
||||||
|
"Username" => $useremail,
|
||||||
|
"AutoConfirm" => true,
|
||||||
|
"Signature" => ''
|
||||||
|
];
|
||||||
|
|
||||||
|
$json = json_encode($requestData);
|
||||||
|
$signature = ($vtype==="self") ? 'sdself' : $this->settings->getUserSecret();
|
||||||
|
$requestData['Signature'] = hash('sha256', $json . $signature);
|
||||||
|
|
||||||
|
return $requestData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ResponseInterface $response Response of a performed request
|
||||||
|
*
|
||||||
|
* Outputs a response of a request directly on the page
|
||||||
|
*/
|
||||||
|
private function outputResponse(ResponseInterface $response){
|
||||||
|
// Get all of the response headers.
|
||||||
|
foreach ($response->getHeaders() as $name => $values) {
|
||||||
|
echo $name . ': ' . implode(', ', $values) . "\r\n";
|
||||||
|
}
|
||||||
|
$body = $response->getBody();
|
||||||
|
echo $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @param int $skillID SkillID of the skill for which the verification should be issued (can be read from URL after a search - eg.: https://my.dev.skilldisplay.eu/skill/4/0 has ID 4)
|
||||||
|
* @param string $useremail E-Mail of the SkillDisplay user for whom you want to verify the skill
|
||||||
|
* @param string $vtype Verification type, one of the constants in /src/Constants/VerificationTypes.php
|
||||||
|
*/
|
||||||
|
public function issueVerification(int $skillID, string $useremail, string $vtype){
|
||||||
|
$requestData = $this->generateSignedRequestData($skillID, $useremail, $vtype);
|
||||||
|
|
||||||
|
$client = new \GuzzleHttp\Client();
|
||||||
|
$request = new Request(
|
||||||
|
'POST',
|
||||||
|
$this->settings->getVerificationURL(),
|
||||||
|
array(
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'x-api-key' => $this->settings->getApiKey()
|
||||||
|
),
|
||||||
|
json_encode($requestData)
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $client->send($request);
|
||||||
|
$this->outputResponse($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Issuer constructor.
|
||||||
|
* @param Settings $settings Pass the settings for the Verification API
|
||||||
|
*/
|
||||||
|
public function __construct(Settings $settings)
|
||||||
|
{
|
||||||
|
$this->settings = $settings;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue