diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 57833caec0..bba3785354 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -931,6 +931,9 @@ def _write_cookie_secret_file(self, secret): token = Unicode('', help=_("""Token used for authenticating first-time connections to the server. + The token can be read from the file referenced by JUPYTER_TOKEN_FILE or set directly + with the JUPYTER_TOKEN environment variable. + When no password is enabled, the default is to generate a new, random token. @@ -945,6 +948,10 @@ def _token_default(self): if os.getenv('JUPYTER_TOKEN'): self._token_generated = False return os.getenv('JUPYTER_TOKEN') + if os.getenv('JUPYTER_TOKEN_FILE'): + self._token_generated = False + with io.open(os.getenv('JUPYTER_TOKEN_FILE'), "r") as token_file: + return token_file.read() if self.password: # no token if password is enabled self._token_generated = False