[英]Asp.Net Core - Custom Authorization and Identity from another server?
[英]Identity Server 3 Authentication/Authorization, with ASP.NET CORE 1.0
我目前正在研究基於ASP.NET Core 1.0(連接到Identity Server 3)的RESTful項目。我在Startup.cs的ConfigureServices方法中為所有控制器設置了全局[Authorize]過濾器。
現在,我嘗試在CORE 1.0項目的Startup.cs中針對我的Identity Server 3從AJAX請求驗證我的Bearer令牌,從而授權我的控制器資源。
與(經典)ASP.NET 4.5相比,ASP.NET CORE 1.0似乎發生了很大變化。
你有一些想法如何實現這一目標? 如何在ASP.NET Core 1.0中驗證我的令牌?
非常感謝!
更新
在Asp.net 4.5中,我可以使用app.UseIdentityServerBearerTokenAuthentication (新的IdentityServerBearerTokenAuthenticationOptions(){...}),但是在ASP.NET Core 1.0中不存在。
相反,我嘗試使用以下內容:
var connectOptions = new OpenIdConnectOptions
{
Authority = Configuration["IdentityServerSettings:CoreUrl"],
ClientId = Configuration["IdentityServerSettings:ClientId"],
ClientSecret = Configuration["IdentityServerSettings:ClientSecret"],
PostLogoutRedirectUri = Configuration["IdentityServerSettings:PostLogoutRedirectUri"],
ResponseType = OpenIdConnectResponseType.Code
};
app.UseOpenIdConnectAuthentication(connectOptions);
不幸的是,我得到的只是一個HTTP 302 ...
我認為您要的是要使用Bearer Token Authentication中間件。
您要查找的軟件包是"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0"
可以使用IdentityServer4.AccessTokenValidation解決此問題:)
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions()
{
ScopeName = Configuration["IdentityServerSettings:ApiScopes"],
Authority = Configuration["IdentityServerSettings:CoreUrl"]
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.