thathoff/kirby-oauth

Kirby OAuth 2 插件

安装次数: 13,420

依赖项: 0

推荐者: 0

安全: 0

星标: 32

关注者: 4

分支: 11

开放性问题: 6

类型:kirby-plugin

3.1.0 2024-05-22 13:44 UTC

This package is auto-updated.

Last update: 2024-09-22 14:41:37 UTC


README

Screnshot of Kirby’s Login Screen with OAuth

此插件是一个插件,用于为 OAuth 2.0 支持Kirby的仪表板认证。它使用 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 提供商登录,不会创建新用户。