{"action":"created","comment":{"url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/comments/72468783","id":72468783,"diff_hunk":"@@ -0,0 +1,345 @@\n+<?php\n+\n+/**\n+ * Copyright 2015-2016, SellerLabs <scope-devs@sellerlabs.com>\n+ *\n+ * For the full copyright and license information, please view the LICENSE\n+ * file that was distributed with this source code.\n+ *\n+ * This file is part of the SellerLabs package\n+ */\n+\n+namespace SellerLabs\\Slapp\\Auth;\n+\n+use Exception;\n+use Illuminate\\Auth\\GuardHelpers;\n+use Illuminate\\Config\\Repository as ConfigRepository;\n+use Illuminate\\Contracts\\Auth\\Guard;\n+use Illuminate\\Contracts\\Foundation\\Application;\n+use Illuminate\\Encryption\\Encrypter;\n+use RuntimeException;\n+use Illuminate\\Http\\Request;\n+use SellerLabs\\Scope\\Support\\Enums\\Environment;\n+use SellerLabs\\Slapp\\Interfaces\\SlappClientInterface;\n+use SellerLabs\\Slapp\\Interfaces\\SlappUserInterface;\n+use SellerLabs\\Slapp\\Interfaces\\SlappUserRepositoryInterface;\n+\n+class SlappGuard implements Guard\n+{\n+    use GuardHelpers;\n+\n+    const USER_ID = 'user_id';\n+    const ACCOUNT_ID = 'account_id';\n+    const ACCESS_TOKEN = 'access_token';\n+    const REFRESH_TOKEN = 'refresh_token';\n+\n+    /**\n+     * The name of the Guard.\n+     *\n+     * Corresponds to driver name in authentication configuration.\n+     *\n+     * @var string\n+     */\n+    protected $name;\n+\n+    /**\n+     * @var Request\n+     */\n+    protected $request;\n+\n+    /**\n+     * @var ConfigRepository\n+     */\n+    protected $config;\n+\n+    /**\n+     * @var Application\n+     */\n+    protected $application;\n+\n+    /**\n+     * @var SlappClientInterface\n+     */\n+    protected $client;\n+\n+    /**\n+     * @var Encrypter\n+     */\n+    protected $encrypter;\n+\n+    /**\n+     * @var string\n+     */\n+    protected $accessToken;\n+\n+    /**\n+     * Indicates if the logout method has been called.\n+     *\n+     * @var bool\n+     */\n+    protected $loggedOut = false;\n+\n+    /**\n+     * Indicates if data has been loaded.\n+     *\n+     * @var bool\n+     */\n+    protected $dataLoaded = false;\n+\n+    /**\n+     * SLAPP data.\n+     *\n+     * @var array\n+     */\n+    protected $data = [\n+        self::USER_ID => null,\n+        self::ACCOUNT_ID => null,\n+        self::ACCESS_TOKEN => null,\n+        self::REFRESH_TOKEN => null,\n+    ];\n+\n+    /**\n+     * Create a new authentication guard.\n+     *\n+     * @param string $name\n+     * @param SlappUserRepositoryInterface $provider\n+     * @param Request $request\n+     * @param ConfigRepository $config\n+     * @param Application $application\n+     * @param SlappClientInterface $client\n+     */\n+    public function __construct(\n+        $name,\n+        SlappUserRepositoryInterface $provider,\n+        Request $request,\n+        ConfigRepository $config,\n+        Application $application,\n+        SlappClientInterface $client\n+    ) {\n+        $this->name = $name;\n+        $this->provider = $provider;\n+        $this->request = $request;\n+        $this->config = $config;\n+        $this->application = $application;\n+        $this->client = $client;\n+        $this->encrypter = new Encrypter(\n+            $this->config['slapp.client_secret'],\n+            'AES-256-CBC'\n+        );\n+    }\n+\n+    /**\n+     * Set access token.\n+     *\n+     * @param string $accessToken\n+     */\n+    public function setAccessToken($accessToken)\n+    {\n+        $this->accessToken = $accessToken;\n+        $this->client->setAccessToken($accessToken);\n+    }\n+\n+    /**\n+     * Get access token.\n+     *\n+     * @return string\n+     */\n+    public function getAccessToken() {\n+        return $this->accessToken;\n+    }\n+\n+    /**\n+     * Set SLAPP data.\n+     *\n+     * @param array $data\n+     */\n+    protected function setData(array $data) {\n+        $this->data = $data;\n+        $this->dataLoaded = true;\n+    }\n+\n+    /**\n+     * Get the currently authenticated user.\n+     *\n+     * @return \\Illuminate\\Contracts\\Auth\\Authenticatable|null\n+     */\n+    public function user()\n+    {\n+        if ($this->loggedOut) {\n+            return null;\n+        }\n+\n+        $this->setAccessToken($this->getData(self::ACCESS_TOKEN));\n+\n+        // If we've already retrieved the user for the current request we can just\n+        // return it back immediately. We do not want to fetch the user data on\n+        // every call to this method because that would be tremendously slow.\n+        if (! is_null($this->user)) {\n+            return $this->user;\n+        }\n+\n+        $id = $this->getData(self::USER_ID);\n+\n+        $user = null;\n+        if (! is_null($id)) {\n+            $user = $this->provider->findBySlappUserId($id);\n+        }\n+        return $this->user = $user;\n+    }\n+","path":"src/SellerLabs/Slapp/Auth/SlappGuard.php","position":189,"original_position":189,"commit_id":"f0ecc63b75e332035ed8dc8af641f184866895f7","original_commit_id":"f0ecc63b75e332035ed8dc8af641f184866895f7","user":{"login":"5outh","id":959901,"avatar_url":"https://avatars.githubusercontent.com/u/959901?v=3","gravatar_id":"","url":"https://api.github.com/users/5outh","html_url":"https://github.com/5outh","followers_url":"https://api.github.com/users/5outh/followers","following_url":"https://api.github.com/users/5outh/following{/other_user}","gists_url":"https://api.github.com/users/5outh/gists{/gist_id}","starred_url":"https://api.github.com/users/5outh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/5outh/subscriptions","organizations_url":"https://api.github.com/users/5outh/orgs","repos_url":"https://api.github.com/users/5outh/repos","events_url":"https://api.github.com/users/5outh/events{/privacy}","received_events_url":"https://api.github.com/users/5outh/received_events","type":"User","site_admin":false},"body":"Normally I wouldn't mention it, but there's a lot of excess whitespace here","created_at":"2016-07-27T16:01:14Z","updated_at":"2016-07-27T16:01:14Z","html_url":"https://github.com/sellerlabs/slapp-client-php/pull/3#discussion_r72468783","pull_request_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/comments/72468783"},"html":{"href":"https://github.com/sellerlabs/slapp-client-php/pull/3#discussion_r72468783"},"pull_request":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3","id":78415805,"html_url":"https://github.com/sellerlabs/slapp-client-php/pull/3","diff_url":"https://github.com/sellerlabs/slapp-client-php/pull/3.diff","patch_url":"https://github.com/sellerlabs/slapp-client-php/pull/3.patch","issue_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/3","number":3,"state":"open","locked":false,"title":"wip","user":{"login":"dsh","id":84490,"avatar_url":"https://avatars.githubusercontent.com/u/84490?v=3","gravatar_id":"","url":"https://api.github.com/users/dsh","html_url":"https://github.com/dsh","followers_url":"https://api.github.com/users/dsh/followers","following_url":"https://api.github.com/users/dsh/following{/other_user}","gists_url":"https://api.github.com/users/dsh/gists{/gist_id}","starred_url":"https://api.github.com/users/dsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsh/subscriptions","organizations_url":"https://api.github.com/users/dsh/orgs","repos_url":"https://api.github.com/users/dsh/repos","events_url":"https://api.github.com/users/dsh/events{/privacy}","received_events_url":"https://api.github.com/users/dsh/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-22T02:20:30Z","updated_at":"2016-07-27T16:01:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32f30024f0bd59fb866ae045c9669bc7ab753768","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3/commits","review_comments_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3/comments","review_comment_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/3/comments","statuses_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/statuses/f0ecc63b75e332035ed8dc8af641f184866895f7","head":{"label":"sellerlabs:dsh/cookie-auth","ref":"dsh/cookie-auth","sha":"f0ecc63b75e332035ed8dc8af641f184866895f7","user":{"login":"sellerlabs","id":11278378,"avatar_url":"https://avatars.githubusercontent.com/u/11278378?v=3","gravatar_id":"","url":"https://api.github.com/users/sellerlabs","html_url":"https://github.com/sellerlabs","followers_url":"https://api.github.com/users/sellerlabs/followers","following_url":"https://api.github.com/users/sellerlabs/following{/other_user}","gists_url":"https://api.github.com/users/sellerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/sellerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sellerlabs/subscriptions","organizations_url":"https://api.github.com/users/sellerlabs/orgs","repos_url":"https://api.github.com/users/sellerlabs/repos","events_url":"https://api.github.com/users/sellerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/sellerlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":39468348,"name":"slapp-client-php","full_name":"sellerlabs/slapp-client-php","owner":{"login":"sellerlabs","id":11278378,"avatar_url":"https://avatars.githubusercontent.com/u/11278378?v=3","gravatar_id":"","url":"https://api.github.com/users/sellerlabs","html_url":"https://github.com/sellerlabs","followers_url":"https://api.github.com/users/sellerlabs/followers","following_url":"https://api.github.com/users/sellerlabs/following{/other_user}","gists_url":"https://api.github.com/users/sellerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/sellerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sellerlabs/subscriptions","organizations_url":"https://api.github.com/users/sellerlabs/orgs","repos_url":"https://api.github.com/users/sellerlabs/repos","events_url":"https://api.github.com/users/sellerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/sellerlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sellerlabs/slapp-client-php","description":"PHP client for SellerLabs' Accounts API","fork":false,"url":"https://api.github.com/repos/sellerlabs/slapp-client-php","forks_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/forks","keys_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/teams","hooks_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/hooks","issue_events_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/events{/number}","events_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/events","assignees_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/assignees{/user}","branches_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/branches{/branch}","tags_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/tags","blobs_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/statuses/{sha}","languages_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/languages","stargazers_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/stargazers","contributors_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/contributors","subscribers_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/subscribers","subscription_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/subscription","commits_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/contents/{+path}","compare_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/merges","archive_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/downloads","issues_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues{/number}","pulls_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls{/number}","milestones_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/milestones{/number}","notifications_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/labels{/name}","releases_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/releases{/id}","deployments_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/deployments","created_at":"2015-07-21T20:30:06Z","updated_at":"2016-07-25T15:59:49Z","pushed_at":"2016-07-22T02:20:30Z","git_url":"git://github.com/sellerlabs/slapp-client-php.git","ssh_url":"git@github.com:sellerlabs/slapp-client-php.git","clone_url":"https://github.com/sellerlabs/slapp-client-php.git","svn_url":"https://github.com/sellerlabs/slapp-client-php","homepage":"","size":58,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"sellerlabs:master","ref":"master","sha":"c4fb50eb757f48b61b65cabece45340ffc0f19e6","user":{"login":"sellerlabs","id":11278378,"avatar_url":"https://avatars.githubusercontent.com/u/11278378?v=3","gravatar_id":"","url":"https://api.github.com/users/sellerlabs","html_url":"https://github.com/sellerlabs","followers_url":"https://api.github.com/users/sellerlabs/followers","following_url":"https://api.github.com/users/sellerlabs/following{/other_user}","gists_url":"https://api.github.com/users/sellerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/sellerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sellerlabs/subscriptions","organizations_url":"https://api.github.com/users/sellerlabs/orgs","repos_url":"https://api.github.com/users/sellerlabs/repos","events_url":"https://api.github.com/users/sellerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/sellerlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":39468348,"name":"slapp-client-php","full_name":"sellerlabs/slapp-client-php","owner":{"login":"sellerlabs","id":11278378,"avatar_url":"https://avatars.githubusercontent.com/u/11278378?v=3","gravatar_id":"","url":"https://api.github.com/users/sellerlabs","html_url":"https://github.com/sellerlabs","followers_url":"https://api.github.com/users/sellerlabs/followers","following_url":"https://api.github.com/users/sellerlabs/following{/other_user}","gists_url":"https://api.github.com/users/sellerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/sellerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sellerlabs/subscriptions","organizations_url":"https://api.github.com/users/sellerlabs/orgs","repos_url":"https://api.github.com/users/sellerlabs/repos","events_url":"https://api.github.com/users/sellerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/sellerlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sellerlabs/slapp-client-php","description":"PHP client for SellerLabs' Accounts API","fork":false,"url":"https://api.github.com/repos/sellerlabs/slapp-client-php","forks_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/forks","keys_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/teams","hooks_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/hooks","issue_events_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/events{/number}","events_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/events","assignees_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/assignees{/user}","branches_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/branches{/branch}","tags_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/tags","blobs_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/refs{/sha}","trees_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/statuses/{sha}","languages_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/languages","stargazers_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/stargazers","contributors_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/contributors","subscribers_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/subscribers","subscription_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/subscription","commits_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/commits{/sha}","git_commits_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/git/commits{/sha}","comments_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/comments{/number}","issue_comment_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/comments{/number}","contents_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/contents/{+path}","compare_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/merges","archive_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/downloads","issues_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues{/number}","pulls_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls{/number}","milestones_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/milestones{/number}","notifications_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/labels{/name}","releases_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/releases{/id}","deployments_url":"https://api.github.com/repos/sellerlabs/slapp-client-php/deployments","created_at":"2015-07-21T20:30:06Z","updated_at":"2016-07-25T15:59:49Z","pushed_at":"2016-07-22T02:20:30Z","git_url":"git://github.com/sellerlabs/slapp-client-php.git","ssh_url":"git@github.com:sellerlabs/slapp-client-php.git","clone_url":"https://github.com/sellerlabs/slapp-client-php.git","svn_url":"https://github.com/sellerlabs/slapp-client-php","homepage":"","size":58,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3"},"html":{"href":"https://github.com/sellerlabs/slapp-client-php/pull/3"},"issue":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/3"},"comments":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/sellerlabs/slapp-client-php/statuses/f0ecc63b75e332035ed8dc8af641f184866895f7"}}}}
{"actor":{"display_login":"5outh"}}