![](/img/trans.png)
[英]Shared authentication based on Identity Server 4 between MVC and SPA applications
[英]Identity Shared between Applications - Identity Framework C#.NET
我有2個應用程序,一個MVC 5主站點(A)和一個Web Api 2從屬端點(B)托管在訪問1個數據庫的兩台不同計算機上。
這些應用程序應基於表單身份驗證共享身份驗證和授權。 在(A)上通過身份驗證后,推薦的實現方式是:
我嘗試使用身份驗證Cookie,如下所示:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieName = "DefaultCookie",
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/auth/login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
validateInterval:TimeSpan.FromMinutes(20),
regenerateIdentity: (manager,user) => user.GenerateUserIdentityAsync(manager))
}
});
但是我還沒有完全成功。
您可以自己動手,但IdentityServer4可以執行此類操作。 粗放1)MVC認證; 2)MVC獲取ID令牌; 3)將請求傳遞給具有ID令牌的Web API; 4)Web API檢查令牌是否有效並獲得聲明; 5)如果用戶被授權,請執行操作; 6)只要令牌有效,重復3-5。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.