doulu3399 2014-12-20 18:31
浏览 186

Laravel过滤器除了内部API请求

I'm using the HMVC package to consume my own API. However it also includes some POST requests which require authenticaton. Obviously I can't just dump in my password in the request nor do I find ENV variables an elegant solution.

Is there a way to check inside the basic auth filter whether the request is made internally?

The filter is applied to the controller, not the route

  • 写回答

1条回答 默认 最新

  • dtjbcda841554 2014-12-22 01:30
    关注

    First option

    You could add the exception test on the filter, so that you only apply the filter rule if the request is not from localhost.

    Second option

    You would apply the filter on the Route, so that you wouldn't have problems accessing the controller locally.

    Route::get('profile', array('before' => 'auth', function()
    {
        // Only authenticated users may enter...
    }));
    

    Source: http://laravel.com/docs/4.2/security#protecting-routes

    Third option

    It doesn't seem an elegant solution either, but a workaroung would be to look if the request comes from localhost, you could manually authenticate the user.

    $user = User::find(1);
    Auth::login($user);
    

    Source: http://laravel.com/docs/4.2/security#manually

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度