Blazor с AzureADB2 C застрял в цикле входа навсегда из-за исключения ошибки авторизации - PullRequest
0 голосов
/ 18 июня 2020

Я хочу авторизовать свое приложение с помощью AzureADB2 C. Я использую общий шаблон RedirectToLogin

<AuthorizeView>
    <Authorized>
...
    </Authorized>
    <NotAuthorized>
        @{ Console.WriteLine("Not Authorized");}
        <RedirectToLogin/>
    </NotAuthorized>
</AuthorizeView>

, где перенаправление для входа в систему перенаправляет на AzureADB2 C .UI-контроллер

        _navigationManager.NavigateTo("AzureADB2C/Account/SignIn", true);

Раньше все работало нормально и по-прежнему отлично работает в режиме инкогнито в chrome. Но в обычном режиме он навсегда застрял в l oop, где он перенаправляет на AzureADB2 C для входа в систему, перенаправляет обратно, потому что он уже вошел в систему, но попадает в раздел NotAuthorized и т. Д.

В выводе есть строка

Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The required antiforgery cookie ".AspNetCore.Antiforgery.2Onc2cpxnQY" is not present.

Но если я отключу AntiforgeryValidation

        services.AddRazorPages(o =>
        {
            o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute());
        });
        //services.AddRazorPages();
        services.AddServerSideBlazor();

