加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Laravel Passport通过访问令牌获取客户端ID

发布时间:2020-12-14 19:46:21 所属栏目:大数据 来源:网络整理
导读:我正在写一个小sms网关,供几个项目使用, 我实施了laravel护照认证(client credentials grant token) 然后我将CheckClientCredentials添加到api中间件组: protected $middlewareGroups = [ 'web' = [ ... ],'api' = [ 'throttle:60,1','bindings',LaravelP
我正在写一个小sms网关,供几个项目使用,

我实施了laravel护照认证(client credentials grant token)

然后我将CheckClientCredentials添加到api中间件组:

protected $middlewareGroups = [
    'web' => [
       ...
    ],'api' => [
        'throttle:60,1','bindings',LaravelPassportHttpMiddlewareCheckClientCredentials::class
    ],];

逻辑工作正常,现在在我的控制器中我需要让客户端与有效令牌相关联.

routes.php文件

Route::post('/sms',function(Request $request) {
    // save the sms along with the client id and send it

    $client_id = ''; // get the client id somehow

    sendSms($request->text,$request->to,$client_id);
});

出于明显的安全原因,我永远不能使用消费者请求发送客户端ID,例如$client_id = $request-> client_id;.

有一种棘手的方法.
您可以在中间件CheckClientCredentials中修改句柄方法,只需添加此行即可.
$request["oauth_client_id"] = $psr->getAttribute('oauth_client_id');

然后你可以在controller的函数中得到client_id:

public function info(IlluminateHttpRequest $request)
{
    var_dump($request->oauth_client_id);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读