Auth0 Home Blog Docs

One Application (WebApp, App, API) per project. Is it possible?

Hi everyone,
our projects (I think as most do) normally have three Parts:

  • Backend (API)
  • WebApp
  • App

In Auth0 context, that would mean three applications. But what if the App/WebApp wants to access data from the API? It needs a valid token from the API App, doesn’t it?

I tried that out by creating those three apps and changing the Client Id for the WebApp Quickstart to the one from the API. That works! :+1:

But for the React Native Quickstart, changing the Client Id to the API one will lead to a spontaneously closing window.

Do you have any idea on how to configure such a scenario, since I know the API App is thought for M2M communication, but other people must have this problem?

Thanks very much!

That’s not the right approach. Don’t change the ClientID in your app/webapp. Create a client application for Webapp and App, as you’ve done, of which you’ll use the ClientID in your code/project configuration (when doing the authorization request towards Auth0) as it comes by default (when you use the Quickstart sample project).

What you need to do is to put your API (API identifier) as audience parameter in the authorization request.

You find the API identifier here…

…which you’d put in your code like this for example:

const webAuth = new auth0.WebAuth({
  domain: authConfig.domain,
  redirectUri: `${window.location.origin}/callback`,
  clientID: authConfig.clientId,
  responseType: "token id_token",
  audience: "https://example-api/", // <---- NOTE THIS OPTION!
  scope: "openid profile email read:bookings delete:bookings"
});

(In your case, you wouldn’t use the API App at all, which is basically just an automatically generated sample/test app.)