Hello,
I’ve got some problem with AuthenticationProvider and a jquery Ajax call…
I’ve got a javascrip that at login button click does
<script>
$(document).ready(function () {
var formObj = $(".login-form");
formObj.submit(function (event) {
event.preventDefault();
validator = formObj.validate();
if (validator.checkForm()) {
var formData = {
userName: $(“form input[name=username]”).val(),
password: $(“form input[name=password]”).val(),
remember: $(“input:checkbox[name=remember]:checked”).val() ? true : false
}
func = $.ajax({
url: “@Url.Content(”~/api/auth")",
data: formData,
type: “POST”,
}).done(function (data, textStatus, jqXHR) {
alert(jqXHR.status);
if (jqXHR.status == 200 && “success” == textStatus) {
@if(Request.Params.Get(“redirect”)!= null) {
<text>
window.location = “@Request.Params.Get(“redirect”)”;
</text>
}
else
{
<text>
window.location = ‘@Url.Content(System.Configuration.ConfigurationManager.AppSettings.Get(“tmrclient.login.landing”))’
</text>
}
}
else
{
console.log(‘error’);
}
});
}
});
});
</script>
and in my AuthProvider I do
public override object Authenticate(IServiceBase authService, IAuthSession session, Authenticate request)
{
[omiss]
throw HttpError.Unauthorized(ErrorMessages.InvalidUsernameOrPassword);
}
The problem I’ve is that Servicestack’s authentication responds me with the whole HTML content of the redirect action (I see a 302 in net tracing) but I expected a json response since the call was made in ajax…any suggestion on this?
Thanks
The correct url to POST to is /api/auth/credentials