Azure B2C GetOwinContext().Authentication.Challeng

2019-01-29 02:49发布

I am using Azure B2C and I am using the project at https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-webapp-dotnet as startup guide. I manage to run this sample fine by replacing the config entries with my client ID, tenant ID, etc. However when I try to add Azure B2C authentication to my current web app (Asp.NET MVC dot net 4.5) it behaves in a very weird way. When I press log in it redirects me to a slightly different url than it does in the working sample. It replaces the And sign after the policy with a question mark /authorize?p=b2c_1_signin***?***client_id

This is how the policy url is showing in the Azure B2C portal window: https://login.microsoftonline.com/XXX.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1_SignIn&client_id=XXXX&nonce=defaultNonce&redirect_uri=https%3A%2F%2Flocalhost%3A44316%2F&scope=openid&response_type=id_token&prompt=login

However this is the url that my app strangely redirects to: # login.microsoftonline.com/XXX.onmicrosoft.com/oauth2/v2.0/authorize?p=b2c_1_signin?client_id=XXXXX&redirect_uri=https%3a%2f%2flocalhost%3a44316%2f&response_mode=form_post&response_type=id_token&scope=openid&state=OpenIdConnect.AuthenticationProperties%3d1dRzpEoUYWC8q6vPoGU3VtcY7wXXmMDVlkWqr8aQLvWqv64IWeGE0jUnQ6chCZBWEo55uYHsSD27R6EjKIlEaEQWdH6dgIrNDj_n234nLkHb7bKsToir8Yr8j7gbXPb7dBG00wlOufyOfXRT29owsOzjJ8WWwguWDWlo2MN3McsuIWflDKup5qCtQTUS71RBGAEbcQJ_1BqFxIUZsbTglEg4KGm-mroT0tz7PGDcRQU&nonce=636311347285953639.YzQyOWNmYjQtNzAxOS00MTBmLTlkYzQtZGM4MjNlNjdjYThlM2ZlMWMxZGEtYWE0MS00YzY3LWFiM2MtZDgyZWNiNGUxOWQ0

I copied the code exactly from the working sample and it didn't work. I even created a whole new mvc project from scratch and I copied the code from the sample project and it still didn't work. When it redirects to that url it shows 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

I am pretty sure the answer is quite obvious and I will look very silly but I'm pulling my hair here and any input is really appreciated.

1条回答
干净又极端
2楼-- · 2019-01-29 03:29

Nevermind guys the problem was resolved by updating Microsoft.IdentityModel.Protocol.Extensions to version 1.0.4.4 or later.

Hope this helps anyone who is still struggling with this.

查看更多
登录 后发表回答