From e01063e3e977db8e945ef19bbd4ab0c5e747cc33 Mon Sep 17 00:00:00 2001
From: kaiyou <pierre@jaury.eu>
Date: Tue, 17 Mar 2020 12:16:49 +0100
Subject: [PATCH] Use a hack to access the client object from the OIDC Code
 Mixin

---
 hiboo/sso/oidc.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/hiboo/sso/oidc.py b/hiboo/sso/oidc.py
index 3d603a6..7019dce 100644
--- a/hiboo/sso/oidc.py
+++ b/hiboo/sso/oidc.py
@@ -103,14 +103,17 @@ class OpenIDMixin(object):
     def exists_nonce(self, nonce, request):
         return bool(utils.redis.get("nonce:{}".format(nonce)))
 
+    def get_client(self):
+        # TODO: this is a terribly ugly hack meant only as a temporary measure
+        # waiting for authlib to merge our PRs allowing a more generic way of
+        # always having the current client in the context.
+        return inspect.currentframe().f_back.f_back.f_back.f_locals["self"].client
+
     def get_jwt_config(self, grant=None):
-        # In the case of AuthorizationCode, the current object is not the grant
-        # but a grant extension, so the client is retrieved through the grant argument
-        client = self.request.client if grant is None else grant.client
-        return client.get_jwt_config()
+        return self.get_client().get_jwt_config()
 
     def generate_user_info(self, user, scope):
-        return Client.generate_user_info(user, scope)
+        return self.get_client().generate_user_info(user, scope)
 
 
 class Client(sqla_oauth2.OAuth2ClientMixin):
@@ -157,8 +160,7 @@ class Client(sqla_oauth2.OAuth2ClientMixin):
             'exp': 3600,
         }
 
-    @classmethod
-    def generate_user_info(cls, user, scope):
+    def generate_user_info(self, user, scope):
         """ User info generation function used by the oidc code mixin and the userinfo endpoint
         """
         return oidc.UserInfo(
-- 
GitLab