Search code examples
angularlaravel-5json-web-token

JSW tokens serverside (laravel) and/or clientside (angular 2)?


I found some good resources about JSW (JSON Web Tokens). I am working with Angular 2 rc1 and Laravel 5 and found some good resources:

  1. https://github.com/auth0/angular2-jwt
  2. https://www.toptal.com/web/cookie-free-authentication-with-json-web-tokens-an-example-in-laravel-and-angularjs
  3. https://auth0.com/blog/2015/05/14/creating-your-first-real-world-angular-2-app-from-authentication-to-calling-an-api-and-everything-in-between/

Do I need the implementation of JSW on clientside (Angular 2) AND serverside (Laravel)? What if someone types the url in the addressbar in the browser...


Solution

  • Angular 2 requests JWT (Json Web Tokens) on login; Laravel generates it and you save it on the client-side (Angular 2) using localStorage. Then on each API call that needs Authentication, you send the JWT and validate it using Laravel (Middlewares are useful). Hope it helps Happy Coding :)