Hi there,
I have a Django app that is working fine. I wanted to integrate Auth0’s OAuth Authentication to my app. I followed their official tutorial, but when I go to my Login Url, I get the error at Auth0 page that says:
Callback URL mismatch
Below is the screenshot of error:
Below is my django project’s main urls.py
:
urlpatterns = [
path("admin/", admin.site.urls, name="admin"),
path("", login, name="home_x"),
path("accounts/", include("apps.accounts.urls")), # URLs of Login/Registration System
]
Below is urls.py
of my django app named accounts
:
urlpatterns = [
path("login", views.login, name="login"),
path("logout", views.logout, name="logout"),
path("callback", views.callback, name="callback"),
path(
"switch-workspace/", SwitchWorkspace.as_view(), name="switch_workspace"
),
]
Below is my views.py
:
def login(request):
return oauth.auth0.authorize_redirect(
request, request.build_absolute_uri(reverse("callback"))
)
def callback(request):
token = oauth.auth0.authorize_access_token(request)
request.session["user"] = token
return redirect(request.build_absolute_uri(reverse("switch_workspace")))
def logout(request):
request.session.clear()
return redirect(
f"https://{settings.AUTH0_DOMAIN}/v2/logout?"
+ urlencode(
{
"returnTo": request.build_absolute_uri(reverse("login")),
"client_id": settings.AUTH0_CLIENT_ID,
},
quote_via=quote_plus,
),
)
Below is my settings.py
:
AUTH0_CLIENT_ID=env("AUTH0_CLIENT_ID")
AUTH0_CLIENT_SECRET=env("AUTH0_CLIENT_SECRET")
AUTH0_DOMAIN=env("AUTH0_DOMAIN")
and finally below are my settings in Auth0 Account:
Allowed Callbacks URLs: http://127.0.0.1:8000/accounts/switch-workspace/, http://localhost:8000/accounts/switch-workspace/,
this is showing in the image below as well:
Anyone knows that what’s wrong? Because I don’t think I did anything wrong following the official tutorial here