blankogmbh / kirby-oauth

此包已被废弃且不再维护。作者建议使用 thathoff/kirby-oauth 包。

Kirby OAuth 2 插件

安装次数: 3,524

依赖: 0

建议: 0

安全: 0

星星: 28

关注者: 4

分支: 10

公开问题: 4

类型:kirby-plugin

3.1.0 2024-05-22 13:44 UTC

This package is auto-updated.

Last update: 2024-05-22 13:46:54 UTC


README

Screnshot of Kirby’s Login Screen with OAuth

此插件是一个插件,用于为 OAuth 2.0Kirby 中的面板认证提供支持。它使用 PHP League的OAuth 2 Client,因此支持所有 官方第三方 提供商。甚至可以 实现自己的 提供商。

Kirby 兼容性

  • 对于 Kirby 4,请使用 3.0.0 或更高版本
  • 对于 Kirby 3.6 - 3.9,请使用 2 或更高版本
  • 对于 Kirby 3.0 - 3.6,请使用版本 1(不再维护)

使用Composer安装

由于提供者存在二级依赖,目前仅支持通过Composer安装

安装插件

composer require thathoff/kirby-oauth

安装提供者

该插件使用 PHP League的OAuth 2 Client,因此您可以从所有 官方第三方 提供商中选择。还可以通过使用 GenericProvider实现自己的 提供商来使用自己的提供者。

例如,要安装对Google的支持,请运行

composer require league/oauth2-google

选项

通用选项

以下配置选项可用。并且可以添加到Kirby的 config.php

return [
  //... other config options

  'thathoff' => [
      'oauth' => [
        // Add your providers configuration here
        'providers' => [
          // for details see „Provider Options” below
        ],

        // Only allow logins for existing kirby users (don’t create new users)
        'onlyExistingUsers' => false,

         // Set the default role of newly created users.
        'defaultRole' => 'admin',

        // Allow every valid user of all OAuth providers to login.
        // For details see “Configure Allowed Users” below.
        // DANGEROUS: Make sure you know what you’re doing when setting this to true!
        'allowEveryone' => false,

        // List of E-mail domains which are allowed to login
        'domainWhitelist' => [
          // For details see “Configure Allowed Users” below.
        ],

        // List of E-mail addresses which are allowed to login
        'emailWhitelist' => [
          // For details see “Configure Allowed Users” below.
        ],

        // Remove the standard Kirby login form and only display OAuth options.
        'onlyOauth' => false,
      ],
  ],
];

提供者选项

thathoff.oauth.providers 数组是所有配置的OAuth提供者的列表,每个条目都有一个唯一的键。每个数组条目用作新OAauth提供者类实例的配置选项,因此为所选OAuth提供者类的所有选项都可用。

此外,还支持 nameclass 两个属性,以提供登录屏幕的显示名称以及在不使用 GenericProvider 的情况下要使用的提供者类。

//...
'providers' => [
  'google' => [
    'class' => "League\OAuth2\Client\Provider\Google", // use special google class from league/oauth2-google
    'clientId' => 'somerandomstring.apps.googleusercontent.com',
    'clientSecret' => 'clientsecret',
    'icon'         => 'users'  // Pick any default Kirby icon for the login button (optional)
  ],
  'custom' => [
    // this one uses \League\OAuth2\Client\Provider\GenericProvider automatically
    'name'                    => 'My Custom Provider' // The name is optional
    'clientId'                => 'demoapp',    // The client ID assigned to you by the provider
    'clientSecret'            => 'demopass',   // The client password assigned to you by the provider
    'redirectUri'             => 'https://example.com/your-redirect-url/',
    'urlAuthorize'            => 'https://example.com/oauth2/lockdin/authorize',
    'urlAccessToken'          => 'https://example.com/oauth2/lockdin/token',
    'urlResourceOwnerDetails' => 'https://example.com/oauth2/lockdin/resource',
    'icon'                    => 'users'  // Pick any default Kirby icon for the login button (optional)
  ],

重定向URL

OAuth提供者要求您在配置应用程序时提供 重定向URL。请使用 https://example.com/oauth/login/PROVIDER_ID,其中example.com是您的域名,PROVIDER_ID是config.php中配置选项的键(在前面的配置示例中为 googlecustom)。如果您在子目录中安装了Kirby,请记住在URL中包含子目录。

配置允许的用户

默认情况下,只有白名单用户才能登录到Kirby面板。

域名白名单:通过将域名添加到域名白名单(domainWhitelist),允许所有具有在一个域名下验证电子邮件地址的账户。

邮箱白名单:通过将电子邮件地址添加到邮箱白名单(emailWhitelist),所有拥有已验证电子邮件地址且与白名单中条目匹配的账户将被允许。

允许所有人:allowEveryone设置为true,所有已认证的账户都能登录。请谨慎使用此选项!你可能希望将默认用户角色更改为比默认的admin更受限的角色。

默认角色:新创建的用户首次登录时将获得由defaultRole定义的角色。默认为admin。请注意,如果用户已经创建,则角色不会更新。如果你想通过在Kirby面板中更改角色来手动将用户列入白名单,可以将此角色设置为nobody

仅现有用户:onlyExistingUsers设置为true,只有已创建的用户才能使用OAuth提供商登录,不会创建新用户。