I am using the new webapi.
Now I do not know if I am doing this correctly, but I am trying to configure the api to return the authentication cookie to the HttpResponseMessages header to use it in another mvc application.
I am using FormsAuthenticationTicket as I think I need to use e.g.
public HttpResponseMessage Get(LoginModel model)
{
if (model.UserName == "bob")
{
var msg = new HttpResponseMessage(HttpStatusCode.OK);
var expires = DateTime.Now.AddMinutes(30);
var auth = new FormsAuthenticationTicket(1, model.UserName, DateTime.Now, expires,
model.RememberMe,"password",
FormsAuthentication.FormsCookiePath);
var cookie = new HttpCookie("user");
cookie.Value = FormsAuthentication.Encrypt(auth);
cookie.Domain = "localhost";
cookie.Expires = expires;
msg.Headers.Add("result",cookie.Value);
return msg;
}
return new HttpResponseMessage(HttpStatusCode.Forbidden);
}
now in my mvc application login controller I call the service and get the data value from the header set in the api controller.
string data = response.Headers["result"].ToString();
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(data);
Every time I try to run FormsAuthentication.Decrypt, I get an error all the time
Failed to verify data.
I assume that due to the fact that the api encrypts the data, it uses some kind of key that the site does not know about. I'm right?
Can anyone help?