【问题标题】:identity server 4 securing api on the same project身份服务器 4 在同一项目上保护 api
【发布时间】:2017-03-12 09:14:36
【问题描述】:

我们使用 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
   });

我们将不胜感激。

【问题讨论】:

    标签: identityserver4


    【解决方案1】:

    您可以使用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();
             //...
    

    【讨论】:

    • 这是一个好习惯吗?对我来说似乎更像是一项工作。因为我必须为自己的项目指定权限。
    • 您必须映射路径才能拥有此功能,否则管道开始相互覆盖。最佳做法是将它们放在完全独立的项目中。
    • @adem caglin,你是如何自动获得授权 URL 的?
    猜你喜欢
    • 2021-10-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 2020-11-17
    • 1970-01-01
    • 2019-01-06
    相关资源
    最近更新 更多