mfc / oauth2
TYPO3 CMS 的通用 OAuth2 身份验证和授权
Requires
- php: ^7.4 || ^8.1
- league/oauth2-client: ^2.6
- m4tthumphrey/php-gitlab-api: ^11.13.0
- omines/oauth2-gitlab: ^3.4
- php-http/guzzle7-adapter: ^1.0
- psr/http-factory: ^1.0
- typo3/cms-beuser: ^12.2 || ^13.0 || dev-main
- typo3/cms-core: ^12.2 || ^13.0 || dev-main
This package is auto-updated.
Last update: 2024-09-18 14:36:51 UTC
README
此扩展为 TYPO3 安装提供 OAuth 2.0 身份验证。
1. 功能
- 可以自动创建新的后端用户
- 某些 OAuth 资源服务器可以控制管理员权限并分配后端用户组成员资格
2. 使用方法
1) 安装
安装此扩展的唯一方法是通过 Composer。在你的基于 Composer 的 TYPO3 项目根目录下,只需运行 composer require mfc/oauth2
。
2) 配置扩展
为了添加用于登录的 OAuth2 服务器,我们建议你创建自己的小扩展,使用现有的站点包,或者将配置放入 typo3conf/AdditionalConfiguration.php
。
2.1) 使用此扩展中包含的 GitLab 提供者
配置 GitLab 登录提供者非常简单。只需将以下配置放入你的 ext_localconf.php
或上述 typo3conf/AdditionalConfiguration.php
,并根据需要自定义它。
Mfc\OAuth2\ResourceServer\Registry::addServer( 'gitlab', // identifier for the Resource Server 'Login with GitLab', // Text displayed on the Login Screen \Mfc\OAuth2\ResourceServer\GitLab::class, [ 'enabled' => true, // Enable/Disable the provider 'arguments' => [ 'appId' => 'your-app-id', 'appSecret' => 'your-app-secret', 'gitlabServer' => 'https://gitlab.com', // Your GitLab Server 'gitlabAdminUserLevel' => \Mfc\OAuth2\ResourceServer\GitLab::USER_LEVEL_DEVELOPER, // User level at which the user will be given admin permissions 'gitlabDefaultGroups' => '0', // Groups to assign to the User (comma separated list possible) 'gitlabUserOption' => 0, // UserConfig 'blockExternalUser' => false, // Blocks users with flag external from access the backend 'projectName' => 'your/repo', // the repository from which user information is fetched ], ] );
如果你使用的是托管版本的 GitLab,你可以通过访问 https://gitlab.com/profile/applications 或你自托管 GitLab 服务器上的等效页面来获取提供者的所需信息。
在 GitLab 中创建应用程序时,你可能需要以下信息
- 重定向 URI:
<your-domain-here>/typo3/index.php
- 作用域:
api
,read_user
,openid
2.2 创建自己的提供者
要创建自己的提供者,你需要创建自己的扩展,并创建一个扩展 Mfc\OAuth2\ResourceServer\AbstractResourceServer
的类。然后,你可以使用 2.1 中显示的相同样板代码来注册你新创建的提供者。提供者注册中包含的 arguments
数组将作为第一个参数传递给提供者的构造函数,并添加一个包含你设置标识符的 providerName
键。
示例
你已经创建了自己的扩展,并创建了类 Just\AnExample\Providers\ExampleProvider
。要注册你的提供者,你将扩展配置如下
Mfc\OAuth2\ResourceServer\Registry::addServer( 'example-provider', // identifier for the Resource Server 'Login with Example', // Text displayed on the Login Screen \Just\AnExample\Providers\ExampleProvider::class, [ 'enabled' => true, // Enable/Disable the provider 'arguments' => [ 'yourarg' => 'somevalue', // ... ], ] );
传递给你的提供者的第一个参数是
array( 'providerName' => 'example-provider', 'yourarg' => 'somevalue', // ... );
3. 许可证
mfc/oauth2 根据 GPL-2 许可证 发布。