2017-01-30 6 views
2

OID2アクセストークンを利用した認証と認可を提供するために、OpenID Connectを使用してIDプロバイダを構築しました。サーバー上の承認ワークフローが機能します。しかし、認証が失敗したときにASP.NET Coreクライアントが自動的にOpenID Connectプロバイダにリダイレクトされるようには見えません。私は現在、ちょうどここで401ASP.NET Core&OpenID Connect外部IDプロバイダへのリダイレクト

である私のstartup.csを受け取る:

 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
     loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
     loggerFactory.AddDebug(); 

     if (env.IsDevelopment()) 
     { 
      app.UseDeveloperExceptionPage(); 
      app.UseBrowserLink(); 
     } 
     else 
     { 
      app.UseExceptionHandler("/Home/Error"); 
     } 

     app.UseStaticFiles(); 

     app.UseCookieAuthentication(); 

     var options = new OpenIdConnectOptions 
          { 
           Authority = "http://localhost:63467", 
           AutomaticAuthenticate = true, 
           AutomaticChallenge = true, 
           AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet, 
           AuthenticationScheme = "oidc", 
           ClientId = "2", 
           ClientSecret = "alskghalsd", 
           Configuration = 
            new OpenIdConnectConfiguration 
             { 
              AuthorizationEndpoint = 
               "http://localhost:63467/connect/authorize", 
              TokenEndpoint = 
               "http://localhost:63467/connect/token" 
             }, 
           PostLogoutRedirectUri = "/", 
           ResponseType = "Code", 
           RemoteSignOutPath = "/signout", 
           UseTokenLifetime = true, 
           SaveTokens = true, 
           SignInScheme = "Cookies", 
           RequireHttpsMetadata = false 
          }; 
     options.Scope.AddRange(new[] { "openid name role profile" }); 
     app.UseOpenIdConnectAuthentication(options); 

     app.UseMvc(routes => 
     { 
      routes.MapRoute(
       name: "default", 
       template: "{controller=Home}/{action=Index}/{id?}"); 
     }); 
    } 

答えて

0

私はIdentityServerを使用してアイデンティティエンドポイントとしてアプリケーションをホストすることによって、これを解決することになったし、それに応じて私のクライアントを構成しました。

 public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddMvc(
      opts => 
       { 
        // custom api exception filter 
        opts.Filters.Add(typeof(ApiExceptionFilter)); 
       }); 
     services.Configure<IISOptions>(
      options => 
       { 
        options.AutomaticAuthentication = false; 
        options.ForwardClientCertificate = false; 
        options.ForwardWindowsAuthentication = false; 
       }); 

     services.AddSingleton(this.Configuration); 
     services.AddIdentityServer(); 
    } 

     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
    { 
      app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = "Cookies" }); 
     JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); 

     // get values from config 
     IConfigurationSection clientSettings = this.Configuration.GetSection("AppSettings:ClientSettings"); 
     string[] scopes = clientSettings["Scope"].Split(' '); 
     var oidcOptions = new OpenIdConnectOptions 
          { 
           AuthenticationScheme = clientSettings["AuthenticationScheme"], 
           SignInScheme = clientSettings["SignInScheme"], 
           Authority = clientSettings["Authority"], 
           ClaimsIssuer = clientSettings["ClaimsIssuer"], 
           RequireHttpsMetadata = 
            clientSettings.GetValue<bool>("RequireHttpsMetadata"), 
           ClientId = clientSettings["ClientId"], 
           ClientSecret = clientSettings["ClientSecret"], 
           ResponseType = clientSettings["ResponseType"], 
           GetClaimsFromUserInfoEndpoint = clientSettings.GetValue<bool>("GetClaimsFromUserInfoEndpoint"), 
           SaveTokens = clientSettings.GetValue<bool>("SaveTokens") 
          }; 
     foreach (var scope in scopes) 
     { 
      oidcOptions.Scope.Add(scope); 
     } 

     app.UseOpenIdConnectAuthentication(oidcOptions); 

     app.UseStaticFiles(); 

     app.UseMvcWithDefaultRoute(); 
} 

これは、他のユーザーに代替ソリューションを提供するための答えとしてマークする前に、しばらくお待ちください。

関連する問題