Skip to content

Commit

Permalink
fix(sdk): Add http status code check for token requests. Fixes #4312 (#…
Browse files Browse the repository at this point in the history
…5782)

Signed-off-by: Anna Jung (VMware) <antheaj@vmware.com>
  • Loading branch information
Anna authored Jun 3, 2021
1 parent f3c0c46 commit 0d84877
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sdk/python/kfp/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,19 @@ def get_auth_code(client_id):
open_new_tab(auth_url)
return input("If there's no browser window prompt, please direct to the URL above, then copy and paste the authorization code here: ")


def get_refresh_token_from_code(auth_code, client_id, client_secret):
payload = {"code": auth_code, "client_id": client_id, "client_secret": client_secret,
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob", "grant_type": "authorization_code"}
res = requests.post(OAUTH_TOKEN_URI, data=payload)
return (str(json.loads(res.text)[u"refresh_token"]))
res.raise_for_status()
return str(json.loads(res.text)[u"refresh_token"])


def id_token_from_refresh_token(client_id, client_secret, refresh_token, audience):
payload = {"client_id": client_id, "client_secret": client_secret,
"refresh_token": refresh_token, "grant_type": "refresh_token",
"audience": audience}
res = requests.post(OAUTH_TOKEN_URI, data=payload)
return (str(json.loads(res.text)[u"id_token"]))
res.raise_for_status()
return str(json.loads(res.text)[u"id_token"])

0 comments on commit 0d84877

Please sign in to comment.