{"action":"created","comment":{"url":"https://api.github.com/repos/google/google-auth-library-php/pulls/comments/30206340","id":30206340,"diff_hunk":"@@ -104,4 +104,102 @@ public function getCacheKey()\n     }\n     return $key;\n   }\n+\n+  /**\n+   * Updates metadata with the authorization token\n+   *\n+   * @param $metadata array metadata hashmap\n+   * @param $authUri string optional auth uri\n+   * @param $client optional client interface\n+   *\n+   * @return array updated metadata hashmap\n+   */\n+  public function updateMetadata($metadata,\n+                                 $authUri = null,\n+                                 ClientInterface $client = null)\n+  {\n+    // scope exists. use oauth implementation\n+    $scope = $this->auth->getScope();\n+    if (!is_null($scope)) {\n+      return parent::updateMetadata($metadata, $authUri, $client);\n+    }\n+\n+    // no scope found. create jwt with the auth uri\n+    $credJson = array(\n+      'private_key' => $this->auth->getSigningKey(),\n+      'client_email' => $this->auth->getIssuer(),\n+    );\n+    $jwtCreds = new ServiceAccountJwtAccessCredentials($credJson);\n+    return $jwtCreds->updateMetadata($metadata, $authUri, $client);\n+  }\n+}\n+\n+/**\n+ * Authenticates requests using Google's Service Account credentials via\n+ * JWT Access.\n+ *\n+ * This class allows authorizing requests for service accounts directly\n+ * from credentials from a json key file downloaded from the developer\n+ * console (via 'Generate new Json Key').  It is not part of any OAuth2\n+ * flow, rather it creates a JWT and sends that as a credential.\n+ */\n+class ServiceAccountJwtAccessCredentials extends CredentialsLoader","path":"src/ServiceAccountCredentials.php","position":43,"original_position":43,"commit_id":"87b8045a5144356bc828a7e796492ed119ae98cd","original_commit_id":"87b8045a5144356bc828a7e796492ed119ae98cd","user":{"login":"kesar","id":1288106,"avatar_url":"https://avatars.githubusercontent.com/u/1288106?v=3","gravatar_id":"","url":"https://api.github.com/users/kesar","html_url":"https://github.com/kesar","followers_url":"https://api.github.com/users/kesar/followers","following_url":"https://api.github.com/users/kesar/following{/other_user}","gists_url":"https://api.github.com/users/kesar/gists{/gist_id}","starred_url":"https://api.github.com/users/kesar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kesar/subscriptions","organizations_url":"https://api.github.com/users/kesar/orgs","repos_url":"https://api.github.com/users/kesar/repos","events_url":"https://api.github.com/users/kesar/events{/privacy}","received_events_url":"https://api.github.com/users/kesar/received_events","type":"User","site_admin":false},"body":"I would add this class in a different file. At the same time now that there are two different ServiceAccountCredentials an interface could make sense with the method  updateMetadata","created_at":"2015-05-13T06:58:44Z","updated_at":"2015-05-13T06:58:44Z","html_url":"https://github.com/google/google-auth-library-php/pull/44#discussion_r30206340","pull_request_url":"https://api.github.com/repos/google/google-auth-library-php/pulls/44","_links":{"self":{"href":"https://api.github.com/repos/google/google-auth-library-php/pulls/comments/30206340"},"html":{"href":"https://github.com/google/google-auth-library-php/pull/44#discussion_r30206340"},"pull_request":{"href":"https://api.github.com/repos/google/google-auth-library-php/pulls/44"}}},"pull_request":{"url":"https://api.github.com/repos/google/google-auth-library-php/pulls/44","id":35296041,"html_url":"https://github.com/google/google-auth-library-php/pull/44","diff_url":"https://github.com/google/google-auth-library-php/pull/44.diff","patch_url":"https://github.com/google/google-auth-library-php/pull/44.patch","issue_url":"https://api.github.com/repos/google/google-auth-library-php/issues/44","number":44,"state":"open","locked":false,"title":"Add jwt access credentials","user":{"login":"stanley-cheung","id":11674202,"avatar_url":"https://avatars.githubusercontent.com/u/11674202?v=3","gravatar_id":"","url":"https://api.github.com/users/stanley-cheung","html_url":"https://github.com/stanley-cheung","followers_url":"https://api.github.com/users/stanley-cheung/followers","following_url":"https://api.github.com/users/stanley-cheung/following{/other_user}","gists_url":"https://api.github.com/users/stanley-cheung/gists{/gist_id}","starred_url":"https://api.github.com/users/stanley-cheung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stanley-cheung/subscriptions","organizations_url":"https://api.github.com/users/stanley-cheung/orgs","repos_url":"https://api.github.com/users/stanley-cheung/repos","events_url":"https://api.github.com/users/stanley-cheung/events{/privacy}","received_events_url":"https://api.github.com/users/stanley-cheung/received_events","type":"User","site_admin":false},"body":" * Add ServiceAccountJwtAccessCredentials class\r\n * Change updateMetadata callback function signature to accept authUri parameter\r\n * if no scope is set in ServiceAccountCredentials, use ServiceAccountJwtAccessCredentials instead\r\n * to calculate the token for the ServiceAccountJwtAccessCredentials class, use the passed in authUri to encode the JWT. no outbound call needs to be made\r\n * add some unit tests","created_at":"2015-05-13T05:46:41Z","updated_at":"2015-05-13T06:58:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1fb03686e466c2869a8b7f9a07624cb2e6b0b10","assignee":{"login":"tbetbetbe","id":9272342,"avatar_url":"https://avatars.githubusercontent.com/u/9272342?v=3","gravatar_id":"","url":"https://api.github.com/users/tbetbetbe","html_url":"https://github.com/tbetbetbe","followers_url":"https://api.github.com/users/tbetbetbe/followers","following_url":"https://api.github.com/users/tbetbetbe/following{/other_user}","gists_url":"https://api.github.com/users/tbetbetbe/gists{/gist_id}","starred_url":"https://api.github.com/users/tbetbetbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tbetbetbe/subscriptions","organizations_url":"https://api.github.com/users/tbetbetbe/orgs","repos_url":"https://api.github.com/users/tbetbetbe/repos","events_url":"https://api.github.com/users/tbetbetbe/events{/privacy}","received_events_url":"https://api.github.com/users/tbetbetbe/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/google/google-auth-library-php/pulls/44/commits","review_comments_url":"https://api.github.com/repos/google/google-auth-library-php/pulls/44/comments","review_comment_url":"https://api.github.com/repos/google/google-auth-library-php/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/google-auth-library-php/issues/44/comments","statuses_url":"https://api.github.com/repos/google/google-auth-library-php/statuses/87b8045a5144356bc828a7e796492ed119ae98cd","head":{"label":"stanley-cheung:add_jwt_access_credentials","ref":"add_jwt_access_credentials","sha":"87b8045a5144356bc828a7e796492ed119ae98cd","user":{"login":"stanley-cheung","id":11674202,"avatar_url":"https://avatars.githubusercontent.com/u/11674202?v=3","gravatar_id":"","url":"https://api.github.com/users/stanley-cheung","html_url":"https://github.com/stanley-cheung","followers_url":"https://api.github.com/users/stanley-cheung/followers","following_url":"https://api.github.com/users/stanley-cheung/following{/other_user}","gists_url":"https://api.github.com/users/stanley-cheung/gists{/gist_id}","starred_url":"https://api.github.com/users/stanley-cheung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stanley-cheung/subscriptions","organizations_url":"https://api.github.com/users/stanley-cheung/orgs","repos_url":"https://api.github.com/users/stanley-cheung/repos","events_url":"https://api.github.com/users/stanley-cheung/events{/privacy}","received_events_url":"https://api.github.com/users/stanley-cheung/received_events","type":"User","site_admin":false},"repo":{"id":34537046,"name":"google-auth-library-php","full_name":"stanley-cheung/google-auth-library-php","owner":{"login":"stanley-cheung","id":11674202,"avatar_url":"https://avatars.githubusercontent.com/u/11674202?v=3","gravatar_id":"","url":"https://api.github.com/users/stanley-cheung","html_url":"https://github.com/stanley-cheung","followers_url":"https://api.github.com/users/stanley-cheung/followers","following_url":"https://api.github.com/users/stanley-cheung/following{/other_user}","gists_url":"https://api.github.com/users/stanley-cheung/gists{/gist_id}","starred_url":"https://api.github.com/users/stanley-cheung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stanley-cheung/subscriptions","organizations_url":"https://api.github.com/users/stanley-cheung/orgs","repos_url":"https://api.github.com/users/stanley-cheung/repos","events_url":"https://api.github.com/users/stanley-cheung/events{/privacy}","received_events_url":"https://api.github.com/users/stanley-cheung/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stanley-cheung/google-auth-library-php","description":"Google Auth Library for PHP","fork":true,"url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php","forks_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/forks","keys_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/teams","hooks_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/hooks","issue_events_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/issues/events{/number}","events_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/events","assignees_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/assignees{/user}","branches_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/branches{/branch}","tags_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/tags","blobs_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/statuses/{sha}","languages_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/languages","stargazers_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/stargazers","contributors_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/contributors","subscribers_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/subscribers","subscription_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/subscription","commits_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/contents/{+path}","compare_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/merges","archive_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/downloads","issues_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/issues{/number}","pulls_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/pulls{/number}","milestones_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/milestones{/number}","notifications_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/labels{/name}","releases_url":"https://api.github.com/repos/stanley-cheung/google-auth-library-php/releases{/id}","created_at":"2015-04-24T19:17:22Z","updated_at":"2015-05-07T17:37:49Z","pushed_at":"2015-05-13T06:08:34Z","git_url":"git://github.com/stanley-cheung/google-auth-library-php.git","ssh_url":"git@github.com:stanley-cheung/google-auth-library-php.git","clone_url":"https://github.com/stanley-cheung/google-auth-library-php.git","svn_url":"https://github.com/stanley-cheung/google-auth-library-php","homepage":"","size":313,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"732e11f276216932dcfa3bbc46a644164c2bdf70","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":25315941,"name":"google-auth-library-php","full_name":"google/google-auth-library-php","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/google-auth-library-php","description":"Google Auth Library for PHP","fork":false,"url":"https://api.github.com/repos/google/google-auth-library-php","forks_url":"https://api.github.com/repos/google/google-auth-library-php/forks","keys_url":"https://api.github.com/repos/google/google-auth-library-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/google-auth-library-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/google-auth-library-php/teams","hooks_url":"https://api.github.com/repos/google/google-auth-library-php/hooks","issue_events_url":"https://api.github.com/repos/google/google-auth-library-php/issues/events{/number}","events_url":"https://api.github.com/repos/google/google-auth-library-php/events","assignees_url":"https://api.github.com/repos/google/google-auth-library-php/assignees{/user}","branches_url":"https://api.github.com/repos/google/google-auth-library-php/branches{/branch}","tags_url":"https://api.github.com/repos/google/google-auth-library-php/tags","blobs_url":"https://api.github.com/repos/google/google-auth-library-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/google-auth-library-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/google-auth-library-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/google-auth-library-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/google-auth-library-php/statuses/{sha}","languages_url":"https://api.github.com/repos/google/google-auth-library-php/languages","stargazers_url":"https://api.github.com/repos/google/google-auth-library-php/stargazers","contributors_url":"https://api.github.com/repos/google/google-auth-library-php/contributors","subscribers_url":"https://api.github.com/repos/google/google-auth-library-php/subscribers","subscription_url":"https://api.github.com/repos/google/google-auth-library-php/subscription","commits_url":"https://api.github.com/repos/google/google-auth-library-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/google-auth-library-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/google-auth-library-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/google-auth-library-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/google-auth-library-php/contents/{+path}","compare_url":"https://api.github.com/repos/google/google-auth-library-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/google-auth-library-php/merges","archive_url":"https://api.github.com/repos/google/google-auth-library-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/google-auth-library-php/downloads","issues_url":"https://api.github.com/repos/google/google-auth-library-php/issues{/number}","pulls_url":"https://api.github.com/repos/google/google-auth-library-php/pulls{/number}","milestones_url":"https://api.github.com/repos/google/google-auth-library-php/milestones{/number}","notifications_url":"https://api.github.com/repos/google/google-auth-library-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/google-auth-library-php/labels{/name}","releases_url":"https://api.github.com/repos/google/google-auth-library-php/releases{/id}","created_at":"2014-10-16T18:36:42Z","updated_at":"2015-05-07T17:24:56Z","pushed_at":"2015-05-13T06:08:34Z","git_url":"git://github.com/google/google-auth-library-php.git","ssh_url":"git@github.com:google/google-auth-library-php.git","clone_url":"https://github.com/google/google-auth-library-php.git","svn_url":"https://github.com/google/google-auth-library-php","homepage":"","size":674,"stargazers_count":6,"watchers_count":6,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":5,"forks":4,"open_issues":5,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/google-auth-library-php/pulls/44"},"html":{"href":"https://github.com/google/google-auth-library-php/pull/44"},"issue":{"href":"https://api.github.com/repos/google/google-auth-library-php/issues/44"},"comments":{"href":"https://api.github.com/repos/google/google-auth-library-php/issues/44/comments"},"review_comments":{"href":"https://api.github.com/repos/google/google-auth-library-php/pulls/44/comments"},"review_comment":{"href":"https://api.github.com/repos/google/google-auth-library-php/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/google-auth-library-php/pulls/44/commits"},"statuses":{"href":"https://api.github.com/repos/google/google-auth-library-php/statuses/87b8045a5144356bc828a7e796492ed119ae98cd"}}}}