dimanche 27 septembre 2015

Angular app in AWS authorization issue

I have an app build on angularjs with laravel php serve as backend. The api request for login using facebook works on my workstation, but when I push to aws, the console log me an error:

http://ift.tt/1OBwg7k 401 (Unauthorized)

The json returned as:

message: "Please make sure your request has an Authorization header"

But there is Authorization in request header.

enter image description here

Checklist: - Database in config has been changed to RDS - Facebook site url has been changed to aws domain

The error come from Authenticate.php from laravel

<?php
namespace App\Http\Middleware;
use JWT;
use Config;
use Closure;
use Illuminate\Contracts\Auth\Guard;

class Authenticate
{

    protected $auth;


    public function __construct(Guard $auth)
    {
        $this->auth = $auth;
    }


    public function handle($request, Closure $next, $role)
    {


        if ($request->header('Authorization'))
        {
            $token = explode(' ', $request->header('Authorization'))[1];
            $payload = (array) JWT::decode($token, Config::get('app.token_secret'), array('HS256'));

            if ($payload['exp'] < time())
            {
                return response()->json(['message' => 'Token has expired']);
            }

            $request['user'] = $payload;

            return $next($request);
        }
        else
        {
            return response()->json(['message' => 'Please make sure your request has an Authorization header'], 401);
        }
    }
}

Thanks!!




Aucun commentaire:

Enregistrer un commentaire