Reputation: 1153
I am building an application using Laravel and Angular. I have defined the following route
Route::group(array('prefix' => 'api'), function() {
Route::resource('getdealsbymerchant/{merchant_id}', 'dealsController@getdealsbymerchant',
array('only' => array('index')));
});
I have this route working. When I hit it I get a JSON response.
I have also been able to make API call in Angular to read the data and displayed it.
In my app.js I have defined
var app = angular.module('deals', [])
.constant('API_URL', 'http://www.coupon.local/api/getdealsbymerchant/');
I am aware that I can protect routes by adding
'middleware' => 'auth',
to the route.
My question is how do I authenticate my Angular application to make sure that only the angular application has access to the API and not everyone else.
Do I pass username and password in the app.js or is there a better way of doing it? Also since app.js is in public folder, wouldn't everyone be able to see the username password I am passing?
Please help. Thanks.
Upvotes: 1
Views: 708
Reputation: 85
Storing any user or password , keys etc.. in angular is a bad idea because it makes it visible for the user.. The best way I know is to make a middle layer ... so instead of calling this endpoint : http://www.coupon.local/api/getdealsbymerchant/
angular should call : http://www.coupon.local/getdealsbymerchant which internally will do the call to the api and has all the private things in server side
Upvotes: 1