Skip to content

Commit 887146c

Browse files
committedJan 30, 2020
Write README.md, improve documentation, fix typos
1 parent 6a5b363 commit 887146c

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed
 

‎README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# flask-restplus-csrf-demo
1+
# `flask-restplus-csrf` demo
2+
3+
This is a small example project to demonstrate usage of [flask-restplus-csrf](https://github.com/OpenTechStrategies/flask-restplus-csrf).
4+
5+
See the doc string at the top of [demo.py](demo.py) for a detailed
6+
description of exactly what is being demonstrated. To see the demo in
7+
action, run
8+
9+
```
10+
$ ./demo.py
11+
```
12+
13+
and then point your browser at http://localhost:5000/web. While [demo.py](demo.py) is running, you can also do
14+
15+
```
16+
$ pytest test_demo.py
17+
```
18+
19+
to run a series of tests that verify that
20+
[flask-restplus-csrf](https://github.com/OpenTechStrategies/flask-restplus-csrf)
21+
is working correctly.

‎demo.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
#!/usr/bin/env python3.6
1+
#!/usr/bin/env python3.7
22

33
"""./demo.py, then point your browser at localhost:5000/web
44
55
Note that this demo uses a fairly simple implementation of login, as the goal
66
is to demo the CSRF functionality, not the session management. Your
7-
implementation might be using oauth rather than cookie-based logins, and that
7+
implementation might be using OAuth rather than cookie-based logins, and that
88
is fine. As long as your session management generates a unique, ephemeral
9-
identity (such as a session id or an oauth bearer token),
9+
identity (such as a session id or an OAuth bearer token), code similar
10+
to this demo should work.
1011
11-
There are two types of pages returned from this demo. We return json
12+
There are two types of pages returned from this demo. We return JSON
1213
from the /api/ urls and we return web pages from the /web/ urls. The
13-
/api/ json is handled by the flask-restplus api object. The /web/ urls
14-
are handled by the traditional flask App. We return the csrf token
15-
for api calls that themselves require the token. We add the csrf
16-
token to all /web/ pages if the user is logged in.
14+
/api/ JSON is handled by the flask-restplus-csrf api object. The /web/
15+
urls are handled by the traditional flask App. We return the CSRF
16+
token for API calls that themselves require the token. We add the
17+
CSRF token to all /web/ pages if the user is logged in.
1718
1819
The /web/ urls get the token added to the head of the document. If
1920
you look in the template, you'll see that pages call csrf.js, which
@@ -46,7 +47,7 @@
4647
# restarts of the server.
4748
app.secret_key = os.urandom(32) # 256-bit random encryption key
4849

49-
## We call Api with a csrf=True paramter. We could alternatively pass
50+
## We call Api with a csrf=True parameter. We could alternatively pass
5051
## a csrf instance (subclassed or otherwise) as the value of parameter
5152
## csrf. This would allow us to, for example, change how usernames
5253
## are stored by overriding get_username. See csrf.py for more.
@@ -84,7 +85,7 @@ def process_login():
8485

8586
# This just tells us if we're logged in
8687
@api.route('/api/logged_in')
87-
class LogedInApiHandler(Resource):
88+
class LoggedInApiHandler(Resource):
8889
def get(self):
8990
return {'message': session.get('logged_in', False)}
9091

0 commit comments

Comments
 (0)
Please sign in to comment.