How can a cell obtain user name from e.g. HttpContext?

75 views
Skip to first unread message

Paul A

unread,
Aug 9, 2016, 8:19:50 AM8/9/16
to Project Jupyter
Hi all, I have a user id passed via HttpContext, so in principle the notebook should know who is connecting. I know this is not secure, but should work for "Hey {}".format(context['username']. 

How can I get access to that HttpContext instance?

MinRK

unread,
Aug 9, 2016, 9:29:46 AM8/9/16
to Project Jupyter

Since the kernel is a different process from the server, objects in the server are not available to the kernels. Environment variables can be used to share little bits of information throughout the server and kernels, e.g.

export MY_USERNAME='something'
jupyter notebook

in which case the MY_USERNAME env will be available to the server and all of its kernel subprocesses. If the server doesn’t know its name until some time later, you can modify how kernels are started, to pass this environment variable on each kernel launch.

-MinRK


On Tue, Aug 9, 2016 at 2:19 PM, Paul A <rootsum...@gmail.com> wrote:
Hi all, I have a user id passed via HttpContext, so in principle the notebook should know who is connecting. I know this is not secure, but should work for "Hey {}".format(context['username']. 

How can I get access to that HttpContext instance?

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/45b3039b-41d8-464c-a041-81a108fc8450%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul A

unread,
Aug 9, 2016, 10:55:09 AM8/9/16
to Project Jupyter
Sorry, the question was about retrieving the username of the client connection to the notebook.

The server-side username can be easily returned as:

username = jupyter_client.session.Session().msg_header('')['username']



On Tuesday, August 9, 2016 at 2:29:46 PM UTC+1, Min RK wrote:

Since the kernel is a different process from the server, objects in the server are not available to the kernels. Environment variables can be used to share little bits of information throughout the server and kernels, e.g.

export MY_USERNAME='something'
jupyter notebook

in which case the MY_USERNAME env will be available to the server and all of its kernel subprocesses. If the server doesn’t know its name until some time later, you can modify how kernels are started, to pass this environment variable on each kernel launch.

-MinRK

On Tue, Aug 9, 2016 at 2:19 PM, Paul A <rootsum...@gmail.com> wrote:
Hi all, I have a user id passed via HttpContext, so in principle the notebook should know who is connecting. I know this is not secure, but should work for "Hey {}".format(context['username']. 

How can I get access to that HttpContext instance?

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

MinRK

unread,
Aug 11, 2016, 9:29:47 AM8/11/16
to Project Jupyter
On Tue, Aug 9, 2016 at 4:55 PM, Paul A <rootsum...@gmail.com> wrote:
Sorry, the question was about retrieving the username of the client connection to the notebook.

The server-side username can be easily returned as:

username = jupyter_client.session.Session().msg_header('')['username']


The browser never communicates directly with the kernel. All communication is mediated through the server. The server has access to HTTP headers, etc. It could use this information when starting a kernel to define an environment variable, for instance, when starting the kernel. This could also be done more simply on notebook-server startup, since the server is presumably launched for a given user.

-Min
 


On Tuesday, August 9, 2016 at 2:29:46 PM UTC+1, Min RK wrote:

Since the kernel is a different process from the server, objects in the server are not available to the kernels. Environment variables can be used to share little bits of information throughout the server and kernels, e.g.

export MY_USERNAME='something'
jupyter notebook

in which case the MY_USERNAME env will be available to the server and all of its kernel subprocesses. If the server doesn’t know its name until some time later, you can modify how kernels are started, to pass this environment variable on each kernel launch.

-MinRK


On Tue, Aug 9, 2016 at 2:19 PM, Paul A <rootsum...@gmail.com> wrote:
Hi all, I have a user id passed via HttpContext, so in principle the notebook should know who is connecting. I know this is not secure, but should work for "Hey {}".format(context['username']. 

How can I get access to that HttpContext instance?

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/45b3039b-41d8-464c-a041-81a108fc8450%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Jonathan Frederic

unread,
Aug 11, 2016, 8:56:23 PM8/11/16
to jup...@googlegroups.com

I don't recall if you can get a user name from JS Web APIs, but if you can, you should be able to pass it to the kernel using a comm


Reply all
Reply to author
Forward
0 new messages