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 <[email protected]> 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 "%[email protected]" % js["login"] + js["name"] = js.get("name", js["login"]) + js["email"] = js.get("email", "%[email protected]" % js["login"]) return js return None
