I’m trying to deploy in an Azure App Service an Angular application that has integrated AD B2C with a user flow (signupsignin1) and with authorization code flow PKCE, this is what I did:
- For all the configuration of the B2C and the Angular app I used this link: https://learn.microsoft.com/en-us/azure/active-directory-b2c/configure-authentication-sample-angular-spa-app
- I moved the code to Angular 14 and created a home component with the button sign-in.
The redirect URL: http://localhost:4200/home
It works properly.
-Configuration to deploy in App Service-
- App Service
Stack Node v16
SO: Windows
Created…
Then I copied the URL => https://name-app.azurewebsites.net
- Angular
a. I added the web.config and configure the angular.json
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Angular.json
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
b. msalConfig I added the new redirect URL:
const msalConfig: Configuration = {
auth: {
clientId: <clientId>,
authority: b2cPolicies.authorities.signUpSignIn.authority,
knownAuthorities: [b2cPolicies.authorityDomain],
redirectUri: 'https://name-app.azurewebsites.net/home',
},
cache: {
cacheLocation: BrowserCacheLocation.LocalStorage,
storeAuthStateInCookie: isIE,
},
system: {
loggerOptions: {
loggerCallback(logLevel: LogLevel, message: string) {
},
logLevel: LogLevel.Verbose,
piiLoggingEnabled: false
}
}
}
- Adding the new Redirect URIs in the app registration of the Angular:
Single-page application:
New URL: https://name-app.azurewebsites.net/home
- Build the Angular.
a. ng b
-
Install in the VS the extension Azure App Service.
-
Deploy the dist folder.
-
In portal Azure go to the App service -> configuration -> Path mappings/Virtual applications and directories/Virtual path:
Edit: sitewwwrootname-project-angular
Save. -
Start the app service.
-
Go to URL.
Now here comes the problem, it loads the home page but when I click on sign-in throw these errors:
a. In page: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
b. Console: GET https://name-app.azurewebsites.net/home, HTTP 404 ‘Not Found’.
c. https://test-deploy-angular.azurewebsites.net/favicon.ico, HTTP 404 ‘Not Found’
Warnings:
d. Cookie “ARRAffinity” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute.
e. This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “”.
10.
Is the redirect URL incorrect in msalconfig or in the registration app?
Is the web.config incorrect?
I don´t know what is wrong. And I searched information about this but I didn´t find anything related.
Regards,
Luis Cáceres.
2
Answers
To benefit the community here, posting our discussion/solution from Q&A thread.
Cause: Misconfiguration in the application’s web.config file caused a bad redirect after "sign in".
Resolution: Change the following line in the web.config file so that it redirects to “/index.html” and instead of “/”:
Thanks for your cooperation with this, Luis.
If your
web.config
can’t process the request, you will get this error on the page:That can happen for many reason, but in your case the likelihood is that your code param that comes from the B2C redirect is too big for the default limits. If that is the case, the solution will be setting the
maxQueryString
higher than the default in yourweb.config
.It would look like: