0

Asp .Net Identity CoreIdentity Server 4과 함께 사용하려고합니다. 사용자가 제대로 로그인했다는 것을 로그 (Ids)에서 볼 수 있습니다.Identity Server 4 (2.0)가 Asp.Net Core Identity 쿠키를 읽지 않습니다.

정보 : 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에는 자체 쿠키가 있고 Asp.net 핵심 신원에는 해당 쿠키가 있으며 동일한 쿠키를 읽어야합니다. 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 연결 로그인은 인증을 위해 Identity Server 내의 내부 컨트롤러를 사용하기 때문에 작동하지 않습니다. 과부하를 원하지 않습니다. Identity Server 4에서 Aspnet ID 또는 비자로 설정된 쿠키를 사용하는 방법을 파악해야합니다.

// [권한 부여 (AuthenticationSchemes = "Identity.Application은")]

이 솔루션은 내가 내가 내가이쪽으로 생각이 기울고하고 있기 때문에 새로운 하나를 열었습니다 Stack에 물었다 이전 질문에서 온 ID 쿠키 문제가 아닌 ID 서버의 설정 문제입니다.

+0

이상한 설정입니다. 귀하의 문제는 Identity Server에서 컨트롤러로의 리디렉션이 인증 후 발생하면 ASP ID가 차지하고 베어러 토큰을 거부한다는 것입니다. 아이덴티티 서버를 아이덴티티 프로 바이더로 사용한다면 왜 이런 방식으로 ASP 아이덴티티를 사용하고 싶습니까? 더 좋은 해결책은 Identity Server 4 설명서를보고 Identity Server의 사용자 저장소를 ASP ID와 통합하고 사용자 관리에만 사용할 수있는 방법을 살펴 보는 것입니다. 그런 다음 클라이언트 응용 프로그램에서 openid connect를 사용하고 Provider로 Idsvr4를 설치할 수 있습니다. – Derek

+0

그 진술 중 상당 부분이 다시 시도하고 싶다는 것을 잘 모르겠습니까? 나는 신원 서버 튜토리얼을 따라왔다. ID를 가리키는 웹 앱이 있습니다. Ids만이 데이터베이스 내에서 사용자를 편집 할 수 있습니다.웹 API와 타사 애드온이 아이디를 인증 할 수있을뿐만 아니라 사용자가 자신의 사용자 데이터를 업데이트 할 수 있도록 허용 할 수 있어야합니다. 내가 뭔가 잘못하고 있다면 정교하게 말하십시오. – 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을 모두 설정해야합니다. 그러면 모든 것이 제대로 작동합니다.