.Net Framework 4.7.1 + Angular

Hi everyone,

In my organization we are trying to switch to auth0. Currently we have solution where we are using .net MVC application to load our Angular app. Basically we are displaying MVC page wchich have script tags and reference to app-root selector. We are trying to figure what will be the best way to connect those two worlds. Currently we were thinking about handling login step on .NET side, then we have to somehow pass the tokens to Angular, then angular via interceptor will pass the token with the request to the api. What is the best way to share the token between server side app and our SPA ? Is there a possibility to use oauth angular npm package to handle this or we need to manually pass the token to Angular e.g. expose some enpoint with token on mvc side, store token in local storage or something ? What should be the flow when token on mvc side expires ? Additionally I will say that this angular app is also used as microfrontend and module federation but this is another topic I think.

Hi @m.placzkow, and welcome to the Auth0 Community!

For your use case, my suggestion is to set the callback URL to a route within your Angular application. The flow would be something like:

  1. User navigates to your Angular application (initially loaded via the .NET MVC page).
  2. Angular detects that the user is not authenticated.
  3. Angular redirects the user to your .NET MVC application (or a specific endpoint on it).
  4. The .NET MVC application initiates the Auth0 authentication flow, redirecting the user to the Auth0 login page.
  5. User authenticates on the Auth0 page.
  6. Auth0 redirects the user back to your Angular application’s callback route
  7. The library stores the tokens in the browser’s storage.
  8. Your Angular application is now authenticated.

As for refreshing tokens, you can use Silent Authentication. Please see our docs for more information on how to set them up.

Please let me know if you need any additional information!

Sincerely,
Teodor.