如何使用$ .ajax()在laravel 5应用中登录 [英] How to get login in laravel 5 app using $.ajax()
问题描述
我有一个 laravel 5 应用.在应用程序中,登录功能是使用angularjs 开发的(通过$ http()请求电子邮件/密码).现在有另一个.net应用程序.我想让 .net用户请求(通过使用jquery ajax发送电子邮件/密码),以登录到我的系统.响应将为JSON.如果响应成功,则.net应用程序系统会将页面重定向到laravel 5应用程序.我已请求使用$ .ajax()登录.但是问题是laravel 5抛出 TokenMismatchException 错误.因此,我需要传递csrf令牌.但是我不知道如何将Anet请求中的csrf令牌从.net应用传递给laravel 5应用.如果有人知道解决方案,将不胜感激.而且,如果有.net替代laravel 5登录的任何其他标准方法,也将不胜感激.
I have a laravel 5 app. In the app, login functionality is developed with angularjs (requesting email/password with $http()). Now there is another .net app. I want to let .net user to request (by sending email/password using jquery ajax) to get logged in into my system. Response will be JSON. If response will be success, .net app system will redirect page into laravel 5 app. I have requested to login using $.ajax(). But problem is that laravel 5 throws TokenMismatchException error. So I need to pass csrf token. But I don't know that how I can pass csrf token in ajax request from .net app to laravel 5 app. If anyone knows the solution, it will be appreciated. And also if there is any alternative standard approach for .net to laravel 5 login, it will be also appreciated.
laravel 5-角度登录
$http({
method: 'POST',
url: LOGIN_CONTROLLER_URL,
data: {
st_email: 'some@email.com',
st_password: 'dowhateveryouwanttodo'
}
});
JQuery Ajax登录
$.ajax({
method: 'POST',
url: LOGIN_CONTROLLER_URL,
data: {
st_email: 'some@email.com',
st_password: 'dowhateveryouwanttodo'
}
});
推荐答案
我可以建议您 JWT (JSON Web令牌). CSRF令牌仅保护您免受攻击.要登录,请使用JWT
. Web上有许多可以在项目中使用的包/捆绑包.对于Laravel来说,最好的之一是:
I can suggest you the JWT (JSON Web Token). CSRF token only protects you from attacks. To login use JWT
. There are many packages/bundles on web that you can use in your project. For Laravel one of the best is:
这篇关于如何使用$ .ajax()在laravel 5应用中登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!