waglpz / google-sso
使用Google实现单点登录。最小化实现。
v2.0.1
2023-06-07 08:01 UTC
Requires
- php: ^8.2
- ext-json: *
- google/apiclient: ^2.13
- waglpz/webapp: ^v2.0
- waglpz/webapp-security: ^v2.0
Requires (Dev)
- doctrine/coding-standard: ^11.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-doctrine: ^1.3
- phpstan/phpstan-phpunit: ^1.1
- phpstan/phpstan-strict-rules: ^1.5
- phpstan/phpstan-symfony: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.1
- phpunit/phpunit: ^10.0
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: ^3.7
- symfony/var-dumper: ^5.4
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进行身份验证
- 按照说明 创建网络应用程序凭据
- 将JSON凭证下载到某个隐藏目录,并在配置中包含此路径。
- 使用配置
authConfig
设置这些凭据的路径。 - 使用配置键
scopes
设置您将要调用的API所需的权限范围。 - 在配置中设置您应用程序的重定向URI。
- 设置重定向到Google时预期的提示。可以是
none
、consent
或select_account
。 - 在处理重定向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