Triggering authentication with /login

Triggering authentication with /login

When visitors to your app visit the /login route, they'll be redirected to Auth0 to begin the authentication flow.

# 👆 We're continuing from the steps above. Append this to your webappexample/views.py file.
 
def login(request):
    return oauth.auth0.authorize_redirect(
        request, request.build_absolute_uri(reverse("callback"))
    )

Finalizing authentication with /callback

After your users finish logging in with Auth0, they'll be returned to your application at the /callback route. This route is responsible for actually saving the session for the user, so when they visit again later, they won't have to sign back in all over again.

# 👆 We're continuing from the steps above. Append this to your /views.py file.
 
def callback(request):
    token = oauth.auth0.authorize_access_token(request)
    request.session["user"] = token
    return redirect(request.build_absolute_uri(reverse("index")))

To inquire User roles

You can use the following code sample:

import requests url = "https://dev-s2lge48ro4vtrqmv.us.auth0.com/api/v2/users/:id/roles" payload = {} headers = { 'Accept': 'application/json' } response = requests.request("GET", url, headers=headers, data=payload) print(response.text)

Last updated