lodash | title | name | image | tags | snippets | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
true |
Python Web App Tutorial |
Python |
/media/platforms/python.png |
|
|
<%= 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
callbackURL
specified in theAuth0Lock
constructor 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. Note that you should import wraps
first, adding the following line to your file from functools import wraps
.
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
if 'profile' not in session:
# Redirect to Login page here
return redirect('/')
return f(*args, **kwargs)
return decorated
We've actually used the annotation on step 5.