簡體   English   中英

401未經ASP.Net Core 1.1 MVC應用程序中IdentityServer3的授權

[英]401 Unauthorized with IdentityServer3 In ASP.Net Core 1.1 MVC Application

在過去的一年中,我將IdentityServer3與多個應用程序一起使用。 所有這些應用程序都在.Net Framework 4.5上運行。 現在,我已經創建了ASP.Net Core MVC(1.1)應用程序,並且我想使用我的IdentityServer保護該應用程序的安全。 但是我正在努力使它起作用。 我收到401未經授權的錯誤。

這是我正在使用的配置:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies",
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
});

JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    AuthenticationScheme = "oidc",
    SignInScheme = "Cookies",

    Authority = "<IdentityServer URL>",
    RequireHttpsMetadata = false,

    ClientId = "clientid",

    ResponseType = "token id_token",
    Scope = { "openid","email"},

    SaveTokens = true,

    PostLogoutRedirectUri = "http://localhost:29995/",

    Scope = { "openid, email" },
    ResponseType = "id_token token",

    Events = new OpenIdConnectEvents()
    {
        OnTokenValidated = (context) =>
        {
            //my code
            return Task.FromResult(0);
        }
    }
});

當我嘗試訪問安全頁面時,我得到401未經授權。 它甚至都不會轉到IdentityServer的登錄頁面。

嘗試擊中的網址

https://<IdentityServerUrl>/connect/authorize?client_id=APITestweb&redirect_uri=http://localhost:29995/signin-oidc&response_type=code id_token&scope=openid profile email&response_mode=form_post&nonce=<data>&state=<data>

客戶端ID和url的配置正確。 我嘗試創建另一個ASP.Net MVC應用程序(不是ASP.Net Core),並且在使用相同配置信息的情況下也可以正常工作。

請幫忙。

[編輯]添加日志記錄信息

[Debug] Executing action "WebClient.Controllers.HomeController.About (WebClient)"
[Information] Authorization failed for user: null.
[Warning] Authorization failed for the request at filter '"Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter"'.
[Information] Executing ChallengeResult with authentication schemes ([]).
[Debug] AuthenticationScheme: "Cookies" was not authenticated.
[Verbose] Entering "Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler"'s HandleUnauthorizedAsync.
[Verbose] Using properties.RedirectUri for 'local redirect' post authentication: '"http://localhost:29995/Home/About"'.
[Debug] Reading data from file '"C:\path\DataProtection-Keys\key-2a848b38-3cf4-4c57-b8ef-4c0b56c83993.xml"'.
[Debug] Found key {2a848b38-3cf4-4c57-b8ef-4c0b56c83993}.
[Debug] Considering key {2a848b38-3cf4-4c57-b8ef-4c0b56c83993} with expiration date 2017-03-08 21:08:54Z as default key.
[Debug] Decrypting secret element using Windows DPAPI.
[Debug] Opening CNG algorithm '"AES"' from provider 'null' with chaining mode CBC.
[Debug] Opening CNG algorithm '"SHA256"' from provider 'null' with HMAC.
[Debug] Using key {2a848b38-3cf4-4c57-b8ef-4c0b56c83993} as the default key.
[Verbose] Performing protect operation to key {2a848b38-3cf4-4c57-b8ef-4c0b56c83993} with purposes "('project path', 'Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware', 'System.String', 'oidc', 'v1')".
[Verbose] Performing protect operation to key {2a848b38-3cf4-4c57-b8ef-4c0b56c83993} with purposes "('project path', 'Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectMiddleware', 'System.String', 'oidc', 'v1')".
[Information] AuthenticationScheme: "oidc" was challenged.
[Information] Request finished in 1301.6524ms 401
[Debug] Connection id ""0HL10CR7G2G0J"" completed keep alive response.

如果您使用的是Microsoft.AspNetCore.Authentication.OpenIdConnect v.1.1.0,則當前存在一個錯誤(或可能稱為更改的重大更改)。

對我來說,1.0.0軟件包仍在工作,因此請檢查降級是否有幫助。

鏈接到1.1.0中引入的有關變更的GitHub問題以及其為何被打破

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM