allow oauth provider to be missing

mostly for testing
This commit is contained in:
Min RK
2017-03-31 16:15:00 +02:00
parent 5819b442aa
commit 5e1516189b
2 changed files with 16 additions and 15 deletions

View File

@@ -246,20 +246,21 @@ class User(HasTraits):
spawner.api_token = api_token
spawner.admin_access = self.settings.get('admin_access', False)
spawner.oauth_client_id = client_id = 'user-%s-%s' % (self.escaped_name, server_name)
client_store = self.settings['oauth_provider'].client_authenticator.client_store
try:
oauth_client = client_store.fetch_by_client_id(client_id)
except ClientNotFoundError:
oauth_client = None
# create a new OAuth client + secret on every launch,
# except for resuming containers.
if oauth_client is None or not spawner.will_resume:
spawner.oauth_client_secret = client_secret = new_token()
print(server.base_url)
client_store.add_client(client_id, client_secret,
url_path_join(server.base_url, 'oauth_callback'),
)
db.commit()
oauth_provider = self.settings.get('oauth_provider')
if oauth_provider:
client_store = oauth_provider.client_authenticator.client_store
try:
oauth_client = client_store.fetch_by_client_id(client_id)
except ClientNotFoundError:
oauth_client = None
# create a new OAuth client + secret on every launch,
# except for resuming containers.
if oauth_client is None or not spawner.will_resume:
spawner.oauth_client_secret = client_secret = new_token()
client_store.add_client(client_id, client_secret,
url_path_join(server.base_url, 'oauth_callback'),
)
db.commit()
# trigger pre-spawn hook on authenticator
authenticator = self.authenticator