mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-17 15:03:02 +00:00
ensure oauth uses same db session as app
further remnant of test threads
This commit is contained in:
@@ -1247,7 +1247,7 @@ class JupyterHub(Application):
|
|||||||
def init_oauth(self):
|
def init_oauth(self):
|
||||||
base_url = self.hub.base_url
|
base_url = self.hub.base_url
|
||||||
self.oauth_provider = make_provider(
|
self.oauth_provider = make_provider(
|
||||||
self.session_factory,
|
lambda : self.db,
|
||||||
url_prefix=url_path_join(base_url, 'api/oauth2'),
|
url_prefix=url_path_join(base_url, 'api/oauth2'),
|
||||||
login_url=url_path_join(base_url, 'login')
|
login_url=url_path_join(base_url, 'login')
|
||||||
)
|
)
|
||||||
|
@@ -52,14 +52,7 @@ class JupyterHubSiteAdapter(AuthorizationCodeGrantSiteAdapter):
|
|||||||
class HubDBMixin(object):
|
class HubDBMixin(object):
|
||||||
"""Mixin for connecting to the hub database"""
|
"""Mixin for connecting to the hub database"""
|
||||||
def __init__(self, session_factory):
|
def __init__(self, session_factory):
|
||||||
self.session_factory = session_factory
|
self.db = session_factory()
|
||||||
self._local = threading.local()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def db(self):
|
|
||||||
if not hasattr(self._local, 'db'):
|
|
||||||
self._local.db = scoped_session(self.session_factory)()
|
|
||||||
return self._local.db
|
|
||||||
|
|
||||||
|
|
||||||
class AccessTokenStore(HubDBMixin, oauth2.store.AccessTokenStore):
|
class AccessTokenStore(HubDBMixin, oauth2.store.AccessTokenStore):
|
||||||
@@ -77,7 +70,6 @@ class AccessTokenStore(HubDBMixin, oauth2.store.AccessTokenStore):
|
|||||||
if user is None:
|
if user is None:
|
||||||
raise ValueError("No user for access token: %s" % access_token.user_id)
|
raise ValueError("No user for access token: %s" % access_token.user_id)
|
||||||
orm_access_token = orm.OAuthAccessToken(
|
orm_access_token = orm.OAuthAccessToken(
|
||||||
generated=True,
|
|
||||||
client_id=access_token.client_id,
|
client_id=access_token.client_id,
|
||||||
grant_type=access_token.grant_type,
|
grant_type=access_token.grant_type,
|
||||||
expires_at=access_token.expires_at,
|
expires_at=access_token.expires_at,
|
||||||
|
Reference in New Issue
Block a user