AngularJS + Laravel 5认证 [英] AngularJS + Laravel 5 Authentication

查看:191
本文介绍了AngularJS + Laravel 5认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在建设我的SPA与angularJS,我来到这里我要实现我的angularJS网站的用户身份验证点。但是,我不知道从哪里开始和什么是最好的做法。

While building my SPA with angularJS, i came to the point where i want to implement user authentication in my angularJS website. However, i have no idea where to start and what the best practices are.

基本上我有一个肯定可以有一个或多个角色。我找实例,所以我可以得到如何妥善处理这一个基本的了解,但到目前为止,我只跨都很简单或不那么安全的(像的this )。

Basically i have a sure that can have one or more roles. I've looked for examples so i could get a basic understanding of how to handle this properly, but so far i've only came across examples that are very simple or are not so secure (like this).

所以我的问题是,如何我使用REST(或自定义的API网址)来验证用户,然后显示使用angularJS页面上的用户信息,同时确保最佳的安全保障,通过使用实现身份验证服务(例如)从Laravel的CSRF令牌?

So my question is, how to I implement a authentication service using REST (or custom API urls) to authenticate a user, and then display the user information on the page using angularJS, while also ensuring best security coverage by using (for example) the csrf token from Laravel?

在此先感谢,
尼克·范德Meij

Thanks in advance, Nick van der Meij

推荐答案

我作出AngularJS应用和Laravel 5条提出了后端的API基于REST,而我的身份验证方法是:

I'm making an AngularJS app and an API RESTful made with Laravel 5 for the backend, and my approach for the authentication was:


  1. -auth的。基本上扩展了Laravel添加授权使用令牌验证模式。

  2. 添加简单的角色包laravel。我用 permiso 。有多个角色/用户和权限/角色。很简单的。

  3. 添加到jStorage前端。 (你可以使用AngularJS模块来代替)。

  1. Installed jwt-auth. Basically extends the Auth model of Laravel adding authorization with tokens.
  2. Added simple role package to laravel. I used permiso. Has multiple roles/user and permissions/role. Very simple.
  3. Added jStorage to frontend. (you can use AngularJS module instead).

因此​​,步骤是:


  1. 前端发送用户凭据(电子邮件和传递)。

  2. 服务器检查,智威汤逊-AUTH使得令牌给该用户,并发送备份。

  3. 前端保存在浏览器上存储的令牌(CSRF没有这种方法需要)。

  4. 要在所有的API调用旁边用提出的授权:承载头(或标记= ...

  1. Frontend send user credentials (email and pass).
  2. Server checks, jwt-auth makes a token to that user and send it backs.
  3. Frontend save the token on the browser storage (no csrf needed with this approach).
  4. All next calls to the API are made with Authorization: Bearer header (or with ?token=... )

这篇关于AngularJS + Laravel 5认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