Deploying to Azure Static Website problem

Hello,

I’m considering deploying my Angular WebApp to the Azure Storage Static Website hosting. That methods of deploying my SPA is forcing me to use hash path for my routing.

Then my callback url from Auth0 must contains the hash too! But as I read on other threads here it seems impossible.

What are my options?

Daniel

Hi @danbord

You can use the same root path of your application to be the callback URL. In the callback, you will be redirected with the authorization response in the fragment, something that looks like this:

https://yourapp.com#access_token=xxxx&expires_in=xxx&token_type=Bearar&id_token=xxx&...

At the start of your application logic you can use Auth0.js’ parseHash method to check for a valid authorization response and act accordingly:

auth0.parseHash(function(err, authResult) {
  if (err) {
    // this means an error came from a previous authorization request
    return console.log(err);
  } else if (authResult) {
    // if you land here, it means that the fragment had a valid authorization response
    //
    // The contents of authResult depend on which authentication parameters were used.
    // It can include the following:
    // authResult.accessToken - access token for the API specified by `audience`
    // authResult.expiresIn - string with the access token's expiration time in seconds
    // authResult.idToken - ID token JWT containing user profile information
  } else {
    // no authentication result found in the fragment
    // continue with the regular application startup flow
  }
});
1 Like

Hello @nicolas_sabena ,

thanks for your answer, but it does not seems to work as my angular app seems to override the hash part when the route does not actually exists.

I tried to check the window.location.hash from the ngOnInit of my app.component.ts.

Then try a url like http://localhost:4200#test. Result : it just redirects me to http://localhost:4200/#/ without entering the app ngOnInit

Daniel

Oh, nevermind I got it to work! :smiley:

When typing the hash manually in the url bar (when the site is already loaded) it ignores it when the route does not exists. But loading the url with the hash from another page it works.

In the end, I’m finally using a RouteGuard to process it.

Thanks

Dan

2 Likes

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