2016-12-08 16 views
2

私は過去1年間に複数のアプリケーションでIdentityServer3を使用しています。それらのアプリケーションはすべて.NET Framework 4.5で動作しています。今、私はASP.Net Core MVC(1.1)アプリケーションを作成しました。このアプリケーションをセキュリティで保護するために私のIdentityServerを使いたいと思っていました。しかし、私はそれが機能するように苦労しています。 401 Unauthorizedエラーが表示されます。401 ASP.Net Core 1.1のMVCアプリケーションでIdentityServer3に無許可

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のをヒットしようとしていることを

URL。私は別のASP.Net MVCアプリケーション(ASP.Netコアではない)を作成しようとしましたが、それは同じ設定情報でうまく動作します。

助けてください。 (1がそれを呼ぶかもしれないとして、または変更を壊す)

[編集]あなたはMicrosoft.AspNetCore.Authentication.OpenIdConnect v.1.1.0を使用している場合はログ情報

[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. 
+0

1.1プロジェクトにログを追加しましたか?伐採は何を言いますか? – Lutando

+0

@ルタンゴありがとうございます。私は質問にログ情報を追加しました。 – user3731783

+0

OIDC mwのどのバージョンですか? –

答えて

3

を追加し、そこに現在のバグです。

私にとって、1.0.0パッケージはまだ動作していますので、ダウングレードが役立つかどうかを確認してください。

Link to GitHub issue on change introduced in 1.1.0 and why it was breaking

+0

あなたがいます。どうもありがとうございます。同様の問題を抱えている他の人たちのために、私はMicrosoft.AspNetCore.Authentication.Cookiesもダウングレードしなければなりませんでした。その後、完全な.Net Frameworkでは必要ないリダイレクトuriにsingin-oidcパスを追加する必要がありました。 – user3731783

関連する問題