n30 / socialite-amazon
Laravel Socialite 用于使用 Amazon/AWS 账户进行登录。集成了 Social Stream 的 Social 提供程序扩展。
Requires
- php: ^7.2||^8.0
- ext-json: *
- laravel/socialite: *
This package is auto-updated.
Last update: 2024-09-29 06:15:01 UTC
README
需求
- PHP >= 7.2
(以下之一,按优先顺序以便于即插即用...):
如果您想将 Amazon 登录集成到 Laravel,并且不确定选择哪个需求,那么如果您使用的是 JetStream,我们建议使用 Social Stream。否则使用 Breeze 或自定义应用程序时,请使用 Social Providers。
安装 Socialite Providers & 基本用法(包:SocialiteProviders/Providers)
请参阅基本安装指南,然后按照以下特定提供程序的说明进行操作。
不使用额外包的安装(无 Social Stream/Social Providers)
在完成以下安装的其余部分后,请参阅下面的“Socialite Standalone 使用方法”。
安装
composer require n30/socialiteproviders-amazon
该包为熟练的 Socialite 开发者提供灵活性,希望使用自己的自定义方法,不需要额外包。如果您不确定,请确保运行以下命令,否则包将无法工作,并按照说明会导致错误,所以...
接下来运行
composer require socialiteproviders/manager
将配置添加到 config/services.php
'amazon' => [
'client_id' => env('AMAZON_CLIENT_ID'),
'client_secret' => env('AMAZON_CLIENT_SECRET'),
'redirect' => env('AMAZON_REDIRECT_URI'), //recommended: /oauth/amazon/callback
],
启用 Socialite 包作为 SocialiteProviders 添加提供程序事件监听器
配置包的监听器以监听 SocialiteWasCalled 事件。
将事件添加到 app/Providers/EventServiceProvider 中的 listen[] 数组中。有关详细说明,请参阅基本安装指南。
protected $listen = [ \SocialiteProviders\Manager\SocialiteWasCalled::class => [ // ... other providers \SocialiteProviders\Amazon\AmazonExtendSocialite::class.'@handle', ], ];
.env
AMAZON_CLIENT_ID=amzn1.application-oa2-client.xxxxxxxxxxxxxxxxxxxx
AMAZON_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx
AMAZON_REDIRECT_URI="${APP_URL}/oauth/amazon/callback"
启用 Social Stream
如果使用 Social Stream,请编辑您的 config/socialstream.php 文件以添加
'providers' => [
Providers::google(),
Providers::facebook(),
Providers::twitter(),
Providers::linkedin(),
'amazon' //<--Add Amazon at the end of your list of providers
],
Socialite Standalone 使用方法
如果您使用 Social Stream 或 Socialite Providers 基础包,可以跳过此部分。
routes/web.php
Route::get('/', 'AmazonController@index');
Route::get('callback', 'AmazonController@callback');
在所需位置创建控制器,例如
php artisan make:controll AmazonController
AmazonController
namespace App\Http\Controllers; use Illuminate\Http\Request; use Laravel\Socialite\Facades\Socialite; class AmazonController extends Controller { public function index() { return Socialite::driver('amazon')->redirect(); } public function callback() { $user = Socialite::driver('amazon')->user(); dd($user); } }
Amazon API 密钥
最后,您还需要一个 Amazon API 密钥
Amazon 登录文档 解释了创建安全配置文件以及启用 Amazon 登录的所有细节。
在此处创建 API 密钥 here
用法
社交流使用方法
有关更多设计集成,请参阅基于您的 Livewire 或 Intertia 实现的 Social Stream 的官方文档Socialite Providers。socialstream.blade.php 按钮的示例可能是
<a href="{{ route('oauth.redirect', ['provider' => 'amazon' ]) }}">
{{-- Place your Amazon SVG Icon here... I recommend Blade-ui-icons backage for easy icons: @svg('jam-amazon', "h-6 w-6") --}}
<span class="sr-only">Amazon</span>
</a>
Socialite Standalone & Socialite Provider
现在您应该能够像常规使用 Socialite 一样使用提供程序(假设您已安装 facade)
return Socialite::driver('amazon')->redirect();
返回的用户字段
nameemailuser_id
请参阅亚马逊文档以获取详细信息。
许可协议
MIT版权(c) 2023 n30