commit 50f06d3aa240d2f5c1c51b139447843d1dc771cd Author: Florian Weiss Date: Thu Mar 26 12:56:55 2020 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0caea8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +vendor/ \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1e30f8d --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ +{ + "require": { + "guzzlehttp/guzzle": "^6.5", + "ext-json": "*" + }, + "autoload": { + "files": [ "src/Constants/VerificationTypes.php" ], + "psr-4": { + "SkillDisplay\\APIToolKit\\": "src/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..63d9755 --- /dev/null +++ b/composer.lock @@ -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": [] +} diff --git a/src/Configuration/Settings.php b/src/Configuration/Settings.php new file mode 100644 index 0000000..56306cb --- /dev/null +++ b/src/Configuration/Settings.php @@ -0,0 +1,59 @@ +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; + } +} + diff --git a/src/Constants/VerificationTypes.php b/src/Constants/VerificationTypes.php new file mode 100644 index 0000000..67ddef5 --- /dev/null +++ b/src/Constants/VerificationTypes.php @@ -0,0 +1,6 @@ +issueVerification(193,'--skilldisplay-user-email--', VERIFICATION_SELF); \ No newline at end of file diff --git a/src/Verification/Issuer.php b/src/Verification/Issuer.php new file mode 100644 index 0000000..c92fe04 --- /dev/null +++ b/src/Verification/Issuer.php @@ -0,0 +1,80 @@ + $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; + } +} \ No newline at end of file