waglpz/google-sso

使用Google实现单点登录。最小化实现。

v2.0.1 2023-06-07 08:01 UTC

This package is auto-updated.

Last update: 2024-09-07 10:36:07 UTC


README

Google SSO客户端库使您能够通过Google API进行单点登录。

要求

PHP 8.2或更高版本

安装

composer require waglpz/google-sso:"^1.0"

使用OAuth进行身份验证

  1. 按照说明 创建网络应用程序凭据
  2. 将JSON凭证下载到某个隐藏目录,并在配置中包含此路径。
  3. 使用配置authConfig设置这些凭据的路径。
  4. 使用配置键scopes设置您将要调用的API所需的权限范围。
  5. 在配置中设置您应用程序的重定向URI。
  6. 设置重定向到Google时预期的提示。可以是noneconsentselect_account
  7. 在处理重定向URI的脚本中,用授权代码交换访问令牌
示例
  $config = include __DIR__ . '/../config/sso.php';
  $googleSSO = new \GoogleSSO\GoogleSSO($config);
  $authorizationCodeUrl = $googleSSO->createAuthUrl();
  // Go to the $authorizationCodeUrl and select account you will authenticate against.
  // these will redirect you to defined/known redirect URI and a PHP script will use the code which sends back from Google.
  $accountData = $googleSSO->fetchAccountDataUsingAuthorizationCode($_GET['code']);
  // $accountData contains necessary information if one was founded by google

代码质量和测试

要检查编码风格违规,请运行

composer waglpz:code:style:check

要自动修复(可修复的)编码风格违规,请运行

composer waglpz:code:style:fix

要检查静态类型违规,请运行

waglpz:code:analyse

要检查回归,请运行

composer waglpz:test:norma

要一次性检查所有违规,请运行

composer waglpz:check:normal