|
1 |
| -#!/usr/bin/env python3.6 |
| 1 | +#!/usr/bin/env python3.7 |
2 | 2 |
|
3 | 3 | """./demo.py, then point your browser at localhost:5000/web
|
4 | 4 |
|
5 | 5 | Note that this demo uses a fairly simple implementation of login, as the goal
|
6 | 6 | 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 |
8 | 8 | 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. |
10 | 11 |
|
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 |
12 | 13 | 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. |
17 | 18 |
|
18 | 19 | The /web/ urls get the token added to the head of the document. If
|
19 | 20 | you look in the template, you'll see that pages call csrf.js, which
|
|
46 | 47 | # restarts of the server.
|
47 | 48 | app.secret_key = os.urandom(32) # 256-bit random encryption key
|
48 | 49 |
|
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 |
50 | 51 | ## a csrf instance (subclassed or otherwise) as the value of parameter
|
51 | 52 | ## csrf. This would allow us to, for example, change how usernames
|
52 | 53 | ## are stored by overriding get_username. See csrf.py for more.
|
@@ -84,7 +85,7 @@ def process_login():
|
84 | 85 |
|
85 | 86 | # This just tells us if we're logged in
|
86 | 87 | @api.route('/api/logged_in')
|
87 |
| -class LogedInApiHandler(Resource): |
| 88 | +class LoggedInApiHandler(Resource): |
88 | 89 | def get(self):
|
89 | 90 | return {'message': session.get('logged_in', False)}
|
90 | 91 |
|
|
0 commit comments