, все равно будет какая-то тихая ошибка, препятствующая авторизации. Вот результат отладки

Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager: Debug: Requesting navigation to URI AzureADB2C/Account/SignIn?state=hello with forceLoad=True
Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime: Debug: Begin invoke JS interop '4': 'Blazor._internal.navigationManager.navigateTo'
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Debug: The JS interop call with callback id '4' succeeded.
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 GET http://localhost:44377/AzureADB2C/Account/SignIn?state=hello  
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Debug: The request path /AzureADB2C/Account/SignIn does not match a supported file type
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 2 candidate(s) found for the request path '/AzureADB2C/Account/SignIn'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController.SignIn (Microsoft.AspNetCore.Authentication.AzureADB2C.UI)' with route pattern 'AzureADB2C/Account/SignIn/{scheme?}' is valid for the request path '/AzureADB2C/Account/SignIn'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Fallback {*path:nonfile}' with route pattern '{*path:nonfile}' is valid for the request path '/AzureADB2C/Account/SignIn'
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Debug: Request matched endpoint 'Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController.SignIn (Microsoft.AspNetCore.Authentication.AzureADB2C.UI)'
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: Debug: AuthenticationScheme: AzureADB2CCookie was not authenticated.
Microsoft.AspNetCore.Routing.Tree.TreeRouter: Debug: Request successfully matched the route with name '(null)' and template 'AzureADB2C/Account/SignIn/{scheme?}'
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Route matched with {area = "AzureADB2C", action = "SignIn", controller = "Account", page = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult SignIn(System.String, System.String) on controller Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController (Microsoft.AspNetCore.Authentication.AzureADB2C.UI).
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Execution plan of authorization filters (in the following order): None
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Execution plan of resource filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Execution plan of action filters (in the following order): Microsoft.AspNetCore.Mvc.Filters.ControllerActionFilter (Order: -2147483648), Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter (Order: -3000)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Execution plan of exception filters (in the following order): None
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Execution plan of result filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Executing controller factory for controller Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController (Microsoft.AspNetCore.Authentication.AzureADB2C.UI)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Debug: Executed controller factory for controller Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController (Microsoft.AspNetCore.Authentication.AzureADB2C.UI)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Executing action method Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController.SignIn (Microsoft.AspNetCore.Authentication.AzureADB2C.UI) - Validation state: Valid
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Executed action method Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController.SignIn (Microsoft.AspNetCore.Authentication.AzureADB2C.UI), returned result Microsoft.AspNetCore.Mvc.ChallengeResult in 0.0463ms.
Microsoft.AspNetCore.Mvc.ChallengeResult: Information: Executing ChallengeResult with authentication schemes (AzureADB2C).
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler: Debug: HandleChallenge with Location: https://....b2clogin.com/.../b2c_1_susi_debug/oauth2/v2.0/authorize?...
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler: Information: AuthenticationScheme: AzureADB2COpenID was challenged.
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Information: Executed action Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureADB2C.Controllers.Internal.AccountController.SignIn (Microsoft.AspNetCore.Authentication.AzureADB2C.UI) in 37.236ms
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 61.4082ms 302 
Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport: Debug: Waiting for the application to finish sending data.
Microsoft.AspNetCore.SignalR.HubConnectionHandler: Debug: OnConnectedAsync ending.
Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager: Debug: Removing connection 9RAYKqX7W11hXUt9cHz15w from the list of connections.
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 790.7527ms 101 
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 POST http://localhost:44377/_blazor/disconnect multipart/form-data; boundary=----WebKitFormBoundarymF4fZsaeLr6SecM9 359
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Debug: POST requests are not supported
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 2 candidate(s) found for the request path '/_blazor/disconnect'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Blazor disconnect' with route pattern '/_blazor/disconnect/' is valid for the request path '/_blazor/disconnect'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Fallback {*path:nonfile}' with route pattern '{*path:nonfile}' is valid for the request path '/_blazor/disconnect'
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Debug: Request matched endpoint 'Blazor disconnect'
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: Debug: AuthenticationScheme: AzureADB2CCookie was not authenticated.

Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Debug: Disposing circuit 'JNHhYB29Nm5n0jAtPW6p95PgrxY0b8ied423l_Dmd4M' succeded.
Microsoft.AspNetCore.Components.Server.CircuitDisconnectMiddleware: Debug: Circuit with id 'JNHhYB29Nm5n0jAtPW6p95PgrxY0b8ied423l_Dmd4M' terminated gracefully.
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint 'Blazor disconnect'
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 50.466ms 200 
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 POST http://localhost:44377/signin-oidc application/x-www-form-urlencoded 1356
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Debug: POST requests are not supported
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 1 candidate(s) found for the request path '/signin-oidc'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Fallback {*path:nonfile}' with route pattern '{*path:nonfile}' is valid for the request path '/signin-oidc'
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Debug: Request matched endpoint '/_Host'
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler: Debug: Updating configuration
Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler: Debug: Received 'id_token'
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: Information: AuthenticationScheme: AzureADB2CCookie signed in.
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished in 14.9947ms 302 
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 GET http://localhost:44377/  
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Debug: The request path / does not match a supported file type
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 2 candidate(s) found for the request path '/'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Page: /_Host' with route pattern '' is valid for the request path '/'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'Fallback {*path:nonfile}' with route pattern '{*path:nonfile}' is valid for the request path '/'
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Debug: Request matched endpoint '/_Host'
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: Debug: AuthenticationScheme: AzureADB2CCookie was not authenticated.
Microsoft.AspNetCore.Routing.Tree.TreeRouter: Debug: Request successfully matched the route with name '(null)' and template ''
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Information: Route matched with {page = "/_Host", area = "", action = "", controller = ""}. Executing page /_Host
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Execution plan of authorization filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.AutoValidateAntiforgeryTokenAuthorizationFilter
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Execution plan of resource filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Execution plan of action filters (in the following order): Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter (Order: -3000)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Execution plan of exception filters (in the following order): None
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Execution plan of result filters (in the following order): Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.SaveTempDataFilter
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Executing page factory for page Some.Spa.Pages.Pages__Host (Some.Spa.Views)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Debug: Executed page factory for page Some.Spa.Pages.Pages__Host (Some.Spa.Views)
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Information: Executing an implicit handler method - ModelState is Valid
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker: Information: Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService: Information: Authorization failed.

Что это может быть?

Другой связанный вопрос - как предотвратить бесконечный вход в систему l oop, если такая ошибка происходит в процессе производства?

...