You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/09/08 08:37:43 UTC

[incubator-ponymail-foal] 08/10: Switch to using token headers (non-deprecated), lint

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 87d70b72c025defd8ecc81c477f707ee7b9a526a
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Sep 8 10:31:42 2020 +0200

    Switch to using token headers (non-deprecated), lint
---
 server/plugins/oauthGithub.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/server/plugins/oauthGithub.py b/server/plugins/oauthGithub.py
index a1698d4..3cdd348 100644
--- a/server/plugins/oauthGithub.py
+++ b/server/plugins/oauthGithub.py
@@ -14,15 +14,23 @@ import plugins.server
 import typing
 
 
-async def process(formdata, session, server: plugins.server.BaseServer) -> typing.Optional[dict]:
-    formdata['client_id'] = server.config.oauth.github_client_id
-    formdata['client_secret'] = server.config.oauth.github_client_secret
+async def process(
+    formdata, session, server: plugins.server.BaseServer
+) -> typing.Optional[dict]:
+    formdata["client_id"] = server.config.oauth.github_client_id
+    formdata["client_secret"] = server.config.oauth.github_client_secret
 
-    rv = await server.runners.run(requests.post, 'https://github.com/login/oauth/access_token', data=formdata)
-    m = re.search(r"(access_token=[a-f0-9]+)", rv.text)
+    rv = await server.runners.run(
+        requests.post, "https://github.com/login/oauth/access_token", data=formdata
+    )
+    m = re.search(r"access_token=([a-f0-9]+)", rv.text)
 
     if m:
-        rv = await server.runners.run(requests.get, "https://api.github.com/user?%s" % m.group(1))
+        rv = await server.runners.run(
+            requests.get,
+            "https://api.github.com/user",
+            headers={"authorization": "token %s" % m.group(1)},
+        )
         js = rv.json()
         js["oauth_domain"] = "github.com"
         return js