身份服务器4保护api在同一个项目上

时间:2016-10-29 19:11:31

标签: identityserver4

我们使用IdentityServer作为我们的Web应用程序和API资源的openid提供程序。 我想在身份服务器上公开一个安全的api端点来编辑用户,不知怎的,我无法让配置工作。我的客户端是有角度的,我有一个有效的不记名令牌。

app.UseCors("AllowSpecificOrigin");
app.UseIdentity();
app.UseIdentityServer();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
   AuthenticationScheme = "Cookies"
});

JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
   {
      Authority = Configuration["AuthServerUrl"],
      ScopeName = "api",
      AutomaticAuthenticate = true,
      AutomaticChallenge = true,
      RequireHttpsMetadata = false
   });

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以使用MapWhen进行分支,如下所示:

         app.MapWhen(x => x.Request.Path.StartsWithSegments("/custom"), builder =>
         {
             builder.UseCookieAuthentication(new CookieAuthenticationOptions
             {
                AuthenticationScheme = "Cookies"
             });

             JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

             builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
             {
                 Authority = Configuration["AuthServerUrl"],
                 ScopeName = "api",
                 AutomaticAuthenticate = true,
                 AutomaticChallenge = true,
                 RequireHttpsMetadata = false
            });
            // .....
         });
         app.UseIdentity();
         app.UseIdentityServer();
         //...