auth0-angular icon indicating copy to clipboard operation
auth0-angular copied to clipboard

dynamic config auth0 module at later point after APP_INITIALIZER

Open AngrySKL opened this issue 2 years ago • 8 comments

Describe the problem you'd like to have solved

According the description here, Auth0 module could only be configured during APP_INITIALIZER. In my scenario, it can not work. I need to show a page(which will be translated to different languages) to the user which datacenter(each datacenter has its own set of auth0 configuration) to connect to, and only after the selection is done, I can know which auth0 configuration I should give to auth0 module.

Describe the ideal solution

Maybe allow later time configuration will help

AngrySKL avatar Jun 08 '22 03:06 AngrySKL

Thanks for reaching out.

What you are describing seems to be doable with APP_INITIALIZER, but will come down to a couple of extra things:

  • Store the selected datacenter in local storage
  • Refresh the page after selecting a data-center
  • Use the datacenter from localstorage in your APP_INITIALIZER

Even tho I can understand this might not be ideal, I believe it should work fine for your use case.

frederikprijck avatar Jun 08 '22 07:06 frederikprijck

thanks for the quick response, actually I am building an Ionic Mobile App, I do not think refresh is acceptable. And as I said, the datacenter selection page needs to be translated to different languages which means when the page is shown, the APP_INITIALIZER should be already done, right? I am checking auth0-spa-js this package, maybe I need to build an AuthService myself?

AngrySKL avatar Jun 08 '22 07:06 AngrySKL

We currently have no way for you to initialize our SDK at a later point in time. You can definitely leverage Auth0-SPA-JS if our Angular SDK doesn't work for you.

Could you elaborate on what settings are different between the several datacenters that would require you to initialize it at a later point in time?

frederikprijck avatar Jun 09 '22 09:06 frederikprijck

We have this concept called datacenter, each datacenter has its own Auth0 domain id and client id. The first step of our App is to let the user choose which datacenter to connect to, and only after the datacenter is selected, I can know the domain id and client id and at this point I can initialize the Auth0 SDK.

AngrySKL avatar Jun 18 '22 03:06 AngrySKL

And I tried to call AuthModule.forRoot in feature module which I think is wired, and yes, it did not work, lol.

AngrySKL avatar Jun 18 '22 03:06 AngrySKL

And I have encounter one question when I was using Auth0-SPA-JS, does refresh token only work when I explicitly call getTokenSillently? Like I set refresh token to 7 days, id token to 20 minutes, and I close my app for 1 day, and then reopen the app, what should I expect when I call auth0Client.isAuthenticated() ?

AngrySKL avatar Jun 18 '22 03:06 AngrySKL

There should be no need to call getTokenSilently, as long as you use

const auth0 = await createAuth0Client({
  domain: '<AUTH0_DOMAIN>',
  client_id: '<AUTH0_CLIENT_ID>',
  redirect_uri: '<MY_CALLBACK_URL>'
});

The above code will immediately call checkSession (which calls getTokenSilently under-the-hood for you).

frederikprijck avatar Jun 20 '22 06:06 frederikprijck

cool, thanks for your help, but I think it is better for auth0-angular to be able to dynamically initialize

AngrySKL avatar Jun 24 '22 13:06 AngrySKL

I am closing this for now, as I believe there is little demand for this and there are workaround available.

We can always reconsider this if demand increases.

frederikprijck avatar Sep 30 '22 11:09 frederikprijck