longthanhtran/yii2-oauth2-resource-server

OAuth 2.0 资源服务器

1.0.0 2021-09-19 05:50 UTC

This package is auto-updated.

Last update: 2024-09-19 12:00:05 UTC


README

介绍。

该包是使用 League 的 OAuth2 Server 包实现的资源服务器功能的包装器。它接收带有 access_token 的 bearer 令牌,并在接受请求之前将其与定义的 OAuth2 授权服务器进行验证。

当前支持的与 OAuth2 授权服务器通信的授权类型是 client_credentials

设置。

参数。

  • @app/config/params.php 文件中准备一对 clientIdclientSecret。授权服务器 URL 也包含其详细信息。
...
  'resourceServer' => [
    'authzServerUrl' => 'your-oauth-authz-server-url',
    'publicKey'      => 'your-public-key-path'
  ],
  'clientCredentials' => [
    'clientId'     => 'your-client-id',
    'clientSecret' => 'your-client-secret',
  ]
...

OAuthRequester 组件

  • @app/config/web.php 中,放置 OAuthRequest 的组件定义
...
  'oauthRequester' => [
    'class' => 'longthanhtran\oauth2\filters\OAuthRequester'
  ]
...

用法

从您的 (rest) 控制器,在 behaviors 函数中附加 RequestValidator,例如

public function behaviors()
{
  $behaviors = parent::behaviors();

  $behaviors['authenticator'] = [
    'class' => 'longthanhtran\oauth2\filters\RequestValidator'
  ];

  return $behaviors;
}