我已經做執行以下操作(使用cookie認證)類似的東西:
1 - 設置cookie域爲所有網站
我Startup.Auth.cs
看起來像這樣的頂級域名:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => {
var identity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
//some additional claims and stuff specific to my needs
return Task.FromResult(identity);
})
},
CookieDomain = ".example.com"
});
2 - 更新所有的網站的web.config中使用相同的<machineKey />
礦看起來像這樣:
<machineKey
decryption="Auto"
decryptionKey="my_key"
validation="HMACSHA512"
validationKey="my_other_key" />
現在我可以,比如說,account.example.com
進行登錄操作,並且將用戶重定向到site1.example.com
和認證,他們將可以看到。
由於api是無狀態的,它不會查找cookie,對嗎?據我所知,它只查找認證頭。這將如何工作的API?我打算將API保存在我的MVC項目中,因此api將位於example.com/api,這也會起作用嗎? – CularBytes 2015-08-26 09:55:52
因此,您可以使用承載令牌代替。關鍵是機器密鑰在機器上是相同的,否則令牌不能被解密。 – 2015-08-26 10:49:45