Skip to content

Commit

Permalink
adds GatewayClient.auth_scheme configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed May 28, 2021
1 parent 40c477b commit e135fd6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ src

*.swp
*.map
.idea/
.vscode/
Read the Docs
config.rst

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

# jetbrains ide stuff
*.iml
.idea/

# vscode ide stuff
*.code-workspace
.history
.vscode/*
!.vscode/*.template

21 changes: 18 additions & 3 deletions jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,30 @@ def _headers_default(self):
return os.environ.get(self.headers_env, self.headers_default_value)

auth_token = Unicode(default_value=None, allow_none=True, config=True,
help="""The authorization token used in the HTTP headers. (JUPYTER_GATEWAY_AUTH_TOKEN env var)
"""
help="""The authorization token used in the HTTP headers. The header will be formatted as:
{
'Authorization': '{auth_scheme} {auth_token}'
}
(JUPYTER_GATEWAY_AUTH_TOKEN env var)"""
)
auth_token_env = 'JUPYTER_GATEWAY_AUTH_TOKEN'

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

auth_scheme = Unicode(default_value=None, allow_none=True, config=True,
help="""The auth scheme, added as a prefix to the authorization token used in the HTTP headers.
(JUPYTER_GATEWAY_AUTH_SCHEME env var)"""
)
auth_scheme_env = 'JUPYTER_GATEWAY_AUTH_SCHEME'

@default('auth_scheme')
def _auth_scheme_default(self):
return os.environ.get(self.auth_scheme_env, 'token')

validate_cert_default_value = True
validate_cert_env = 'JUPYTER_GATEWAY_VALIDATE_CERT'
validate_cert = Bool(default_value=validate_cert_default_value, config=True,
Expand Down Expand Up @@ -268,7 +283,7 @@ def init_static_args(self):
self._static_args['headers'] = json.loads(self.headers)
if 'Authorization' not in self._static_args['headers'].keys():
self._static_args['headers'].update({
'Authorization': 'token {}'.format(self.auth_token)
'Authorization': '{} {}'.format(self.auth_scheme, self.auth_token)
})
self._static_args['connect_timeout'] = self.connect_timeout
self._static_args['request_timeout'] = self.request_timeout
Expand Down

0 comments on commit e135fd6

Please sign in to comment.