dplsnw7329 2015-09-28 01:27
浏览 60

AWS授权问题中的Angular应用程序

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://example.com/api/me 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!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料