2017-09-18 5 views
0

Auth0を認証プロバイダとして使用してRazor Pagesアプリケーションを作成していますが、LoginPathの問題が発生しています。私は他のStackOverflowにあなたがConfigureServicesメソッドにこれを置くべきと言う答えを見てきました:Auth0とAsp.Net Core 2.0 Razor Pages LoginPathの問題

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

/私はそのコードのservices.AddAuthenticationセクションの下に入れてみましたが、それは/インデックスにリダイレクトされません。ログイン。私はAuth0ログインページにリダイレクトするための[Authorize]属性の失敗を正しく取得する方法を他のどこにも見ていません。私はパスがセットされますができれば、私はこのコードが実行しますインデックスページに考え出し:

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 Webアプリケーションでより良く機能します。 – Rob

答えて

0

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

私はこれを追加すると、私のコードは動作し、右のログインページにリダイレクトするために始めました。

関連する問題