Skip to content

Commit ed1ca52

Browse files
authored
Merge pull request #219 from fcollonval/patch-1
Add `authenticated` decorator to handlers in doc
2 parents 4f2d91d + 25db52a commit ed1ca52

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/source/developers/extensions.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ The easiest way to add endpoints and handle incoming requests is to subclass the
2727
.. code-block:: python
2828
2929
from jupyter_server.base.handlers import JupyterHandler
30+
import tornado
3031
3132
class MyExtensionHandler(JupyterHandler):
3233
34+
@tornado.web.authenticated
3335
def get(self):
3436
...
3537
38+
@tornado.web.authenticated
3639
def post(self):
3740
...
3841
42+
.. note::
43+
It is best practice to wrap each handler method with the ``authenticated`` decorator to ensure that each request is authenticated by the server.
3944

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

@@ -178,13 +183,16 @@ Jupyter Server provides a convenient mixin class for adding these properties to
178183
179184
from jupyter_server.base.handlers import JupyterHandler
180185
from jupyter_server.extension.handler import ExtensionHandlerMixin
186+
import tornado
181187
182188
183189
class MyExtensionHandler(ExtensionHandlerMixin, JupyterHandler):
184190
191+
@tornado.web.authenticated
185192
def get(self):
186193
...
187194
195+
@tornado.web.authenticated
188196
def post(self):
189197
...
190198
@@ -217,16 +225,19 @@ Pair the example above with ``ExtensionHandlers`` that also inherit the ``Extens
217225
ExtensionHandlerMixin,
218226
ExtensionHandlerJinjaMixin
219227
)
228+
import tornado
220229
221230
class MyExtensionHandler(
222231
ExtensionHandlerMixin,
223232
ExtensionHandlerJinjaMixin,
224233
JupyterHandler
225234
):
226235
236+
@tornado.web.authenticated
227237
def get(self):
228238
...
229239
240+
@tornado.web.authenticated
230241
def post(self):
231242
...
232243

0 commit comments

Comments
 (0)