首页 技术 正文
技术 2022年11月13日
0 收藏 345 点赞 3,982 浏览 2003 个字

我是使用 Laravel 5.4 + Dingo Api + passport/jwt 两个验证方式

目前需要用到 passport 的 client_credentials

获取 token成功之后,如果需要验证 token的有效,需要在

  1. app\Http\Kernel.php$routeMiddleware 中 添加一个
//客户端证书发放令牌验证中间件
'client_credentials' => \App\Http\Middleware\CheckClientCredentials::class,

如:

protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
'jwt.refresh' => \Tymon\JWTAuth\Middleware\RefreshToken::class,
'jwt.generalize.auth' => \App\Http\Middleware\GeneralizeAuth::class,
'cors' => \Barryvdh\Cors\HandleCors::class,
//客户端证书发放令牌验证中间件
'client_credentials' => \Laravel\Passport\Http\Middleware\CheckClientCredentials::class,
];
  1. 然后在路由中需要验证的中间件数组中,添加 client_credentials 就可以了。

如:

<?php
use Illuminate\Http\Request;
$api = app('Dingo\Api\Routing\Router');$api->version('v1', function ($api){
$api->group([
"prefix"=>"test",
'middleware' => [
'client_credentials', //client_credentials 类型验证的中间件
'cors'
],
'namespace' => 'App\Api\Test\Controllers',
], function ($api) { $api->get('test','TestController@test');
});});

Laravel Passport Key path oauth-public.key does not exist or is not readable

You do not mention your installation steps. Presume you did the following:

composer require laravel/passport

Register the service provider inside config/app.php

Laravel\Passport\PassportServiceProvider::class,

Run the migrations

php artisan migrate

only run passport migrate

php artisan migrate --path=vendor/laravel/passport/database/migrations

Lastly generate the keys using

php artisan passport:install

Reference Laravel Passport Key path oauth-public.key does not exist or is not readable


参考:

  1. [ Laravel 5.4 文档 ] 安全 —— API认证(Passport)
  2. Laravel 的 API 认证系统 Passport
  3. Grant Type client_credentials Authentication fails 处理好client_credentials的验证问题
  4. API Authentication (Passport) 原来官网文档已经有如何验证部分的案例啦
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894