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 2021/05/09 17:44:35 UTC
[incubator-ponymail-foal] 02/03: Update Github OAuth to use JSON
response scheme
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 7d4c8e02a59a60b32c28405bd5cd23f6b418e836
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun May 9 19:43:51 2021 +0200
Update Github OAuth to use JSON response scheme
---
server/plugins/oauthGithub.py | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/server/plugins/oauthGithub.py b/server/plugins/oauthGithub.py
index 341c702..5c45094 100644
--- a/server/plugins/oauthGithub.py
+++ b/server/plugins/oauthGithub.py
@@ -19,17 +19,15 @@ async def process(
) -> typing.Optional[dict]:
formdata["client_id"] = server.config.oauth.github_client_id
formdata["client_secret"] = server.config.oauth.github_client_secret
-
- with aiohttp.client.request("POST", "https://github.com/login/oauth/access_token", data=formdata) as rv:
- txt = await rv.read()
- m = re.search(r"access_token=([a-f0-9]+)", txt)
-
- if m:
- with aiohttp.client.request("GET", "https://api.github.com/user", headers={"authorization": "token %s" % m.group(1)}) as rv:
- js = rv.json()
+ headers = {'Accept': 'application/json'}
+ with aiohttp.client.request("POST", "https://github.com/login/oauth/access_token", headers=headers, data=formdata) as rv:
+ resp = await rv.json()
+ if 'access_token' in resp:
+ with aiohttp.client.request("GET", "https://api.github.com/user", headers={"authorization": "token %s" % resp['access_token']}) as orv:
+ js = await orv.json()
js["oauth_domain"] = "github.com"
# Full name and email address might not always be available to us. Fake it till you make it.
- js["name"] = js["name"] or js["login"]
- js["email"] = js["email"] or "%s@users.github.com" % js["login"]
+ js["name"] = js.get("name", js["login"])
+ js["email"] = js.get("email", "%s@users.github.com" % js["login"])
return js
return None