upwebdesign / infusionsoft-socialite
为Laravel Socialite提供的Infusionsoft OAuth2 Provider
v1.0.1
2022-02-05 04:42 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- illuminate/support: ^6.0|^7.0|^8.0|^9.0
- laravel/socialite: ^5.0|6.0
README
安装与基本使用
composer require upwebdesign/infusionsoft-socialite
将配置添加到config/services.php
'infusionsoft' => [ 'client_id' => env('INFUSIONSOFT_CLIENT_ID'), 'client_secret' => env('INFUSIONSOFT_CLIENT_SECRET'), 'redirect' => env('INFUSIONSOFT_REDIRECT_URI', '/auth/infusionsoft/callback'), 'auth' => env('INFUSIONSOFT_AUTH_URI', '/auth/infusionsoft/redirect'), ],
重定向URI是一个本地URL,它将生成发送到Infusionsoft以通过OAuth连接所需的信息。回调URI是用户在成功认证后将被返回的地方。
更新你的.env
当然,重定向和回调都是可选的。
INFUSIONSOFT_CLIENT_ID= INFUSIONSOFT_CLIENT_SECRET= INFUSIONSOFT_REDIRECT_URI= INFUSIONSOFT_CALLBACK_URI=
事件
用户认证后,将触发InfusionsoftSoclialiteAuthenticated
事件。你可以监听此事件以在你的账户中创建新用户。请确保导入InfusionsoftSoclialiteAuthenticated
类。
protected $listen = [ Registered::class => [SendEmailVerificationNotification::class], InfusionsoftSocialiteAuthenticated::class =>[ // Place your listener here... ] ];
此事件将返回一个带有以下键的Socialite User对象。由于Infusionsoft不使用这些字段与OAuth,因此Id和nickname始终为null。
Laravel\Socialite\Two\User {#319 ▼
+token: "********"
+refreshToken: "********"
+expiresIn: 86399
+approvedScopes: array:1 [▶]
+id: null
+nickname: null
+name: "Jane Doe"
+email: "jane@example.com"
+avatar: "https://cdn.com/avatar.jpg"
+user: array:14 [▼
"name" => "Jane Doe"
"email" => "jane@example.com"
"website" => "https://google.com/"
"phone" => null
"address" => array:9 [▶]
"phone_ext" => null
"time_zone" => "America/New_York"
"logo_url" => "https://cdn.com/avatar.jpg"
"currency_code" => "USD"
"language_tag" => "en-US"
"business_type" => null
"business_goals" => []
"business_primary_color" => null
"business_secondary_color" => null
]
}
替代用法
你也可以像通常使用Socialite一样使用此提供者(假设你已经安装了外观)
要启动OAuth流程,请调用重定向方法以请求授权代码。
return Socialite::driver('infusionsoft')->redirect();
使用授权代码检索令牌以执行你想要的任何操作。
$token = Socialite::driver('infusionsoft')->getToken();
获取Infusionsoft连接的账户数据。
$user return Socialite::driver('infusionsoft')->user();