Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authenticated decorator to handlers in doc #219

Merged
merged 2 commits into from
May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/source/developers/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ The easiest way to add endpoints and handle incoming requests is to subclass the
.. code-block:: python

from jupyter_server.base.handlers import JupyterHandler
import tornado

class MyExtensionHandler(JupyterHandler):

@tornado.web.authenticated
def get(self):
...

@tornado.web.authenticated
def post(self):
...

.. note::
It is best practice to wrap each handler method with the ``authenticated`` decorator to ensure that each request is authenticated by the server.

Then add this handler to Jupyter Server's Web Application through the ``_load_jupyter_server_extension`` function.

Expand Down Expand Up @@ -178,13 +183,16 @@ Jupyter Server provides a convenient mixin class for adding these properties to

from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import ExtensionHandlerMixin
import tornado


class MyExtensionHandler(ExtensionHandlerMixin, JupyterHandler):

@tornado.web.authenticated
def get(self):
...

@tornado.web.authenticated
def post(self):
...

Expand Down Expand Up @@ -217,16 +225,19 @@ Pair the example above with ``ExtensionHandlers`` that also inherit the ``Extens
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin
)
import tornado

class MyExtensionHandler(
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin,
JupyterHandler
):

@tornado.web.authenticated
def get(self):
...

@tornado.web.authenticated
def post(self):
...

Expand Down