{"action":"created","comment":{"url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/comments/44522984","id":44522984,"diff_hunk":"@@ -0,0 +1,193 @@\n+<?php\n+\n+namespace plenigo\\internal\\utils;\n+\n+/**\n+ * <p>\n+ * This class implements the generation of JWT Tokens\n+ * </p>\n+ * <p>\n+ * <b>IMPORTANT:</b> This class is part of the internal API, please do not use it, because it can\n+ * be removed in future versions of the SDK or access to such elements could\n+ * be changed from 'public' to 'protected' or less.\n+ * </p>\n+ *\n+ * @category SDK\n+ * @package  PlenigoInternal\n+ * @author   Sebastian Dieguez <s.dieguez@plenigo.com>\n+ * @link     https://www.plenigo.com\n+ *\n+ */\n+class JWT {\n+\n+    /**\n+     * Decodes a JWT string into a PHP object.\n+     *\n+     * @param string      $jwt    The JWT\n+     * @param string|null $key    The secret key\n+     * @param bool        $verify Don't skip verification process \n+     *\n+     * @return object      The JWT's payload as a PHP object\n+     * @throws \\Exception          Algorithm was not provided or the provided JWT was invalid\n+     * \n+     * @uses jsonDecode\n+     * @uses urlsafeB64Decode\n+     */\n+    public static function decode($jwt, $key = null, $verify = true) {\n+        $tks = explode('.', $jwt);\n+        if (count($tks) != 3) {\n+            JWT::_handleRegularError('Wrong number of segments');\n+        }\n+        list($headb64, $bodyb64, $cryptob64) = $tks;\n+        if (null === ($header = JWT::jsonDecode(JWT::urlsafeB64Decode($headb64)))) {\n+            JWT::_handleRegularError('Invalid segment encoding (header)');\n+        }\n+        if (null === $payload = JWT::jsonDecode(JWT::urlsafeB64Decode($bodyb64))) {\n+            JWT::_handleRegularError('Invalid segment encoding (payload)');\n+        }\n+        $sig = JWT::urlsafeB64Decode($cryptob64);\n+        if ($verify) {\n+            if (empty($header->alg)) {\n+                JWT::_handleRegularError('Empty algorithm');\n+            }\n+            if ($sig != JWT::sign(\"$headb64.$bodyb64\", $key)) {\n+                JWT::_handleRegularError('Signature verification failed');\n+            }\n+        }\n+        return $payload;\n+    }\n+\n+    /**\n+     * Converts and signs a PHP object or array into a JWT string.\n+     *\n+     * @param object|array $payload PHP object or array\n+     * @param string       $key     The secret key\n+     *\n+     * @return string      A signed JWT\n+     * @uses jsonEncode\n+     * @uses urlsafeB64Encode\n+     */\n+    public static function encode($payload, $key) {\n+        $header = array('alg' => 'HS256');\n+\n+        $segments = array();\n+        $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));\n+        $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));\n+        $signing_input = implode('.', $segments);\n+\n+        $signature = JWT::sign($signing_input, $key);\n+        $segments[] = JWT::urlsafeB64Encode($signature);\n+\n+        return implode('.', $segments);\n+    }\n+\n+    /**\n+     * Sign a string with a given key and algorithm.\n+     *\n+     * @param string $msg    The message to sign\n+     * @param string $key    The secret key\n+     *\n+     * @return string          An encrypted message\n+     * @throws \\DomainException Unsupported algorithm was specified\n+     */\n+    public static function sign($msg, $key) {\n+        return hash_hmac('sha256', $msg, $key, true);\n+    }\n+\n+    /**\n+     * Decode a JSON string into a PHP object.\n+     *\n+     * @param string $input JSON string\n+     *\n+     * @return object          Object representation of JSON string\n+     * @throws \\Exception Provided string was invalid JSON\n+     */\n+    public static function jsonDecode($input) {","path":"src/plenigo/internal/utils/JWT.php","position":108,"original_position":105,"commit_id":"4313f8f064c7fa2185953bd66052328cbb933b82","original_commit_id":"d1defa3263fb120677d7de179e9bb3ecdcfa6de7","user":{"login":"SebaSOFT","id":2537716,"avatar_url":"https://avatars.githubusercontent.com/u/2537716?v=3","gravatar_id":"","url":"https://api.github.com/users/SebaSOFT","html_url":"https://github.com/SebaSOFT","followers_url":"https://api.github.com/users/SebaSOFT/followers","following_url":"https://api.github.com/users/SebaSOFT/following{/other_user}","gists_url":"https://api.github.com/users/SebaSOFT/gists{/gist_id}","starred_url":"https://api.github.com/users/SebaSOFT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SebaSOFT/subscriptions","organizations_url":"https://api.github.com/users/SebaSOFT/orgs","repos_url":"https://api.github.com/users/SebaSOFT/repos","events_url":"https://api.github.com/users/SebaSOFT/events{/privacy}","received_events_url":"https://api.github.com/users/SebaSOFT/received_events","type":"User","site_admin":false},"body":"We need this for testing, also this is PHP, so server side","created_at":"2015-11-11T11:24:54Z","updated_at":"2015-11-11T11:24:54Z","html_url":"https://github.com/plenigo/plenigo_php_sdk/pull/13#discussion_r44522984","pull_request_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13","_links":{"self":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/comments/44522984"},"html":{"href":"https://github.com/plenigo/plenigo_php_sdk/pull/13#discussion_r44522984"},"pull_request":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13","id":50234641,"html_url":"https://github.com/plenigo/plenigo_php_sdk/pull/13","diff_url":"https://github.com/plenigo/plenigo_php_sdk/pull/13.diff","patch_url":"https://github.com/plenigo/plenigo_php_sdk/pull/13.patch","issue_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/13","number":13,"state":"open","locked":false,"title":"API v2","user":{"login":"SebaSOFT","id":2537716,"avatar_url":"https://avatars.githubusercontent.com/u/2537716?v=3","gravatar_id":"","url":"https://api.github.com/users/SebaSOFT","html_url":"https://github.com/SebaSOFT","followers_url":"https://api.github.com/users/SebaSOFT/followers","following_url":"https://api.github.com/users/SebaSOFT/following{/other_user}","gists_url":"https://api.github.com/users/SebaSOFT/gists{/gist_id}","starred_url":"https://api.github.com/users/SebaSOFT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SebaSOFT/subscriptions","organizations_url":"https://api.github.com/users/SebaSOFT/orgs","repos_url":"https://api.github.com/users/SebaSOFT/repos","events_url":"https://api.github.com/users/SebaSOFT/events{/privacy}","received_events_url":"https://api.github.com/users/SebaSOFT/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-10T10:06:13Z","updated_at":"2015-11-11T11:24:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e01df59268cbd2e25c66d2c8bf2a04dd0c43d1c","assignee":{"login":"maximilianschweitzer","id":115574,"avatar_url":"https://avatars.githubusercontent.com/u/115574?v=3","gravatar_id":"","url":"https://api.github.com/users/maximilianschweitzer","html_url":"https://github.com/maximilianschweitzer","followers_url":"https://api.github.com/users/maximilianschweitzer/followers","following_url":"https://api.github.com/users/maximilianschweitzer/following{/other_user}","gists_url":"https://api.github.com/users/maximilianschweitzer/gists{/gist_id}","starred_url":"https://api.github.com/users/maximilianschweitzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maximilianschweitzer/subscriptions","organizations_url":"https://api.github.com/users/maximilianschweitzer/orgs","repos_url":"https://api.github.com/users/maximilianschweitzer/repos","events_url":"https://api.github.com/users/maximilianschweitzer/events{/privacy}","received_events_url":"https://api.github.com/users/maximilianschweitzer/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13/commits","review_comments_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13/comments","review_comment_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/13/comments","statuses_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/statuses/4313f8f064c7fa2185953bd66052328cbb933b82","head":{"label":"plenigo:PLENIGO-912-update-php-sdk-to-api-v2","ref":"PLENIGO-912-update-php-sdk-to-api-v2","sha":"4313f8f064c7fa2185953bd66052328cbb933b82","user":{"login":"plenigo","id":8374699,"avatar_url":"https://avatars.githubusercontent.com/u/8374699?v=3","gravatar_id":"","url":"https://api.github.com/users/plenigo","html_url":"https://github.com/plenigo","followers_url":"https://api.github.com/users/plenigo/followers","following_url":"https://api.github.com/users/plenigo/following{/other_user}","gists_url":"https://api.github.com/users/plenigo/gists{/gist_id}","starred_url":"https://api.github.com/users/plenigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plenigo/subscriptions","organizations_url":"https://api.github.com/users/plenigo/orgs","repos_url":"https://api.github.com/users/plenigo/repos","events_url":"https://api.github.com/users/plenigo/events{/privacy}","received_events_url":"https://api.github.com/users/plenigo/received_events","type":"Organization","site_admin":false},"repo":{"id":27120947,"name":"plenigo_php_sdk","full_name":"plenigo/plenigo_php_sdk","owner":{"login":"plenigo","id":8374699,"avatar_url":"https://avatars.githubusercontent.com/u/8374699?v=3","gravatar_id":"","url":"https://api.github.com/users/plenigo","html_url":"https://github.com/plenigo","followers_url":"https://api.github.com/users/plenigo/followers","following_url":"https://api.github.com/users/plenigo/following{/other_user}","gists_url":"https://api.github.com/users/plenigo/gists{/gist_id}","starred_url":"https://api.github.com/users/plenigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plenigo/subscriptions","organizations_url":"https://api.github.com/users/plenigo/orgs","repos_url":"https://api.github.com/users/plenigo/repos","events_url":"https://api.github.com/users/plenigo/events{/privacy}","received_events_url":"https://api.github.com/users/plenigo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/plenigo/plenigo_php_sdk","description":"plenigo SDK for PHP","fork":false,"url":"https://api.github.com/repos/plenigo/plenigo_php_sdk","forks_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/forks","keys_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/teams","hooks_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/hooks","issue_events_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/events{/number}","events_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/events","assignees_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/assignees{/user}","branches_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/branches{/branch}","tags_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/tags","blobs_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/languages","stargazers_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/stargazers","contributors_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/contributors","subscribers_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/subscribers","subscription_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/subscription","commits_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/contents/{+path}","compare_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/merges","archive_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/downloads","issues_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues{/number}","pulls_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/labels{/name}","releases_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/releases{/id}","created_at":"2014-11-25T10:36:54Z","updated_at":"2015-05-08T13:05:36Z","pushed_at":"2015-11-10T20:00:46Z","git_url":"git://github.com/plenigo/plenigo_php_sdk.git","ssh_url":"git@github.com:plenigo/plenigo_php_sdk.git","clone_url":"https://github.com/plenigo/plenigo_php_sdk.git","svn_url":"https://github.com/plenigo/plenigo_php_sdk","homepage":null,"size":1052,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":5,"default_branch":"master"}},"base":{"label":"plenigo:master","ref":"master","sha":"c7a230a86281d40ff7d971bcf2b2fae3868bdc90","user":{"login":"plenigo","id":8374699,"avatar_url":"https://avatars.githubusercontent.com/u/8374699?v=3","gravatar_id":"","url":"https://api.github.com/users/plenigo","html_url":"https://github.com/plenigo","followers_url":"https://api.github.com/users/plenigo/followers","following_url":"https://api.github.com/users/plenigo/following{/other_user}","gists_url":"https://api.github.com/users/plenigo/gists{/gist_id}","starred_url":"https://api.github.com/users/plenigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plenigo/subscriptions","organizations_url":"https://api.github.com/users/plenigo/orgs","repos_url":"https://api.github.com/users/plenigo/repos","events_url":"https://api.github.com/users/plenigo/events{/privacy}","received_events_url":"https://api.github.com/users/plenigo/received_events","type":"Organization","site_admin":false},"repo":{"id":27120947,"name":"plenigo_php_sdk","full_name":"plenigo/plenigo_php_sdk","owner":{"login":"plenigo","id":8374699,"avatar_url":"https://avatars.githubusercontent.com/u/8374699?v=3","gravatar_id":"","url":"https://api.github.com/users/plenigo","html_url":"https://github.com/plenigo","followers_url":"https://api.github.com/users/plenigo/followers","following_url":"https://api.github.com/users/plenigo/following{/other_user}","gists_url":"https://api.github.com/users/plenigo/gists{/gist_id}","starred_url":"https://api.github.com/users/plenigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plenigo/subscriptions","organizations_url":"https://api.github.com/users/plenigo/orgs","repos_url":"https://api.github.com/users/plenigo/repos","events_url":"https://api.github.com/users/plenigo/events{/privacy}","received_events_url":"https://api.github.com/users/plenigo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/plenigo/plenigo_php_sdk","description":"plenigo SDK for PHP","fork":false,"url":"https://api.github.com/repos/plenigo/plenigo_php_sdk","forks_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/forks","keys_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/teams","hooks_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/hooks","issue_events_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/events{/number}","events_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/events","assignees_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/assignees{/user}","branches_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/branches{/branch}","tags_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/tags","blobs_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/languages","stargazers_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/stargazers","contributors_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/contributors","subscribers_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/subscribers","subscription_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/subscription","commits_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/contents/{+path}","compare_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/merges","archive_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/downloads","issues_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues{/number}","pulls_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/labels{/name}","releases_url":"https://api.github.com/repos/plenigo/plenigo_php_sdk/releases{/id}","created_at":"2014-11-25T10:36:54Z","updated_at":"2015-05-08T13:05:36Z","pushed_at":"2015-11-10T20:00:46Z","git_url":"git://github.com/plenigo/plenigo_php_sdk.git","ssh_url":"git@github.com:plenigo/plenigo_php_sdk.git","clone_url":"https://github.com/plenigo/plenigo_php_sdk.git","svn_url":"https://github.com/plenigo/plenigo_php_sdk","homepage":null,"size":1052,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13"},"html":{"href":"https://github.com/plenigo/plenigo_php_sdk/pull/13"},"issue":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/13"},"comments":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/plenigo/plenigo_php_sdk/statuses/4313f8f064c7fa2185953bd66052328cbb933b82"}}}}