{"action":"created","comment":{"url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/comments/48684178","id":48684178,"diff_hunk":"@@ -146,54 +193,138 @@ public function request($request) {\n         return false;\n       else\n         return $res;\n-    }\n+    } // request\n \n-    public function getAuthLink() {\n-      return 'https://www.livecoding.tv/o/authorize/?'.\n-              'scope='.$this->scope.'&'.\n-              'state='.$this->state.'&'.\n-              'redirect_uri='.$this->redirect_url.'&'.\n-              'response_type=code&'.\n-              'client_id='.$this->client_id;\n-    } // getAuthLink\n+  } // class LivecodingAuth\n+} // if(!class_exists)\n \n-    public function getState() {\n-      return $this->state;\n-    } // getState\n \n-    public function getAccessToken() {\n-      return $this->access_token;\n-    }\n+if(!class_exists('LivecodingAuthTokens')) {\n \n-    public function setAccessToken($access_token) {\n-      $this->access_token = $access_token;\n-    }\n+  class LivecodingAuthTokens {\n \n-    public function getTokenType() {\n-      return $this->token_type;\n-    }\n+    /**\n+    * Load token datas with an object\n+    **/\n+    public function setTokens($tokens) {\n+      $tokens = json_decode($tokens);\n+      if(isset($tokens->error)) return;\n \n-    public function setTokenType($token_type) {\n-      $this->token_type = $token_type;\n-    }\n+      $this->setAccessToken($tokens->access_token;\n+      $this->setTokenType($tokens->token_type;\n+      $this->setRefreshToken($tokens->refresh_token;\n+      $this->setExpiresIn('Y-m-d H:i:s', (time() + $tokens->expires_in));\n+      $this->setScope($tokens->scope);\n \n-    public function getRefreshToken() {\n-      return $this->refresh_token;\n-    }\n+      $this->storeTokens();\n+    } // setTokens\n+\n+    /**\n+    * Determine if our access token need to be refreshed\n+    **/\n+    public function is_stale() {\n+      return (strtotime($this->getExpiresIn()) - time()) < 7200;\n+    } // is_stale\n+\n+\n+    // Subclasses should override these getters and setters\n+\n+    public function hasTokens() {}\n+\n+    private function storeTokens() {}\n+\n+    public function getState() {}\n+\n+    public function setState($state) {}\n+\n+    private function getAccessToken() {}\n+\n+    private function setAccessToken($access_token) {}\n \n-    public function setRefreshToken($refresh_token) {\n-      $this->refresh_token = $refresh_token;\n+    private function getTokenType() {}\n+\n+    private function setTokenType($token_type) {}\n+\n+    private function getRefreshToken() {}\n+\n+    private function setRefreshToken($refresh_token) {}\n+\n+    private function getExpiresIn() {}\n+\n+    private function setExpiresIn($expires_in) {}\n+\n+    private function getScope() {}\n+\n+    private function setScope($scope) {}\n+  }\n+\n+\n+  class LivecodingAuthTokensSession extends LivecodingAuthTokens {\n+","path":"livecodingAuth.php","position":325,"original_position":325,"commit_id":"19185d31e050e682ab102a0befad56b1c132c23c","original_commit_id":"19185d31e050e682ab102a0befad56b1c132c23c","user":{"login":"bill-auger","id":1642691,"avatar_url":"https://avatars.githubusercontent.com/u/1642691?v=3","gravatar_id":"","url":"https://api.github.com/users/bill-auger","html_url":"https://github.com/bill-auger","followers_url":"https://api.github.com/users/bill-auger/followers","following_url":"https://api.github.com/users/bill-auger/following{/other_user}","gists_url":"https://api.github.com/users/bill-auger/gists{/gist_id}","starred_url":"https://api.github.com/users/bill-auger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bill-auger/subscriptions","organizations_url":"https://api.github.com/users/bill-auger/orgs","repos_url":"https://api.github.com/users/bill-auger/repos","events_url":"https://api.github.com/users/bill-auger/events{/privacy}","received_events_url":"https://api.github.com/users/bill-auger/received_events","type":"User","site_admin":false},"body":"should call session_start() in constructor yes? in case the user does not","created_at":"2016-01-02T11:44:21Z","updated_at":"2016-01-02T11:44:21Z","html_url":"https://github.com/Wapaca/livecoding-auth/pull/5#discussion_r48684178","pull_request_url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/comments/48684178"},"html":{"href":"https://github.com/Wapaca/livecoding-auth/pull/5#discussion_r48684178"},"pull_request":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5","id":54897526,"html_url":"https://github.com/Wapaca/livecoding-auth/pull/5","diff_url":"https://github.com/Wapaca/livecoding-auth/pull/5.diff","patch_url":"https://github.com/Wapaca/livecoding-auth/pull/5.patch","issue_url":"https://api.github.com/repos/Wapaca/livecoding-auth/issues/5","number":5,"state":"open","locked":false,"title":"abstract most boiler-plate procedures into the library","user":{"login":"bill-auger","id":1642691,"avatar_url":"https://avatars.githubusercontent.com/u/1642691?v=3","gravatar_id":"","url":"https://api.github.com/users/bill-auger","html_url":"https://github.com/bill-auger","followers_url":"https://api.github.com/users/bill-auger/followers","following_url":"https://api.github.com/users/bill-auger/following{/other_user}","gists_url":"https://api.github.com/users/bill-auger/gists{/gist_id}","starred_url":"https://api.github.com/users/bill-auger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bill-auger/subscriptions","organizations_url":"https://api.github.com/users/bill-auger/orgs","repos_url":"https://api.github.com/users/bill-auger/repos","events_url":"https://api.github.com/users/bill-auger/events{/privacy}","received_events_url":"https://api.github.com/users/bill-auger/received_events","type":"User","site_admin":false},"body":"this version is refactored with as much of the boiler-plate as possible moved out of the front-end and into the library class\r\n\r\nthe front-end example.php is now simplified to the following flow:\r\n  * instantiate the library object\r\n  * check if previously authorized\r\n    * if yes request data and present the returned data\r\n    * if no request auth link and present that\r\n\r\nin order to abstract storage away from the end user, token storage was moved to a new semi-abstract class which is intended to be subclassed for specifc data storage needs - one reference subclass exists for $_SESSION storage\r\n\r\nnote that this version is incompatible with the previous version and so example.php was replaced with the re-written online-status.php example","created_at":"2016-01-01T22:34:38Z","updated_at":"2016-01-02T11:44:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4392a16123d2ac0addd7a3f1ee9e9f15c221b2ca","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5/commits","review_comments_url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5/comments","review_comment_url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wapaca/livecoding-auth/issues/5/comments","statuses_url":"https://api.github.com/repos/Wapaca/livecoding-auth/statuses/19185d31e050e682ab102a0befad56b1c132c23c","head":{"label":"bill-auger:master","ref":"master","sha":"19185d31e050e682ab102a0befad56b1c132c23c","user":{"login":"bill-auger","id":1642691,"avatar_url":"https://avatars.githubusercontent.com/u/1642691?v=3","gravatar_id":"","url":"https://api.github.com/users/bill-auger","html_url":"https://github.com/bill-auger","followers_url":"https://api.github.com/users/bill-auger/followers","following_url":"https://api.github.com/users/bill-auger/following{/other_user}","gists_url":"https://api.github.com/users/bill-auger/gists{/gist_id}","starred_url":"https://api.github.com/users/bill-auger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bill-auger/subscriptions","organizations_url":"https://api.github.com/users/bill-auger/orgs","repos_url":"https://api.github.com/users/bill-auger/repos","events_url":"https://api.github.com/users/bill-auger/events{/privacy}","received_events_url":"https://api.github.com/users/bill-auger/received_events","type":"User","site_admin":false},"repo":{"id":48844465,"name":"livecoding-auth","full_name":"bill-auger/livecoding-auth","owner":{"login":"bill-auger","id":1642691,"avatar_url":"https://avatars.githubusercontent.com/u/1642691?v=3","gravatar_id":"","url":"https://api.github.com/users/bill-auger","html_url":"https://github.com/bill-auger","followers_url":"https://api.github.com/users/bill-auger/followers","following_url":"https://api.github.com/users/bill-auger/following{/other_user}","gists_url":"https://api.github.com/users/bill-auger/gists{/gist_id}","starred_url":"https://api.github.com/users/bill-auger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bill-auger/subscriptions","organizations_url":"https://api.github.com/users/bill-auger/orgs","repos_url":"https://api.github.com/users/bill-auger/repos","events_url":"https://api.github.com/users/bill-auger/events{/privacy}","received_events_url":"https://api.github.com/users/bill-auger/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bill-auger/livecoding-auth","description":"PHP Class describing how to use the livecoding api","fork":true,"url":"https://api.github.com/repos/bill-auger/livecoding-auth","forks_url":"https://api.github.com/repos/bill-auger/livecoding-auth/forks","keys_url":"https://api.github.com/repos/bill-auger/livecoding-auth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bill-auger/livecoding-auth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bill-auger/livecoding-auth/teams","hooks_url":"https://api.github.com/repos/bill-auger/livecoding-auth/hooks","issue_events_url":"https://api.github.com/repos/bill-auger/livecoding-auth/issues/events{/number}","events_url":"https://api.github.com/repos/bill-auger/livecoding-auth/events","assignees_url":"https://api.github.com/repos/bill-auger/livecoding-auth/assignees{/user}","branches_url":"https://api.github.com/repos/bill-auger/livecoding-auth/branches{/branch}","tags_url":"https://api.github.com/repos/bill-auger/livecoding-auth/tags","blobs_url":"https://api.github.com/repos/bill-auger/livecoding-auth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bill-auger/livecoding-auth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bill-auger/livecoding-auth/git/refs{/sha}","trees_url":"https://api.github.com/repos/bill-auger/livecoding-auth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bill-auger/livecoding-auth/statuses/{sha}","languages_url":"https://api.github.com/repos/bill-auger/livecoding-auth/languages","stargazers_url":"https://api.github.com/repos/bill-auger/livecoding-auth/stargazers","contributors_url":"https://api.github.com/repos/bill-auger/livecoding-auth/contributors","subscribers_url":"https://api.github.com/repos/bill-auger/livecoding-auth/subscribers","subscription_url":"https://api.github.com/repos/bill-auger/livecoding-auth/subscription","commits_url":"https://api.github.com/repos/bill-auger/livecoding-auth/commits{/sha}","git_commits_url":"https://api.github.com/repos/bill-auger/livecoding-auth/git/commits{/sha}","comments_url":"https://api.github.com/repos/bill-auger/livecoding-auth/comments{/number}","issue_comment_url":"https://api.github.com/repos/bill-auger/livecoding-auth/issues/comments{/number}","contents_url":"https://api.github.com/repos/bill-auger/livecoding-auth/contents/{+path}","compare_url":"https://api.github.com/repos/bill-auger/livecoding-auth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bill-auger/livecoding-auth/merges","archive_url":"https://api.github.com/repos/bill-auger/livecoding-auth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bill-auger/livecoding-auth/downloads","issues_url":"https://api.github.com/repos/bill-auger/livecoding-auth/issues{/number}","pulls_url":"https://api.github.com/repos/bill-auger/livecoding-auth/pulls{/number}","milestones_url":"https://api.github.com/repos/bill-auger/livecoding-auth/milestones{/number}","notifications_url":"https://api.github.com/repos/bill-auger/livecoding-auth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bill-auger/livecoding-auth/labels{/name}","releases_url":"https://api.github.com/repos/bill-auger/livecoding-auth/releases{/id}","created_at":"2015-12-31T09:45:20Z","updated_at":"2015-12-31T09:45:22Z","pushed_at":"2016-01-01T22:31:31Z","git_url":"git://github.com/bill-auger/livecoding-auth.git","ssh_url":"git@github.com:bill-auger/livecoding-auth.git","clone_url":"https://github.com/bill-auger/livecoding-auth.git","svn_url":"https://github.com/bill-auger/livecoding-auth","homepage":null,"size":11,"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":"Wapaca:master","ref":"master","sha":"59c6be5b6156a11ad8ada309f98e3742153f1002","user":{"login":"Wapaca","id":6703970,"avatar_url":"https://avatars.githubusercontent.com/u/6703970?v=3","gravatar_id":"","url":"https://api.github.com/users/Wapaca","html_url":"https://github.com/Wapaca","followers_url":"https://api.github.com/users/Wapaca/followers","following_url":"https://api.github.com/users/Wapaca/following{/other_user}","gists_url":"https://api.github.com/users/Wapaca/gists{/gist_id}","starred_url":"https://api.github.com/users/Wapaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wapaca/subscriptions","organizations_url":"https://api.github.com/users/Wapaca/orgs","repos_url":"https://api.github.com/users/Wapaca/repos","events_url":"https://api.github.com/users/Wapaca/events{/privacy}","received_events_url":"https://api.github.com/users/Wapaca/received_events","type":"User","site_admin":false},"repo":{"id":48798833,"name":"livecoding-auth","full_name":"Wapaca/livecoding-auth","owner":{"login":"Wapaca","id":6703970,"avatar_url":"https://avatars.githubusercontent.com/u/6703970?v=3","gravatar_id":"","url":"https://api.github.com/users/Wapaca","html_url":"https://github.com/Wapaca","followers_url":"https://api.github.com/users/Wapaca/followers","following_url":"https://api.github.com/users/Wapaca/following{/other_user}","gists_url":"https://api.github.com/users/Wapaca/gists{/gist_id}","starred_url":"https://api.github.com/users/Wapaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wapaca/subscriptions","organizations_url":"https://api.github.com/users/Wapaca/orgs","repos_url":"https://api.github.com/users/Wapaca/repos","events_url":"https://api.github.com/users/Wapaca/events{/privacy}","received_events_url":"https://api.github.com/users/Wapaca/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Wapaca/livecoding-auth","description":"PHP Class describing how to use the livecoding api","fork":false,"url":"https://api.github.com/repos/Wapaca/livecoding-auth","forks_url":"https://api.github.com/repos/Wapaca/livecoding-auth/forks","keys_url":"https://api.github.com/repos/Wapaca/livecoding-auth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wapaca/livecoding-auth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wapaca/livecoding-auth/teams","hooks_url":"https://api.github.com/repos/Wapaca/livecoding-auth/hooks","issue_events_url":"https://api.github.com/repos/Wapaca/livecoding-auth/issues/events{/number}","events_url":"https://api.github.com/repos/Wapaca/livecoding-auth/events","assignees_url":"https://api.github.com/repos/Wapaca/livecoding-auth/assignees{/user}","branches_url":"https://api.github.com/repos/Wapaca/livecoding-auth/branches{/branch}","tags_url":"https://api.github.com/repos/Wapaca/livecoding-auth/tags","blobs_url":"https://api.github.com/repos/Wapaca/livecoding-auth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wapaca/livecoding-auth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wapaca/livecoding-auth/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wapaca/livecoding-auth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wapaca/livecoding-auth/statuses/{sha}","languages_url":"https://api.github.com/repos/Wapaca/livecoding-auth/languages","stargazers_url":"https://api.github.com/repos/Wapaca/livecoding-auth/stargazers","contributors_url":"https://api.github.com/repos/Wapaca/livecoding-auth/contributors","subscribers_url":"https://api.github.com/repos/Wapaca/livecoding-auth/subscribers","subscription_url":"https://api.github.com/repos/Wapaca/livecoding-auth/subscription","commits_url":"https://api.github.com/repos/Wapaca/livecoding-auth/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wapaca/livecoding-auth/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wapaca/livecoding-auth/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wapaca/livecoding-auth/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wapaca/livecoding-auth/contents/{+path}","compare_url":"https://api.github.com/repos/Wapaca/livecoding-auth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wapaca/livecoding-auth/merges","archive_url":"https://api.github.com/repos/Wapaca/livecoding-auth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wapaca/livecoding-auth/downloads","issues_url":"https://api.github.com/repos/Wapaca/livecoding-auth/issues{/number}","pulls_url":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls{/number}","milestones_url":"https://api.github.com/repos/Wapaca/livecoding-auth/milestones{/number}","notifications_url":"https://api.github.com/repos/Wapaca/livecoding-auth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wapaca/livecoding-auth/labels{/name}","releases_url":"https://api.github.com/repos/Wapaca/livecoding-auth/releases{/id}","created_at":"2015-12-30T12:03:13Z","updated_at":"2015-12-30T12:17:45Z","pushed_at":"2016-01-01T22:34:38Z","git_url":"git://github.com/Wapaca/livecoding-auth.git","ssh_url":"git@github.com:Wapaca/livecoding-auth.git","clone_url":"https://github.com/Wapaca/livecoding-auth.git","svn_url":"https://github.com/Wapaca/livecoding-auth","homepage":null,"size":7,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5"},"html":{"href":"https://github.com/Wapaca/livecoding-auth/pull/5"},"issue":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/issues/5"},"comments":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/Wapaca/livecoding-auth/statuses/19185d31e050e682ab102a0befad56b1c132c23c"}}}}