Skip to content

Commit

Permalink
added jwt_login docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Aug 9, 2019
1 parent 5c95766 commit 6c15837
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
8 changes: 0 additions & 8 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@ Welcome to Piccolo API's documentation!
:caption: Contents:

./introduction


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
36 changes: 33 additions & 3 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ To expose several CRUD endpoints in our app, we use Starlette's Router.
from .tables import Table1, Table2, Table3
asgi_app = Router(
asgi_app = Router([
Mount(
path='/table1',
app=PiccoloCRUD(table=Table1),
Expand All @@ -64,12 +64,42 @@ To expose several CRUD endpoints in our app, we use Starlette's Router.
path='/table3',
app=PiccoloCRUD(table=Table3),
),
)
])
import uvicorn
uvicorn.run(asgi_app)
jwt_login
---------

...
This creates an endpoint for logging in, and getting a JSON Web Token (JWT).

.. code-block:: python
from starlette.routing import Route, Router
from piccolo_api.endpoints.auth import jwt_login
from .tables import User
from settings import SECRET
asgi_app = Router([
Route(
path="/login/",
endpoint=jwt_login(
auth_table=User,
secret=SECRET
)
),
])
import uvicorn
uvicorn.run(asgi_app)
You have to pass in two arguments:

* auth_table - a subclass of Piccolo's ``BaseUser`` class, which is used to
authenticate the user.
* secret - this is used for signing the JWT.

.. todo - show example POST using requests

0 comments on commit 6c15837

Please sign in to comment.