Skip to content

Commit f29bb11

Browse files
authored
adds GatewayClient.auth_scheme configurable (#529)
1 parent 86b68e6 commit f29bb11

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ src
2626

2727
*.swp
2828
*.map
29-
.idea/
30-
.vscode/
3129
Read the Docs
3230
config.rst
3331

@@ -37,3 +35,13 @@ config.rst
3735
# copied changelog file
3836
docs/source/other/changelog.md
3937

38+
# jetbrains ide stuff
39+
*.iml
40+
.idea/
41+
42+
# vscode ide stuff
43+
*.code-workspace
44+
.history
45+
.vscode/*
46+
!.vscode/*.template
47+

jupyter_server/gateway/gateway_client.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,30 @@ def _headers_default(self):
176176
return os.environ.get(self.headers_env, self.headers_default_value)
177177

178178
auth_token = Unicode(default_value=None, allow_none=True, config=True,
179-
help="""The authorization token used in the HTTP headers. (JUPYTER_GATEWAY_AUTH_TOKEN env var)
180-
"""
179+
help="""The authorization token used in the HTTP headers. The header will be formatted as:
180+
181+
{
182+
'Authorization': '{auth_scheme} {auth_token}'
183+
}
184+
185+
(JUPYTER_GATEWAY_AUTH_TOKEN env var)"""
181186
)
182187
auth_token_env = 'JUPYTER_GATEWAY_AUTH_TOKEN'
183188

184189
@default('auth_token')
185190
def _auth_token_default(self):
186191
return os.environ.get(self.auth_token_env, '')
187192

193+
auth_scheme = Unicode(default_value=None, allow_none=True, config=True,
194+
help="""The auth scheme, added as a prefix to the authorization token used in the HTTP headers.
195+
(JUPYTER_GATEWAY_AUTH_SCHEME env var)"""
196+
)
197+
auth_scheme_env = 'JUPYTER_GATEWAY_AUTH_SCHEME'
198+
199+
@default('auth_scheme')
200+
def _auth_scheme_default(self):
201+
return os.environ.get(self.auth_scheme_env, 'token')
202+
188203
validate_cert_default_value = True
189204
validate_cert_env = 'JUPYTER_GATEWAY_VALIDATE_CERT'
190205
validate_cert = Bool(default_value=validate_cert_default_value, config=True,
@@ -268,7 +283,7 @@ def init_static_args(self):
268283
self._static_args['headers'] = json.loads(self.headers)
269284
if 'Authorization' not in self._static_args['headers'].keys():
270285
self._static_args['headers'].update({
271-
'Authorization': 'token {}'.format(self.auth_token)
286+
'Authorization': '{} {}'.format(self.auth_scheme, self.auth_token)
272287
})
273288
self._static_args['connect_timeout'] = self.connect_timeout
274289
self._static_args['request_timeout'] = self.request_timeout

0 commit comments

Comments
 (0)