Set audience inside Django App to call protected API

Hello,

I have started using Auth0 inside of a django application and I followed the quickstart guide here:

I have it all up and running, login works like a dream and everything was fine.

I then moved on to building an API which again has Auth0 authentication. API is written in python fastapi and again you have amazing documentation which I have followed here:

The problem I am running into now, is getting a user who is logged into the django app to hit the API.

I am getting the current error message:

{
  "detail": {
    "status": "error",
    "message": "Audience doesn't match"
  }
}

Which is all pretty self explanatory. My Bearer token has the aud set as the Client ID of my django app. What needs to happen is during sign in I need to be able to update the audience, so I tried the following:

def login(request):
    return oauth.auth0.authorize_redirect(
        request,
        request.build_absolute_uri(reverse("callback")),
        audience=settings.AUTH0_AUDIENCE
    )

But this does not work.

How do I update the audience inside the django app so I can authenticate inside of the API?

Any help would be greatly appreciated.

I reason for trying:

def login(request):
    return oauth.auth0.authorize_redirect(
        request,
        request.build_absolute_uri(reverse("callback")),
        audience=settings.AUTH0_AUDIENCE
    )

Was due to the fact it talks about it here in the Flask example:

I have resolved my own problem.

Solution:

I was trying to get the Django app to match the API, but instead I needed to get the API to match the django app.

Therefore all i needed to do was to update the audience in my fastapi code be the client id of my django app and then boom…all working perfectly.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.