I am calling a service, and I need to pass the user's permanent security token with every request I make.
In order to do that, I've added this method to my base controller class:
protected UserData getUsr()
{
try
{
UserData usr = new UserData();
usr.SecurityToken = Session["secToken"].ToString();
MembershipUser mvcUser = Membership.GetUser(HttpContext.User.Identity.Name);
usr.Id = (int)mvcUser.ProviderUserKey;
return usr;
}
catch (Exception ex)
{
log.Debug("Could not create usr object", ex);
throw new Exception("Could not authenticate");
}
}
This issue here is that sometimes the User.Identity data out-lasts the session data, causing weird bugs to happen with the user seeing they are logged in but then their requests failing.
Is there a better way to store this token/can I store it in such a way that it will expire whenever the User.Identity object expires?
Also, if anyone knows of some good basic understanding examples/documentation for HttpContext and MVC authorize filters that would be great.