froxlorgmbh / sso
PHP froxlor GmbH SSO 客户端 for Laravel 10+
dev-main
2023-06-15 20:47 UTC
Requires
- php: ^8.0
- ext-json: *
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^7.0
- illuminate/console: ^10.0
- illuminate/support: ^10.0
- socialiteproviders/manager: ^4.0.1
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.31
- phpunit/phpunit: ^9.0
This package is not auto-updated.
Last update: 2024-09-20 23:23:54 UTC
README
PHP froxlor GmbH SSO API 客户端 for Laravel 10+
目录
安装
composer require froxlorgmbh/sso
如果你使用Laravel 10+,你已经完成了,否则请继续。
将服务提供者添加到你的app.php
配置文件中
FroxlorGmbH\SSO\Providers\SSOServiceProvider::class,
事件监听器
- 在
app/Providers/EventServiceProvider
中的listen[]
数组中添加SocialiteProviders\Manager\SocialiteWasCalled
事件。 - 将你的监听器(即来自提供者的那些)添加到刚刚创建的
SocialiteProviders\Manager\SocialiteWasCalled[]
中。 - 为该提供者添加的监听器是
'FroxlorGmbH\\SSO\\Socialite\\SSOExtendSocialite@handle',
。 - 注意:除非你用自己的提供者覆盖它们,否则不需要为内置的socialite提供者添加任何内容。
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
'FroxlorGmbH\\SSO\\Socialite\\SSOExtendSocialite@handle',
],
];
配置
将配置复制到配置文件夹
$ php artisan vendor:publish --provider="FroxlorGmbH\SSO\Providers\SSOServiceProvider"
将环境变量添加到你的.env
SSO_KEY=
SSO_SECRET=
SSO_REDIRECT_URI=https://
你需要向服务配置文件中添加一个条目,以便在生产环境中使用缓存后的配置文件(Laravel命令artisan config:cache
)后,所有配置仍然可用。
添加到config/services.php
'sso' => [ 'client_id' => env('SSO_KEY'), 'client_secret' => env('SSO_SECRET'), 'redirect' => env('SSO_REDIRECT_URI') ],
示例
基本
$sso = new FroxlorGmbH\SSO\SSO(); $sso->setClientId('abc123'); // Get SSH Key by User ID $result = $sso->getSshKeysByUserId(38); // Check, if the query was successfull if ( ! $result->success()) { die('Ooops: ' . $result->error()); } // Shift result to get single key data $sshKey = $result->shift(); echo $sshKey->name;
设置器
$sso = new FroxlorGmbH\SSO\SSO(); $sso->setClientId('abc123'); $sso->setClientSecret('abc456'); $sso->setToken('abcdef123456'); $sso = $sso->withClientId('abc123'); $sso = $sso->withClientSecret('abc123'); $sso = $sso->withToken('abcdef123456');
OAuth令牌
$sso = new FroxlorGmbH\SSO\SSO(); $sso->setClientId('abc123'); $sso->setToken('abcdef123456'); $result = $sso->getAuthedUser(); $user = $userResult->shift();
$sso->setToken('uvwxyz456789'); $result = $sso->getAuthedUser();
$result = $sso->withToken('uvwxyz456789')->getAuthedUser();
外观
use FroxlorGmbH\SSO\Facades\SSO; SSO::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser();
文档
Oauth
public function retrievingToken(string $grantType, array $attributes)
支付意图
public function getPaymentIntent(string $id) public function createPaymentIntent(array $parameters)
SSH密钥
public function getSshKeysByUserId(int $id) public function createSshKey(string $publicKey, string $name = NULL) public function deleteSshKey(int $id)
用户
public function getAuthedUser() public function createUser(array $parameters)
开发
运行测试
composer test
BASE_URL=xxxx CLIENT_ID=xxxx CLIENT_KEY=yyyy CLIENT_ACCESS_TOKEN=zzzz composer test
生成文档
composer docs