Я пытаюсь использовать Owin без идентификации. В моем знаке в процессе я добавляю претензий вроде так:Owin Контекст в модели или репозитории ASP MVC
[HttpPost]
[AllowAnonymous]
public ActionResult Login(Domain.Model.User.User model, string returnUrl)
{
var response = someFunctionCall();
AuthData data = response.authdata;
IEnumerable<Claim> claim = new List<Claim>(){
new Claim(ClaimTypes.CookiePath, MvcApplication.ApplicationPath),
new Claim(ClaimTypes.Name, model.UserId),
new Claim(Constants.ClaimsConstants.1customClaim, data.1customClaim),
new Claim(Constants.ClaimsConstants.2customClaim, data.2customClaim)
};
ClaimsIdentity id = new ClaimsIdentity(claim, CookieAuthenticationDefaults.AuthenticationType);
HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = true }, id);
return RedirectToAction("Index", "Home");
}
В моем классе запуска я устанавливаю в моем OnResponseSigned в провайдера я устанавливаю Thread.CurrentPrinipal Context.OwinContext.Authentcation как IPrincipal. Нравится так:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
CookieSecure = CookieSecureOption.Always,
LoginPath = new PathString("/Account/Login"),
AuthenticationMode = AuthenticationMode.Active,
Provider = new CookieAuthenticationProvider
{
OnResponseSignedIn = (context =>
{
OnSignedInResponse(context);
})
)}
}
private void OnSignedInResponse(CookieResponseSignedInContext context)
{
Thread.CurrentPrincipal = context.OwinContext.Authentication as IPrincipal;
}
позже в приложении мне нужно получить доступ к претензиям, но я не могу этого сделать.
private static readonly ClaimsPrincipal user = Thread.CurrentPrincipal as ClaimsPrincipal;
private static readonly IEnumerable<Claim> claims = user.Claims;
public static CustomUserInfo Idenitiy
{
get
{
UserInfo user = new UserInfo()
{
Custom1 = claims.Where(c => c.Type == Constants.ClaimsConstants.1customClaim).First().Value,
Custom2 = claims.Where(c => c.Type == Constants.ClaimsConstants.2customClaim).First().Value
};
return user;
}
}
Не уверен, что я должен использовать контекст Owin или использовать контекст Thread.current. Когда я проверяю Thread.CurrentPrincipal, похоже, что это просто не в претензиях. Есть предположения?