betalabs / passport-social-grant
Laravel Passport的社会授权
v4.3.0
2021-07-20 14:09 UTC
Requires
- php: ^7.2|^8.0
- laravel/passport: ^8.0|^9.0|^10.0
Requires (Dev)
- phpunit/phpunit: ^8.5|^9.0
This package is auto-updated.
Last update: 2024-09-20 21:22:48 UTC
README
此包为您的Oauth2服务器添加了社会授权。
安装
您可以通过composer安装此包
composer require adaojunior/passport-social-grant
该包将自动注册其服务提供者。或者,您可以在您的config/app.php
文件中手动添加服务提供者
'providers' => [ // ... Adaojunior\PassportSocialGrant\SocialGrantServiceProvider::class, ];
设置
- 实现
SocialGrantUserProvider
接口
<?php namespace App\SocialGrant; use Laravel\Socialite\Facades\Socialite; use Illuminate\Contracts\Auth\Authenticatable; use League\OAuth2\Server\Entities\ClientEntityInterface; use Adaojunior\PassportSocialGrant\SocialGrantUserProvider; class UserProvider implements SocialGrantUserProvider { /** * Retrieve a user by provider and access token. * * @param string $provider * @param string $accessToken * @param ClientEntityInterface $client * @return Authenticatable|null */ public function getUserByAccessToken(string $provider, string $accessToken, ClientEntityInterface $client):? Authenticatable { } }
- 将
SocialGrantUserProvider
接口绑定到您的实现上,在您的应用程序服务提供者的register
方法中,文件路径为app/Providers/AppServiceProvider.php
$this->app->bind( Adaojunior\PassportSocialGrant\SocialGrantUserProvider::class, App\SocialGrant\UserProvider::class );
用法
$response = $http->post('http://your.app/oauth/token', [ 'form_params' => [ 'grant_type' => 'social', 'client_id' => $clientId, 'client_secret' => $clientSecret, 'provider' => $providerName, // name of provider (e.g., 'facebook', 'google' etc.) 'access_token' => $providerAccessToken, // access token issued by specified provider ], ]);