Skip to content

Instantly share code, notes, and snippets.

@b1ff
Created April 23, 2014 09:39
Show Gist options
  • Save b1ff/11208819 to your computer and use it in GitHub Desktop.
Save b1ff/11208819 to your computer and use it in GitHub Desktop.
[AllowAnonymous]
public class AuthenticationController: ApiController
{
private readonly IFormsAuthWrapper _formsAuth;
public AuthenticationController(IFormsAuthWrapper formsAuth)
{
_formsAuth = formsAuth;
}
public HttpResponseMessage Token([FromBody]TokenRequest tokenRequest)
{
if (tokenRequest == null)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot parse input parameters");
}
if (Membership.ValidateUser(tokenRequest.Username, tokenRequest.Password))
{
return Request.CreateResponse(HttpStatusCode.Created, new TokenResult
{
Success = true,
Token = _formsAuth.GetAuthToken(tokenRequest.Username, tokenRequest.Persist)
});
}
return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Wrong username or password");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment