mardi 29 septembre 2015

AWS Laravel DecryptException

I just upload a fresh unmodified copy of script that using laravel and angularjs to AWS beanstalk, but it encounter DecryptException error message when ever i tried to login using an api call to server:

enter image description here

But it works fine on my workstation. These are some of the functions I use to create a user token.

protected function createToken($user)
    {
        $payload = [
            'sub' => $user->id,
            'iat' => time(),
            'exp' => time() + (2 * 7 * 24 * 60 * 60)
        ];
        return JWT::encode($payload, Config::get('app.token_secret'));
    }

Authenticate.php

public function handle($request, Closure $next)
    {
        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