Hi friends,
I try laravel API authendicate token so i add a middleware method and check api verification to make request . It correctly working in localhost but
My issue: It not properly work in live server.
show 'Unauthorized' in live server api response
i also checked manually code in server (local and server is same code)
My code
Middleware Method
public function handle($request, Closure $next)
{
if ($request->header('APP_KEY') == env('APP_KEY'))
return $next($request);
else
return response()->json('Unauthorized', 401);
}
API Route
Route::get('/showfaq','faq\faqController@getfaqList')->middleware('API_verification');
Frontend API Call
$http({
url:'./api/faq/showfaq',
method: 'get',
headers: {'APP_KEY': 'XXXXX'},
}).then(function (response){
$scope.faq = response.data;
},function(error){
consloe.log("soming wrog")
});
Make sure that in your config/auth you have this:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
Then your API routes should be protected like this:
Route::group(['prefix' => 'v1', 'middleware' => ['auth:api'], function () {
});
Now from here:
[https://laravel.com/docs/5.8/authentication](http://)
Path Customization
When a user is successfully authenticated, they will be redirected to the /home URI. You can customize the post-authentication redirect location by defining a redirectTo property on the LoginController, RegisterController, ResetPasswordController, and VerificationController:
protected $redirectTo = '/'; Next, you should modify the RedirectIfAuthenticated middleware's handle method to use your new URI when redirecting the user.
If the redirect path needs custom generation logic you may define a redirectTo method instead of a redirectTo property:
protected function redirectTo() { return '/path'; }
Hope this helps,
Ben
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community