0

Asp .Net Identity CoreIdentity Server 4を使用しようとしています。ユーザーが正しくログインしていることをログ(Id)で確認できます。Identity Server 4(2.0)がAsp.NetコアIDクッキーを読み取っていない

情報:Xena.IdentityServer.Controllers.AccountControllerログイン[0] ユーザー

マイログインコントローラは、その後、私の管理コントローラに介してユーザが送信されます。

[Route("[controller]/[action]")] 
[Authorize] 
//[Authorize(AuthenticationSchemes = "Identity.Application")] 
public class ManageController : Controller 
{ 

    [HttpGet] 
    public async Task<IActionResult> Index(ManageMessageId? message = null) 
    { 
    ..... 
    } 
} 

何らかの理由でログインが失われるため、ユーザーは到着しません。

info: Microsoft.AspNetCore.Mvc.RedirectToActionResult[2] 
     Executing RedirectResult, redirecting to /Manage/Index. 
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2] 
     Executed action Xena.IdentityServer.Controllers.AccountController.Login (Xena.IdentityServer) in 3493.6102ms 
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] 
     Request finished in 3515.9158ms 302 
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] 
     Request starting HTTP/1.1 GET http://localhost:5000/Manage/Index 
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2] 
     Authorization failed for user: (null). 
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[3] 
     Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'. 
info: Microsoft.AspNetCore.Mvc.ChallengeResult[2] 
     Executing ChallengeResult with authentication schemes(). 
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[12] 
     AuthenticationScheme: Bearer was challenged. 
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2] 
     Executed action Xena.IdentityServer.Controllers.ManageController.Index (Xena.IdentityServer) in 46.2285ms 
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] 
     Request finished in 58.6793ms 401 

私はクッキーがブラウザであることがわかりますAuthorization failed for user: (null).手がかりの一部は、このラインだと思います。それはちょうど読まれていない。

アイデンティティ・サーバー4には独自のCookieがあり、Asp.netのコアIDには同じCookieが必要です。私はUsing ASP.NET Core Identityに従ってみましたが、助けにはなりませんでした。アイデンティティサーバープロジェクトの追加

//Adds Asp.net identity 
     services.AddDbContext<ApplicationDbContext>(builder => 
      builder.UseSqlServer(Configuration.GetConnectionString("XenaIdentityConnection"))); 

     // Configuer Asp.net Identity 
     services.AddIdentity<ApplicationUser, IdentityRole<long>>(config => 
      { 
       config.Password.RequireDigit = true; 
       config.Password.RequireLowercase = true; 
       config.Password.RequireNonAlphanumeric = false; 
       config.Password.RequireUppercase = true; 
       config.Password.RequiredLength = 8; 
       config.User.RequireUniqueEmail = true; 
       config.SignIn.RequireConfirmedEmail = true; 
       config.SignIn.RequireConfirmedPhoneNumber = false; 
      }) 
      .AddEntityFrameworkStores<ApplicationDbContext>() 
      .AddSignInManager<ApplicationSignInManager>() // Adds custom SignIn manager. 
      .AddDefaultTokenProviders(); 


    //https://identityserver4.readthedocs.io/en/release/topics/signin.html 
     services.AddAuthentication(options => 
      { 
       options.DefaultScheme = IdentityConstants.ApplicationScheme; 
      }) 
      .AddGoogle("Google", options => 
      { 
       options.AccessType = "offline"; 
       options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; 
       options.ClientId = "xxxxx-jvu30c2n19thoqimd97b4jk1r2poh17p.apps.googleusercontent.com"; 
       options.ClientSecret = "g29nXgVoFZBIBNS-hJJxPWXW"; 
      }).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, "OpenID Connect", options => 
      { 
       options.SaveTokens = true; 
       options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; 
       options.SignOutScheme = IdentityServerConstants.SignoutScheme; 
       options.RequireHttpsMetadata = settingsSetup.RequireHttpsMetadata; 
       options.Authority = settingsSetup.Authority; 
       options.ClientId = "testclient"; 
       options.Scope.Add("testapi"); 
       options.ResponseType = OpenIdConnectResponseType.IdTokenToken; 
       options.TokenValidationParameters = new TokenValidationParameters 
       { 
        NameClaimType = "name", 
        RoleClaimType = "role" 
       }; 
      }); 

    services.AddIdentityServer() 
      .AddSigningCredential(LoadCertificate()) 
      .AddConfigurationStore(options => 
      { 
       options.ConfigureDbContext = builder => 
        builder.UseSqlServer(Configuration.GetConnectionString("XenaIdentityConnection"), 
         sql => sql.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)); 
      }) 
      .AddOperationalStore(options => 
      { 
       options.ConfigureDbContext = builder => 
        builder.UseSqlServer(Configuration.GetConnectionString("XenaIdentityConnection"), 
         sql => sql.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)); 

      }) 
      .AddAspNetIdentity<ApplicationUser>() 
      .AddProfileService<ProfileService>(); 

起動/インデックスを管理して、私の問題を解決しない、次の。しかし、オープンIDの接続ログインは機能しません。なぜなら、IDサーバー内の内部コントローラを使用して認証ができないためです(過負荷にしたくない)。 Identity Server 4にAspnet IDで設定されたCookieを使用させるか、その逆を行う方法を理解する必要があります。

// [承認(AuthenticationSchemes =「Identity.Application」)]

このソリューションは、私がこれに傾いていますので、私は新しいものを開いているStackに尋ね前の質問から来ましたIDクッキーの問題ではなく、アイデンティティサーバーのセットアップの問題です。

+0

これは奇妙な設定のようです。あなたの問題は、Identity Serverからコントローラへのリダイレクトが認証後に行われると、ASP Identityが引き継ぎ、ベアラトークンを拒否していると思います。 IDプロバイダとしてアイデンティティ・サーバーを使用している場合、なぜこのようにASPアイデンティティを使用したいのですか?より良い解決策は、Identity Server 4のドキュメントを参照して、アイデンティティ・サーバーのユーザー・ストアをASP Identityに組み込む方法を見て、ユーザー管理のみに使用する方法です。クライアントアプリケーションでopenid connectを使用し、プロバイダとしてIdsvr4を設定できます。 – Derek

+0

私はその声明の多くがもう一度やり直したいと理解しているのか分かりませんか?私はIDサーバのチュートリアルに従ってきました。 IDを指すWebアプリケーションがあります。 Idsだけがデータベース内のユーザーを編集する能力を持っています。私は、Web APIやサードパーティのアドオンがidsに認証され、ユーザーがユーザーデータを更新できるようにする必要があります。私が何か間違っていたら、詳しく教えてください。 – DaImTo

+0

ここに私が行っているサンプルの一つへのリンクがありますhttps://github.com/IdentityServer/IdentityServer4.Samples/blob/release/Quickstarts/6_AspNetIdentity/src/IdentityServerWithAspNetIdentity/Startup.cs – DaImTo

答えて

0

私は今朝問題を最終的に見つけました。この問題の一部は、IdentityConstantクッキーを使用するカスタムサインインマネージャがあるためです。

services.AddAuthentication(options => 
       { 
        options.DefaultAuthenticateScheme = IdentityConstants.ApplicationScheme; 
        options.DefaultChallengeScheme = IdentityConstants.ApplicationScheme; 
       }) 

DefaultAuthenticateSchemeとDefaultChallengeSchemeの両方を設定する必要があります。そうすれば、すべてがうまくいく。

関連する問題