2016-10-29 38 views
1

我們使用IdentityServer作爲我們的Web應用程序和API資源的openid提供程序。 我想在身份服務器上公開一個用於編輯用戶的安全api端點,不知何故,我無法配置工作。我的客戶是有角度的,我有一個有效的持票人令牌。身份服務器4在同一項目上保護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 
    }); 

任何幫助將不勝感激。

回答

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(); 
     //... 
+0

這是一個好的做法呢?看起來更像是一種對我的工作。因爲我必須爲自己的項目指定權限。 – aurimas

+2

您必須映射路徑才能擁有此功能,否則管道將開始互相覆蓋。最好的做法是讓他們完全分開的項目。 –

+0

@adem caglin,你是如何自動獲得授權URL的? – blgrnboy

相關問題