AngularJS + Laravel 5 Authentication

前端 未结 2 1430
南方客
南方客 2021-02-06 03:44

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

2条回答
  •  有刺的猬
    2021-02-06 04:18

    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. 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).

    So the steps are:

    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=... )

提交回复
热议问题