2017-09-18 5 views
0

Auth0을 인증 공급자로 사용하여 Razor Pages 응용 프로그램을 만들고 LoginPath 문제가 발생합니다.Auth0 및 Asp.Net Core 2.0 면도기 페이지 LoginPath 문제

services.ConfigureApplicationCookie(options => options.LoginPath = "/Index/Login"); 

내가 services.AddAuthentication 코드의 부분 만 아래 그 리디렉션하지 않는 퍼팅 시도/색인/: 나는 당신이 ConfigureServices 방법이 점을 넣어해야한다고 다른 StackOverflow의 답변을 보았다 로그인. Auth0 로그인 페이지로 리다이렉트하는 데 [인증] 속성 오류가 발생하는 것을 다른 곳에서는 볼 수 없습니다.

public async void OnGetLogin(string returnUrl = "/") 
{ 
    await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties() { RedirectUri = returnUrl }); 
} 

내 전체 ConfigureServices 코드는 다음과 같습니다 :

public void ConfigureServices(IServiceCollection services) 
{ 
    // Add authentication services 
    services.AddAuthentication(options => { 
     options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; 
     options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; 
     options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;     
    }) 
    .AddCookie() 
    .AddOpenIdConnect("Auth0", options => { 
     // Set the authority to your Auth0 domain 
     options.Authority = $"https://{Configuration["Auth0:Domain"]}"; 

     // Configure the Auth0 Client ID and Client Secret 
     options.ClientId = Configuration["Auth0:ClientId"]; 
     options.ClientSecret = Configuration["Auth0:ClientSecret"]; 

     // Set response type to code 
     options.ResponseType = "code"; 

     // Configure the scope 
     options.Scope.Clear(); 
     options.Scope.Add("openid"); 
     options.Scope.Add("groups"); 
     options.Scope.Add("profile"); 
     options.Scope.Add("email");         

     // Set the callback path, so Auth0 will call back to http://localhost:5000/signin-auth0 
     // Also ensure that you have added the URL as an Allowed Callback URL in your Auth0 dashboard 
     options.CallbackPath = new PathString("/signin-auth0"); 

     // Configure the Claims Issuer to be Auth0 
     options.ClaimsIssuer = "Auth0"; 

     options.Events = new OpenIdConnectEvents 
     { 
      // handle the logout redirection 
      OnRedirectToIdentityProviderForSignOut = (context) => 
      { 
       var logoutUri = $"https://{Configuration["Auth0:Domain"]}/v2/logout?client_id={Configuration["Auth0:ClientId"]}"; 

       var postLogoutUri = context.Properties.RedirectUri; 
       if (!string.IsNullOrEmpty(postLogoutUri)) 
       { 
        if (postLogoutUri.StartsWith("/")) 
        { 
       // transform to absolute 
       var request = context.Request; 
         postLogoutUri = request.Scheme + "://" + request.Host + request.PathBase + postLogoutUri; 
        } 
        logoutUri += $"&returnTo={ Uri.EscapeDataString(postLogoutUri)}"; 
       } 

       context.Response.Redirect(logoutUri); 
       context.HandleResponse(); 

       return Task.CompletedTask; 
      } 
     }; 
    }); 

    services.ConfigureApplicationCookie(options => options.LoginPath = "/Index/Login"); 

    services.AddMvc(); 
} 

사람은 2.0에서 제대로이 작업을 수행하는 방법을 알고 난이 경로가 색인 페이지로 설정 얻을 수 있다면이 코드가 실행됩니다 생각?

+0

해결 방법을 찾으셨습니까? 나는 또한 Auth0와 함께 면도 페이지를 사용하려고 시도하고 이것을 파악할 수 없습니다. – hs2d

+0

@ hs2d 아니에요. 아니. 나는 Azure B2C를 사용하여 끝내었고 .NET Core 웹 응용 프로그램으로 훨씬 잘 작동합니다. – Rob

답변

0

당신은 작동하려면이 코드를 추가해야합니다 :이 추가되면

services.AddMvc() 
    .AddRazorPagesOptions(options => 
    { 
     options.Conventions.AuthorizeFolder("/"); 
     options.Conventions.AllowAnonymousToPage("/Account/Login"); 
    }); 

, 내 코드가 작동하고 오른쪽 로그인 페이지로 리디렉션하기 시작했다.