{"action":"created","comment":{"url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/comments/63298476","id":63298476,"diff_hunk":"@@ -0,0 +1,93 @@\n+import requests\n+\n+from urllib.parse import urlencode, urljoin\n+from collections import namedtuple\n+\n+from .exceptions import BankIdError\n+\n+Token = namedtuple('Token', ['access_token', 'refresh_token', 'expires_in', 'token_type'])\n+\n+\n+class BaseBankIdClient(object):\n+    \"\"\"\n+    Base BankID client class, which contains common functionality for all BankID providers.\n+    Constructor expects a `client_id` and `client_secret` for all providers. Some providers may introduce\n+    additional arguments. Optionally following keyword arguments may be provided:\n+        authorization_base_url: URL to be used for authorization grant step\n+        api_base_url: Base URL for the API requests not related to authorization step\n+\n+    Public methods may raise `BankIdError` exception for specific BankID errors.\n+    \"\"\"\n+\n+    default_authorization_base_url = NotImplemented\n+    default_api_base_url = NotImplemented\n+    token_endpoint = NotImplemented\n+\n+    def __init__(self, client_id, client_secret, **kwargs):\n+        self.client_id = client_id\n+        self.client_secret = client_secret\n+        self.authorization_base_url = kwargs.get('authorization_base_url', self.default_authorization_base_url)\n+        self.api_base_url = kwargs.get('api_base_url', self.default_api_base_url)\n+\n+    def authorization_url(self, redirect_url):\n+        \"\"\"\n+        Returns authorization grant step URL with `redirect_url` encoded into it to be returned to after auth.\n+        \"\"\"\n+        args = (\n+            ('client_id', self.client_id),\n+            ('redirect_uri', redirect_url),\n+            ('response_type', 'code'),\n+        )\n+        return '{}?{}'.format(self.authorization_base_url, urlencode(args))\n+\n+    def retrieve_access_token(self, code, redirect_url):\n+        \"\"\"\n+        Returns `Token` instance with OAuth2 access and refresh tokens obtained by the given `code`.\n+        `redirect_url` MUST match the one used for `authorization_url`.\n+        \"\"\"\n+        response = requests.post(urljoin(self.api_base_url, self.token_endpoint), data={\n+            'code': code,\n+            'client_id': self.client_id,\n+            'client_secret': self._client_secret(code),\n+            'redirect_uri': redirect_url,\n+            'grant_type': 'authorization_code'\n+        })\n+        if response.status_code == requests.codes.ok:\n+            data = response.json()\n+            return Token(data['access_token'], data['refresh_token'], data['expires_in'], data['token_type'])\n+        else:\n+            self._handle_errors(response)\n+\n+    def refresh_access_token(self, token):\n+        \"\"\"\n+        Refreshes the OAuth2 access token and returns a new one.\n+        Note: can be used only once for a new token. Refreshed token does not contain a `refresh_token` anymore.\n+        \"\"\"\n+        assert token.refresh_token is not None\n+        response = requests.post(urljoin(self.api_base_url, self.token_endpoint), data={","path":"badparking/profiles/bankid/base.py","position":67,"original_position":67,"commit_id":"539a90973151321cab8b94d2adc764867dcbd450","original_commit_id":"539a90973151321cab8b94d2adc764867dcbd450","user":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=3","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"body":"You probably should make a helper method to make post request with params and return data or raise errors","created_at":"2016-05-15T21:45:43Z","updated_at":"2016-05-15T21:45:43Z","html_url":"https://github.com/dchaplinsky/badparking.in.ua/pull/7#discussion_r63298476","pull_request_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/comments/63298476"},"html":{"href":"https://github.com/dchaplinsky/badparking.in.ua/pull/7#discussion_r63298476"},"pull_request":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7","id":70052589,"html_url":"https://github.com/dchaplinsky/badparking.in.ua/pull/7","diff_url":"https://github.com/dchaplinsky/badparking.in.ua/pull/7.diff","patch_url":"https://github.com/dchaplinsky/badparking.in.ua/pull/7.patch","issue_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/7","number":7,"state":"open","locked":false,"title":"Implements BankID integration for Oschadbank and Privatbank, closes #2","user":{"login":"excieve","id":1077193,"avatar_url":"https://avatars.githubusercontent.com/u/1077193?v=3","gravatar_id":"","url":"https://api.github.com/users/excieve","html_url":"https://github.com/excieve","followers_url":"https://api.github.com/users/excieve/followers","following_url":"https://api.github.com/users/excieve/following{/other_user}","gists_url":"https://api.github.com/users/excieve/gists{/gist_id}","starred_url":"https://api.github.com/users/excieve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/excieve/subscriptions","organizations_url":"https://api.github.com/users/excieve/orgs","repos_url":"https://api.github.com/users/excieve/repos","events_url":"https://api.github.com/users/excieve/events{/privacy}","received_events_url":"https://api.github.com/users/excieve/received_events","type":"User","site_admin":false},"body":"Contains a small module for PrivatBank and OschadBank BankID integrations. The latter is pretty much untested and might need more work.\r\n\r\nThis module is wired into the profiles app views so now it's possible to do a full auth flow.\r\n\r\nIn addition to this there's now a `phone` field in the `User` model along with the logic to get it from the BankID.","created_at":"2016-05-13T20:20:32Z","updated_at":"2016-05-15T21:45:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c8f9045a31b3e27c71cc9c52abc075038007d98","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7/commits","review_comments_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7/comments","review_comment_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/7/comments","statuses_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/statuses/539a90973151321cab8b94d2adc764867dcbd450","head":{"label":"dchaplinsky:feature/bankid","ref":"feature/bankid","sha":"539a90973151321cab8b94d2adc764867dcbd450","user":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=3","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"repo":{"id":55057258,"name":"badparking.in.ua","full_name":"dchaplinsky/badparking.in.ua","owner":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=3","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dchaplinsky/badparking.in.ua","description":"New version of badparking.in.ua. Now with mobile apps.","fork":false,"url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua","forks_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/forks","keys_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/teams","hooks_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/hooks","issue_events_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/events{/number}","events_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/events","assignees_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/assignees{/user}","branches_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/branches{/branch}","tags_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/tags","blobs_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/refs{/sha}","trees_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/statuses/{sha}","languages_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/languages","stargazers_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/stargazers","contributors_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/contributors","subscribers_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/subscribers","subscription_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/subscription","commits_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/commits{/sha}","git_commits_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/commits{/sha}","comments_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/comments{/number}","issue_comment_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/comments{/number}","contents_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/contents/{+path}","compare_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/merges","archive_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/downloads","issues_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues{/number}","pulls_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls{/number}","milestones_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/milestones{/number}","notifications_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/labels{/name}","releases_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/releases{/id}","deployments_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/deployments","created_at":"2016-03-30T11:22:57Z","updated_at":"2016-03-30T12:16:24Z","pushed_at":"2016-05-14T18:42:35Z","git_url":"git://github.com/dchaplinsky/badparking.in.ua.git","ssh_url":"git@github.com:dchaplinsky/badparking.in.ua.git","clone_url":"https://github.com/dchaplinsky/badparking.in.ua.git","svn_url":"https://github.com/dchaplinsky/badparking.in.ua","homepage":null,"size":131,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"dchaplinsky:master","ref":"master","sha":"fabf364074b4f3ceae34aa2adffe205be3d10e2b","user":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=3","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"repo":{"id":55057258,"name":"badparking.in.ua","full_name":"dchaplinsky/badparking.in.ua","owner":{"login":"dchaplinsky","id":131186,"avatar_url":"https://avatars.githubusercontent.com/u/131186?v=3","gravatar_id":"","url":"https://api.github.com/users/dchaplinsky","html_url":"https://github.com/dchaplinsky","followers_url":"https://api.github.com/users/dchaplinsky/followers","following_url":"https://api.github.com/users/dchaplinsky/following{/other_user}","gists_url":"https://api.github.com/users/dchaplinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/dchaplinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dchaplinsky/subscriptions","organizations_url":"https://api.github.com/users/dchaplinsky/orgs","repos_url":"https://api.github.com/users/dchaplinsky/repos","events_url":"https://api.github.com/users/dchaplinsky/events{/privacy}","received_events_url":"https://api.github.com/users/dchaplinsky/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dchaplinsky/badparking.in.ua","description":"New version of badparking.in.ua. Now with mobile apps.","fork":false,"url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua","forks_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/forks","keys_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/teams","hooks_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/hooks","issue_events_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/events{/number}","events_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/events","assignees_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/assignees{/user}","branches_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/branches{/branch}","tags_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/tags","blobs_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/refs{/sha}","trees_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/statuses/{sha}","languages_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/languages","stargazers_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/stargazers","contributors_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/contributors","subscribers_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/subscribers","subscription_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/subscription","commits_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/commits{/sha}","git_commits_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/git/commits{/sha}","comments_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/comments{/number}","issue_comment_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/comments{/number}","contents_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/contents/{+path}","compare_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/merges","archive_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/downloads","issues_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues{/number}","pulls_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls{/number}","milestones_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/milestones{/number}","notifications_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/labels{/name}","releases_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/releases{/id}","deployments_url":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/deployments","created_at":"2016-03-30T11:22:57Z","updated_at":"2016-03-30T12:16:24Z","pushed_at":"2016-05-14T18:42:35Z","git_url":"git://github.com/dchaplinsky/badparking.in.ua.git","ssh_url":"git@github.com:dchaplinsky/badparking.in.ua.git","clone_url":"https://github.com/dchaplinsky/badparking.in.ua.git","svn_url":"https://github.com/dchaplinsky/badparking.in.ua","homepage":null,"size":131,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7"},"html":{"href":"https://github.com/dchaplinsky/badparking.in.ua/pull/7"},"issue":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/7"},"comments":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/dchaplinsky/badparking.in.ua/statuses/539a90973151321cab8b94d2adc764867dcbd450"}}}}