Search code examples
angularlaravel-5jwtdingo-apiangular2-jwt

Call laravel backend api from angular 2


I am developing a website fronted in angular2 and an api in laravel with dingo. Now I want to get the data from this api in angular 2. But of course I want to protect the api so that for now only my angular frontend is allowed to get a response from the api.

I searched a lot but can not figure out the best way. Most results in searching use jwt or auth, but with an angular2 application where user have to login. In my case no login is required to go to pages with data from the api.

I would appreciate any suggestions or links to interesting tutorials or other questions on this topic.


Solution

  • If I've understood what you want to achieve, you should just implement a Cross Origin Resource Sharing middleware in Laravel. You can even use the Barryvdh's Laravel CORS package for a quicker approach. JWT is useless in your case as it's just a token auth system that provides your ReST API the capability to authorise users to perform an action that requires an authentication.

    Useful links: Implementing secure CORS APIs