0
我正在用WebApi身份驗證的Thinklecture庫實現Web api中的身份驗證。它工作正常的accessToken在URL中使用下面的代碼:在web api中使用cookie進行身份驗證2
var config = new AuthenticationConfiguration();
// for testing
config.RequireSsl = false;
// security by user token
var handler = new SimpleSecurityTokenHandler("my access key", token =>
{
if (ObfuscatingComparer.IsEqual(token, "accesskey123"))
{
return new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{
new Claim("customerid", "123")
}, "Custom"));
}
return null;
});
config.AddAccessKey(handler, AuthenticationOptions.ForQueryString("userToken"));
這裏,AuthenticationConfiguration是Thinklecture庫的一部分。
什麼我不工作是當試圖使用cookie進行身份驗證與下面的代碼。我已經在提琴手中驗證過cookie正確發送。
var handler2 = new SimpleSecurityTokenHandler("my access key", token =>
{
if (ObfuscatingComparer.IsEqual(token, "accesskey123"))
{
return new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{
new Claim("customerid", "123")
}, "Custom"));
}
return null;
});
config.AddAccessKey(handler2, AuthenticationOptions.ForCookie("company.userToken"));
我使用這個庫錯了嗎?