定制 designmynight/laravel-oauth-introspect-middleware 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

designmynight/laravel-oauth-introspect-middleware

最新稳定版本:v4.0.1

Composer 安装命令:

composer require designmynight/laravel-oauth-introspect-middleware

包简介

Laravel package for letting a resource owner verify OAuth2 access tokens with a remote authorization server

README 文档

README

Especially for a microservices architecture, authentication and authorization functions should be delegated. Protecting resources is best done by implementing the web services as a pure OAuth2 resource server, relying on token verification on a remote authorization server.

Laravel Middleware for OAuth 2.0 Token Introspection

Laravel Passport provides a full OAuth2 server implementation, yet misses optional OAuth2 functionalties as defined in OAuth 2.0 Token Introspection (RFC7662).

The Introspection endpoint is provided by ipunkt/laravel-oauth-introspection. This package provides the middleware required for verifying an access token against a remote Introspection endpoint.

Note: To prevent token scanning attacks, the endpoint MUST also require some form of authorization to access this endpoint. The provided middleware assumes the introspection endpoint requires an OAuth2 Bearer token retrieved using a client credentials grant. Therefore, you MUST provide a valid client id and client secret.

Installation

Install the package on your resource server

composer require designmynight/laravel-oauth-introspect-middleware

and add the Service Provider in your config/app.php

'providers' => [
     // [..]
    \DesignMyNight\Laravel\OAuth2\IntrospectMiddlewareServiceProvider::class
     // [..]
];

and add the MiddleWare in your App/Http/Kernel.php

protected $routeMiddleware = [
    // [..]
    'verifyaccesstoken' => \DesignMyNight\Laravel\OAuth2\VerifyAccessToken::class,
    // [..]   
];

publish the configuration

php artisan vendor:publish

Finally in your .env file, define the following properties

# Url of the authorization server
AUTHORIZATION_SERVER_URL="https://authorization.server.dom"
# Client Identifier as defined in https://tools.ietf.org/html/rfc6749#section-2.2
AUTHORIZATION_SERVER_CLIENT_ID="123"
# The client secret
AUTHORIZATION_SERVER_CLIENT_SECRET="abcdefg"
# Endpoint for requesting the access token
AUTHORIZATION_SERVER_TOKEN_URL="${AUTHORIZATION_SERVER_URL}/oauth/token"
# The OAuth2 Introspection endpoint https://tools.ietf.org/html/rfc7662
AUTHORIZATION_SERVER_INTROSPECT_URL="${AUTHORIZATION_SERVER_URL}/oauth/introspect"

# Optional configuration for requesting an OAuth2 access tokens using the implicit grant flow 
AUTHORIZATION_SERVER_AUTHORIZATION_URL="${AUTHORIZATION_SERVER_URL}/oauth/authorize"
AUTHORIZATION_SERVER_REDIRECT_URL=https://my.machine.dom

Now, use the middleware.

Route::group(['middleware'=>'verifyaccesstoken:required-scope1,required-scope2'], function () {
	Route::get('/endpoint1', 'UserController@index');
	Route::resource('/resource', 'OrderController');
});

统计信息

  • 总下载量: 43.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-01-29