hskrasek / laravel-zero-oauth
轻松将OAuth2身份验证添加到您的Laravel Zero应用程序中。
v0.0.3
2024-06-29 19:27 UTC
Requires
- php: ^8.3
- crell/fp: ^1.0
- crell/serde: ^1.1
- laravel-zero/framework: ^11
- league/oauth2-client: ^2.7
Requires (Dev)
- illuminate/http: ^11
- laravel/pint: ^1.13
- pestphp/pest: ^2.33
- phpstan/phpstan: ^1.10
Suggests
- illuminate/http: Laravel provides an HTTP client that can be used to make requests to your resource server.
This package is auto-updated.
Last update: 2024-09-29 20:04:25 UTC
README
简介
Laravel Zero OAuth 是一个旨在将OAuth 2.0身份验证添加到您的 Laravel Zero 应用程序的库,利用 The PHP League的OAuth 2.0客户端 库。
Laravel Zero 由 Nuno Nuno Maduro 和 Owen Voke 创建,是一个微框架,为您的控制台应用程序提供了一个优雅的起点。它是Laravel的定制版本,优化了构建命令行应用程序。
安装
- 要开始,请使用composer安装它
composer require hskrasek/laravel-zero-oauth
- 然后,将
LaravelZeroOAuthProvider
添加到您的config/app.php
文件中
'providers' => [
App\Providers\AppServiceProvider::class,
++ HSkrasek\LaravelZeroOAuth\LaravelZeroOAuthProvider::class,
],
使用方法
要开始,您需要配置您的OAuth提供程序。此软件包支持所有由 The PHP League的OAuth 2.0客户端 支持的提供程序,您可以在 此处 找到提供程序及其配置选项的列表。您可以通过在 .env
文件中配置提供程序来实现这一点。
OAUTH2_CLIENT_ID=<CLIENT_ID> OAUTH2_CLIENT_SECRET=<CLIENT_SECRET> OAUTH2_SCOPES=<SCOPES> OAUTH2_AUTHORIZE_URI=<AUTHORIZE_URI> OAUTH2_TOKEN_URI=<TOKEN_URI> # Your redirect URI needs to match your applications OAuth configuration. It is recommended to use the default value, but you can change it if necessary. # The package will attempt to correctly start a server for you using PHP's built in server. # OAUTH2_REDIRECT_URI="http://127.0.0.1:8000" # By default the package will use the GenericProvider, but you can change it to any provider supported by The PHP League's OAuth 2.0 Client. # OAUTH2_PROVIDER=League\OAuth2\Client\Provider\GenericProvider::class
配置您的提供程序后,您可以使用 oauth:login
命令开始OAuth流程
php your-app-name oauth:login
在您通过提供程序进行身份验证后,您将能够使用 Keyring
类访问请求令牌
use HSkrasek\LaravelZeroOAuth\Auth\Keyring; // ... public function handle(Keyring $keyring) { $token = $keyring->get('access_token'); // Use the token to make requests to your provider. Http::withToken($token->accessToken)->get('https://api.example.com'); }
鸣谢
许可证
Laravel Zero OAuth 是开源软件,根据 MIT许可证 许可。