{"action":"created","comment":{"url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/comments/47094890","id":47094890,"diff_hunk":"@@ -68,3 +76,41 @@ def has_permission(self, request, view):\n             is_valid_github = hmac.compare_digest(computed_secret, secret)\n             return is_valid_github\n         return False\n+\n+\n+class SocialAuthentication(BaseAuthentication):\n+    \"\"\"\n+    Used in DEFAULT_AUTHENTICATION_CLASSES settings for authentication.\n+    This setting allows users to authenticate with only a Github oauth token.\n+    \"\"\"\n+    def authenticate(self, request):\n+        auth_header = get_authorization_header(request)\\\n+                            .decode(HTTP_HEADER_ENCODING)\n+        auth = auth_header.split()\n+        if not auth or auth[0].lower() != 'bearer':\n+            return None\n+        if len(auth) == 1:\n+            msg = 'Credentials are malformed'\n+            raise exceptions.AuthenticationFailed(msg)\n+        oauth_token = auth[1]\n+\n+        social_user = UserSocialAuth.objects\\\n+                                    .filter(extra_data__contains=oauth_token)\\\n+                                    .first()\n+        if not social_user:\n+            # User does not exist in our DB, attempt social auth\n+            strategy = load_strategy(request=request)\n+            path = NAMESPACE + \":complete\"\n+            backend = 'github'\n+            backend = load_backend(strategy, backend,\n+                                   reverse(path, args=(backend,)))\n+            user = backend.do_auth(access_token=oauth_token)\n+            if not user:\n+                msg = 'Bad credentials'\n+                raise exceptions.AuthenticationFailed(msg)\n+            social = user.social_auth.get(provider='github')\n+            social.extra_data['access_token'] = oauth_token\n+            social.save()","path":"franklin/core/helpers.py","position":57,"original_position":57,"commit_id":"71a7ae882c66e7065348a130650eb9cfb4d0f661","original_commit_id":"71a7ae882c66e7065348a130650eb9cfb4d0f661","user":{"login":"oudeismetis","id":444070,"avatar_url":"https://avatars.githubusercontent.com/u/444070?v=3","gravatar_id":"","url":"https://api.github.com/users/oudeismetis","html_url":"https://github.com/oudeismetis","followers_url":"https://api.github.com/users/oudeismetis/followers","following_url":"https://api.github.com/users/oudeismetis/following{/other_user}","gists_url":"https://api.github.com/users/oudeismetis/gists{/gist_id}","starred_url":"https://api.github.com/users/oudeismetis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oudeismetis/subscriptions","organizations_url":"https://api.github.com/users/oudeismetis/orgs","repos_url":"https://api.github.com/users/oudeismetis/repos","events_url":"https://api.github.com/users/oudeismetis/events{/privacy}","received_events_url":"https://api.github.com/users/oudeismetis/received_events","type":"User","site_admin":false},"body":"Most of this method was borrowed from best practices elsewhere. To summarize: If we don't find the user in the DB, we attempt to `do_auth` with python social auth. If that step succeeds, all the models and everything (with exception to the oauth_token bug) will be saved to the DB for us. Thus, the first time the dashboard calls ANY api endpoint with a users token, we will taken a moment here to initialize that user. All future calls will just hit the DB. New oauth tokens will result in a call to github, but will then just be associated with the user.","created_at":"2015-12-09T14:17:57Z","updated_at":"2015-12-09T14:17:57Z","html_url":"https://github.com/istrategylabs/franklin-api/pull/48#discussion_r47094890","pull_request_url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/comments/47094890"},"html":{"href":"https://github.com/istrategylabs/franklin-api/pull/48#discussion_r47094890"},"pull_request":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48","id":53053768,"html_url":"https://github.com/istrategylabs/franklin-api/pull/48","diff_url":"https://github.com/istrategylabs/franklin-api/pull/48.diff","patch_url":"https://github.com/istrategylabs/franklin-api/pull/48.patch","issue_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues/48","number":48,"state":"open","locked":false,"title":"Github oAuth tokens are all you need to call API","user":{"login":"oudeismetis","id":444070,"avatar_url":"https://avatars.githubusercontent.com/u/444070?v=3","gravatar_id":"","url":"https://api.github.com/users/oudeismetis","html_url":"https://github.com/oudeismetis","followers_url":"https://api.github.com/users/oudeismetis/followers","following_url":"https://api.github.com/users/oudeismetis/following{/other_user}","gists_url":"https://api.github.com/users/oudeismetis/gists{/gist_id}","starred_url":"https://api.github.com/users/oudeismetis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oudeismetis/subscriptions","organizations_url":"https://api.github.com/users/oudeismetis/orgs","repos_url":"https://api.github.com/users/oudeismetis/repos","events_url":"https://api.github.com/users/oudeismetis/events{/privacy}","received_events_url":"https://api.github.com/users/oudeismetis/received_events","type":"User","site_admin":false},"body":"- [x] Remove oAuth2 generation library\r\n- [x] Implement security to handle auth-ing with social tokens\r\n- [ ] Code review\r\n- [ ] Architecture discussion and security risk sanity check\r\n- [ ] Readme updates","created_at":"2015-12-08T23:13:33Z","updated_at":"2015-12-09T14:17:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f36f81fe46f299cfee93e7b7a7f4c0b53c4a5555","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48/commits","review_comments_url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48/comments","review_comment_url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues/48/comments","statuses_url":"https://api.github.com/repos/istrategylabs/franklin-api/statuses/71a7ae882c66e7065348a130650eb9cfb4d0f661","head":{"label":"istrategylabs:github-auth-only","ref":"github-auth-only","sha":"71a7ae882c66e7065348a130650eb9cfb4d0f661","user":{"login":"istrategylabs","id":607333,"avatar_url":"https://avatars.githubusercontent.com/u/607333?v=3","gravatar_id":"","url":"https://api.github.com/users/istrategylabs","html_url":"https://github.com/istrategylabs","followers_url":"https://api.github.com/users/istrategylabs/followers","following_url":"https://api.github.com/users/istrategylabs/following{/other_user}","gists_url":"https://api.github.com/users/istrategylabs/gists{/gist_id}","starred_url":"https://api.github.com/users/istrategylabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istrategylabs/subscriptions","organizations_url":"https://api.github.com/users/istrategylabs/orgs","repos_url":"https://api.github.com/users/istrategylabs/repos","events_url":"https://api.github.com/users/istrategylabs/events{/privacy}","received_events_url":"https://api.github.com/users/istrategylabs/received_events","type":"Organization","site_admin":false},"repo":{"id":39260839,"name":"franklin-api","full_name":"istrategylabs/franklin-api","owner":{"login":"istrategylabs","id":607333,"avatar_url":"https://avatars.githubusercontent.com/u/607333?v=3","gravatar_id":"","url":"https://api.github.com/users/istrategylabs","html_url":"https://github.com/istrategylabs","followers_url":"https://api.github.com/users/istrategylabs/followers","following_url":"https://api.github.com/users/istrategylabs/following{/other_user}","gists_url":"https://api.github.com/users/istrategylabs/gists{/gist_id}","starred_url":"https://api.github.com/users/istrategylabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istrategylabs/subscriptions","organizations_url":"https://api.github.com/users/istrategylabs/orgs","repos_url":"https://api.github.com/users/istrategylabs/repos","events_url":"https://api.github.com/users/istrategylabs/events{/privacy}","received_events_url":"https://api.github.com/users/istrategylabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/istrategylabs/franklin-api","description":"\"One click\" static site deploys? You betcha!","fork":false,"url":"https://api.github.com/repos/istrategylabs/franklin-api","forks_url":"https://api.github.com/repos/istrategylabs/franklin-api/forks","keys_url":"https://api.github.com/repos/istrategylabs/franklin-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/istrategylabs/franklin-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/istrategylabs/franklin-api/teams","hooks_url":"https://api.github.com/repos/istrategylabs/franklin-api/hooks","issue_events_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues/events{/number}","events_url":"https://api.github.com/repos/istrategylabs/franklin-api/events","assignees_url":"https://api.github.com/repos/istrategylabs/franklin-api/assignees{/user}","branches_url":"https://api.github.com/repos/istrategylabs/franklin-api/branches{/branch}","tags_url":"https://api.github.com/repos/istrategylabs/franklin-api/tags","blobs_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/istrategylabs/franklin-api/statuses/{sha}","languages_url":"https://api.github.com/repos/istrategylabs/franklin-api/languages","stargazers_url":"https://api.github.com/repos/istrategylabs/franklin-api/stargazers","contributors_url":"https://api.github.com/repos/istrategylabs/franklin-api/contributors","subscribers_url":"https://api.github.com/repos/istrategylabs/franklin-api/subscribers","subscription_url":"https://api.github.com/repos/istrategylabs/franklin-api/subscription","commits_url":"https://api.github.com/repos/istrategylabs/franklin-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/istrategylabs/franklin-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/istrategylabs/franklin-api/contents/{+path}","compare_url":"https://api.github.com/repos/istrategylabs/franklin-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/istrategylabs/franklin-api/merges","archive_url":"https://api.github.com/repos/istrategylabs/franklin-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/istrategylabs/franklin-api/downloads","issues_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues{/number}","pulls_url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls{/number}","milestones_url":"https://api.github.com/repos/istrategylabs/franklin-api/milestones{/number}","notifications_url":"https://api.github.com/repos/istrategylabs/franklin-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/istrategylabs/franklin-api/labels{/name}","releases_url":"https://api.github.com/repos/istrategylabs/franklin-api/releases{/id}","created_at":"2015-07-17T15:24:07Z","updated_at":"2015-09-02T21:23:20Z","pushed_at":"2015-12-08T23:13:33Z","git_url":"git://github.com/istrategylabs/franklin-api.git","ssh_url":"git@github.com:istrategylabs/franklin-api.git","clone_url":"https://github.com/istrategylabs/franklin-api.git","svn_url":"https://github.com/istrategylabs/franklin-api","homepage":null,"size":154,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":2,"default_branch":"master"}},"base":{"label":"istrategylabs:master","ref":"master","sha":"c247de7909dc015b137ea06f248539bf9da258f2","user":{"login":"istrategylabs","id":607333,"avatar_url":"https://avatars.githubusercontent.com/u/607333?v=3","gravatar_id":"","url":"https://api.github.com/users/istrategylabs","html_url":"https://github.com/istrategylabs","followers_url":"https://api.github.com/users/istrategylabs/followers","following_url":"https://api.github.com/users/istrategylabs/following{/other_user}","gists_url":"https://api.github.com/users/istrategylabs/gists{/gist_id}","starred_url":"https://api.github.com/users/istrategylabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istrategylabs/subscriptions","organizations_url":"https://api.github.com/users/istrategylabs/orgs","repos_url":"https://api.github.com/users/istrategylabs/repos","events_url":"https://api.github.com/users/istrategylabs/events{/privacy}","received_events_url":"https://api.github.com/users/istrategylabs/received_events","type":"Organization","site_admin":false},"repo":{"id":39260839,"name":"franklin-api","full_name":"istrategylabs/franklin-api","owner":{"login":"istrategylabs","id":607333,"avatar_url":"https://avatars.githubusercontent.com/u/607333?v=3","gravatar_id":"","url":"https://api.github.com/users/istrategylabs","html_url":"https://github.com/istrategylabs","followers_url":"https://api.github.com/users/istrategylabs/followers","following_url":"https://api.github.com/users/istrategylabs/following{/other_user}","gists_url":"https://api.github.com/users/istrategylabs/gists{/gist_id}","starred_url":"https://api.github.com/users/istrategylabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/istrategylabs/subscriptions","organizations_url":"https://api.github.com/users/istrategylabs/orgs","repos_url":"https://api.github.com/users/istrategylabs/repos","events_url":"https://api.github.com/users/istrategylabs/events{/privacy}","received_events_url":"https://api.github.com/users/istrategylabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/istrategylabs/franklin-api","description":"\"One click\" static site deploys? You betcha!","fork":false,"url":"https://api.github.com/repos/istrategylabs/franklin-api","forks_url":"https://api.github.com/repos/istrategylabs/franklin-api/forks","keys_url":"https://api.github.com/repos/istrategylabs/franklin-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/istrategylabs/franklin-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/istrategylabs/franklin-api/teams","hooks_url":"https://api.github.com/repos/istrategylabs/franklin-api/hooks","issue_events_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues/events{/number}","events_url":"https://api.github.com/repos/istrategylabs/franklin-api/events","assignees_url":"https://api.github.com/repos/istrategylabs/franklin-api/assignees{/user}","branches_url":"https://api.github.com/repos/istrategylabs/franklin-api/branches{/branch}","tags_url":"https://api.github.com/repos/istrategylabs/franklin-api/tags","blobs_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/istrategylabs/franklin-api/statuses/{sha}","languages_url":"https://api.github.com/repos/istrategylabs/franklin-api/languages","stargazers_url":"https://api.github.com/repos/istrategylabs/franklin-api/stargazers","contributors_url":"https://api.github.com/repos/istrategylabs/franklin-api/contributors","subscribers_url":"https://api.github.com/repos/istrategylabs/franklin-api/subscribers","subscription_url":"https://api.github.com/repos/istrategylabs/franklin-api/subscription","commits_url":"https://api.github.com/repos/istrategylabs/franklin-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/istrategylabs/franklin-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/istrategylabs/franklin-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/istrategylabs/franklin-api/contents/{+path}","compare_url":"https://api.github.com/repos/istrategylabs/franklin-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/istrategylabs/franklin-api/merges","archive_url":"https://api.github.com/repos/istrategylabs/franklin-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/istrategylabs/franklin-api/downloads","issues_url":"https://api.github.com/repos/istrategylabs/franklin-api/issues{/number}","pulls_url":"https://api.github.com/repos/istrategylabs/franklin-api/pulls{/number}","milestones_url":"https://api.github.com/repos/istrategylabs/franklin-api/milestones{/number}","notifications_url":"https://api.github.com/repos/istrategylabs/franklin-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/istrategylabs/franklin-api/labels{/name}","releases_url":"https://api.github.com/repos/istrategylabs/franklin-api/releases{/id}","created_at":"2015-07-17T15:24:07Z","updated_at":"2015-09-02T21:23:20Z","pushed_at":"2015-12-08T23:13:33Z","git_url":"git://github.com/istrategylabs/franklin-api.git","ssh_url":"git@github.com:istrategylabs/franklin-api.git","clone_url":"https://github.com/istrategylabs/franklin-api.git","svn_url":"https://github.com/istrategylabs/franklin-api","homepage":null,"size":154,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48"},"html":{"href":"https://github.com/istrategylabs/franklin-api/pull/48"},"issue":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/issues/48"},"comments":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/istrategylabs/franklin-api/statuses/71a7ae882c66e7065348a130650eb9cfb4d0f661"}}}}