成功的Azure AD B2C登录后,WebForms App进入无限循环

时间:2018-02-01 04:35:09

标签: authentication cookies owin azure-ad-b2c owin-middleware

我已迁移现有网站,以使用Azure AD B2C登录服务进行身份验证。它在本地计算机(IIS)中完美运行。但是当我在其中一个开发服务器中部署时,它会在应用程序和B2C成功登录后生成无限循环(ID令牌生成)。以下是配置的OpenID Connect选项

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            CookieName = "<cookie name>"
        }
        );

app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                // Generate the metadata address using the tenant and policy information
                MetadataAddress = String.Format(aadInstance, Tenant, DefaultPolicy),
                ClientId = ClientId,
                RedirectUri = RedirectUri,
                PostLogoutRedirectUri = PostLogoutRedirectUri,

                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    //
                    // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                    //
                    AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                    AuthenticationFailed = OnAuthenticationFailed,
                    RedirectToIdentityProvider = OnRedirectToIdentityProvider
                },

                // Specify the claims to validate
                TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "name"
                },

                // Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
                Scope = $"openid {ReadTasksScope}"
            }
        );

无限循环按照提到的顺序发生

  1. B2C - SelfAsserted? (在登录页面上提交)
  2. B2C - 确认?
  3. WebForms应用程序 - 重定向到应用程序URL - &gt; https://localhost:44371
  4. 授权?
  5. 在第3步中,应该已经生成了应用Cookie,但事实并非如此。因此,在步骤3和步骤3之间发生无限循环。 4

    OpenIdConnect.nonce.XbB4GN2ZUT%2BT%2F68ac5W7J4VdbdOn%2FHq6yFiDSrBIdjk%3D=R2RQbVA3b0hhaUh2Y1JMc212aGlnRWwtd3kzdW1vNklGMGw2eDV1dnlKbVNCQTNkUHNVczVPajdyaDhiaHNFMG9lWlItSGQtcVZpanBOQTd0azVBaHNPTDNEYjdUY3lBUE5ocUR3VDJEZVNPZXo4d0pTSVk0c0prWUEzZE90M2poSlczODVYX0NibE05LXNnc2tNem05eTl4R1lhNTBFV2hVYjJ6LVUwMjhNLWk3ZTBMOGhjbHN1ckh1cVBKamh4eVRLMUVHb2JnbGlzZjRMUm5zY3VvUkNDdExXaEFjWjFnTVVralYwWEIxaw%3D%3D; path=/; expires=Wed, 31-Jan-2018 12:35:46 GMT; secure; HttpOnly
    

    在本地计算机中,在步骤3中生成应用程序cookie(带有自定义名称)。

    OpenIdConnect.nonce.LWWLkUxp3jcWGk%2BpYClSUqjCShbiZeKXNPv%2FYWgFS20%3D=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT<app_cookie_name>=-Q6cr6axj6kqZ6UklGCuSwqVswxcbH2-LehbrNpAHQ0gP9wvonjl95fHPO0oGRh252UiTX9MhOLl6pG82ES04TRoxCWTo3Gn2dLf-8L0eSZkr01q7QuQEP8NNckhaduiC54l1biHvLan561N6aAz8vzWNu54ceKghDbMBrx1MsbHVGnkfPonU3a8lK6p0tc3Q8_He0vx8ipM0rg2V5gegWGLfmp035bXUwqGWghdlE8tzIkUqBafOrcWR_tcXe342Ujd1MJfX5tokLSA-ZC88b1T-xxhp153sZqZFHPH8AdaA6aLcuGBdhwdmi4vQZSOKAIWoWRpWORHAMR5Pg3FVlDLXG95ro036z3IHFzt2wkt9lw3ubDZQnLt9cm8NT6bwobkXmVaLoE1qEFujfDesA5b-6_WgmqrOEPCDm5PfJ69_qz3_x7Cv-i5dIkeFauT7guBeZim2KA3HllkWmhS2jlSZvzXDSVe5QDyYgdjAIvjLDEnyxe_Xj6OtITjBnnI2Q10HQM6ja3OuHfbtG2fwqSyiPQNRS4uS-l0qtQUC7RrbQL2ix-N5gpNzYtqk98SjwFe99y-FAgUk9EXE7YOG6200ECiA0uYeNSt63sXglhrTr0y3a_F2lCgt8e2uczGsdVwA8MQyC7qkRtpuizwxjRNAMa8lS4vkwFWOFgVVlS18xN19bg-ZKp91R4dDISRuyO6JwYVq3fuVbacs_RFuBRALsg8Nph20Y5gFzdYK_CU-k5JLQd-OwyoB7qdbHMnqvXVvnEZ4uyORGWrZ3zKFSlDLeOwIfb6gblLh7HNioN0wvG7oBAofMAJvKMaLTL6xzbTOlnF90WlBuMLjXYY-WrsLyHMopK93Uqy8SCmfGIHIbBM0v6kvo3MjKCG7yBUsZUYXKadn3VwQqC9TfJuQJEiMyMBxgZf_whscA-gvabVnJwEexZIKKUkVpsrmoUyuoTuWSRUvz3YMjGHohg3Jw; path=/; secure; HttpOnly
    

    没有任何线索就陷入了困境。但是我将尝试自定义CookieAuthentication选项的cookie管理器,如此stackoverflow中所述question

    但我不自信,因为它适用于本地机器,为什么不在服务器上。 请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

我已经在MVC应用程序问题上使用similar post来解决这个问题。

我必须通过添加带有重定向网址的网页来更改重定向网址。

新的重定向网址 - &gt; https://www.appname.com/Default.aspx

旧重定向网址 - &gt; https://www.appname.com/

但我不必为localhost添加页面名称。它按原样工作。