| lodash | true | ||||||
|---|---|---|---|---|---|---|---|
| title | Python Web App Tutorial | ||||||
| name | Python | ||||||
| image | //auth0.com/lib/platforms-collection/img/python.png | ||||||
| tags |
|
||||||
| snippets |
|
<%= include('../_includes/package', { pkgRepo: 'auth0-python', pkgBranch: 'master', pkgPath: 'examples/flask-webapp', pkgFilePath: null, pkgType: 'server' + account.clientParam }) %>
Otherwise, Please follow the steps below to configure your existing Python WebApp to use it with Auth0.
${snippet(meta.snippets.dependencies)}
This example uses flask but it could work with any server
You'll need to create a callback handler that Auth0 will call once it redirects to your app. For that, you can do the following:
${snippet(meta.snippets.setup)}
${include('./_callbackRegularWebApp')}
In this case, the callbackURL should look something like:
http://yourUrl/callback
${lockSDK}
Note: Please note that the
callbackURLspecified in theAuth0Lockconstructor must match the one specified in the previous step
You can access the user information via the profile you stored in the session on step 2
@app.route("/dashboard")
@requires_auth
def dashboard():
return render_template('dashboard.html', user=session['profile'])<div>
<img class="avatar" src="{{user['picture']}}"/>
<h2>Welcome {{user['nickname']}}</h2>
</div>Click here to check all the information that the userinfo hash has.
You have configured your Python Webapp to use Auth0. Congrats, you're awesome!
You can add the following annotation to your Flask app to check if the user is authenticated
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
if not session.has_key('profile'):
# Redirect to Login page here
return redirect('/')
return f(*args, **kwargs)
return decoratedWe've actually used the annotation on step 5.