From 9771ae806055546a5df2cbeea9ec2f67f14b0317 Mon Sep 17 00:00:00 2001 From: Luka Radenovic Date: Thu, 20 Jan 2022 08:59:00 +0100 Subject: [PATCH] Update get_token function --- helpers/hydra_oauth.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/helpers/hydra_oauth.py b/helpers/hydra_oauth.py index eaedc84..629225f 100644 --- a/helpers/hydra_oauth.py +++ b/helpers/hydra_oauth.py @@ -1,5 +1,7 @@ from flask import request, session from requests_oauthlib import OAuth2Session +from oauthlib.oauth2 import BackendApplicationClient +from requests.auth import HTTPBasicAuth from config import * from helpers import HydraError @@ -26,12 +28,18 @@ class HydraOauth: @staticmethod def get_token(state, code): try: - hydra = OAuth2Session( - client_id=HYDRA_CLIENT_ID, - state=state, - ) + auth = HTTPBasicAuth(HYDRA_CLIENT_ID, HYDRA_CLIENT_SECRET) + client = BackendApplicationClient(client_id=HYDRA_CLIENT_ID) + hydra = OAuth2Session(client=client, state=state) + # hydra = OAuth2Session( + # client_id=HYDRA_CLIENT_ID, + # state=state, + # ) token = hydra.fetch_token( - TOKEN_URL, code=code, state=state, client_secret=HYDRA_CLIENT_SECRET + token_url=TOKEN_URL, + auth=auth, + code=code, + client_secret=HYDRA_CLIENT_SECRET, ) session["hydra_token"] = token