I have been playing with Microsoft.Identity platform and trying to get it to work with the basic templates in aspnetcore 6.0, but I get stuck in an infinite login loop.
I am using projects created from the templates for web app and web api (using these commands "dotnet new webapi --force --auth IndividualB2C"
and "dotnet new webapp --force --auth IndividualB2C"
) and then updated the appsettings in both to connect to my Azure B2C tenant.
WEB APP
"AzureAdB2C": {
"CallbackPath": "/signin-oidc",
"ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"ClientSecret": "xxxxx",
"Domain": "xxxx.onmicrosoft.com",
"EditProfilePolicyId": "B2C_1_EditProfile",
"Instance": "https://xxxx.b2clogin.com/",
"SignedOutCallbackPath": "/signout/B2C_1_susi",
"SignUpSignInPolicyId": "B2C_1_SUSI"
},
"DownstreamApi": {
"BaseUrl": "https://localhost:7208/",
"Scopes": "https://xxxx.onmicrosoft.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.impersonation"
}
WEB API
"AzureAdB2C": {
"ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"Domain": "xxxx.onmicrosoft.com",
"Instance": "https://xxxx.b2clogin.com/",
"Scopes": "https://xxxx.onmicrosoft.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/user.impersonation"
"SignUpSignInPolicyId": "B2C_1_SUSI"
}
After making these changes, I can run the applications and the Web App will attempt to login in through my social accounts then go into an infinite loop redirecting between the login server and the app redirect Url.
I do get a log message that MicrosoftIdentityWebChallengeUserException was thrown (presumably because I need to consent to the scopes). My understanding is that the [AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
attribute on the Razor page should handle this consent workflow for me, but it doesn't seem to be doing that.
Is there something additional I need to do in configuring these sample applications or a way to trap the WebChallenge exception (and if so, how do I issue the challenge back to the user)?
I feel like I am missing something obvious here to get this to work, but I cannot seem to find it. Can anyone provide some guidance to get this to work?