Laravel Socialite 的 Unsplash OAuth2 提供者

4.1.0 2020-12-01 23:10 UTC

This package is auto-updated.

Last update: 2024-08-26 21:43:30 UTC


README

composer require socialiteproviders/unsplash

安装与基本使用

请参阅基本安装指南,然后按照以下特定提供者的说明操作。

config/services.php 中添加配置

'unsplash' => [    
  'client_id' => env('UNSPLASH_CLIENT_ID'),  
  'client_secret' => env('UNSPLASH_CLIENT_SECRET'),  
  'redirect' => env('UNSPLASH_REDIRECT_URI') 
],

添加提供者事件监听器

Laravel 11+

在 Laravel 11 中,默认的 EventServiceProvider 提供者已被移除。取而代之的是,在您的 AppServiceProviderboot 方法中使用 Event 门面的 listen 方法添加监听器。

  • 注意:除非您用自己的提供者覆盖了它们,否则不需要为内置的 Socialite 提供者添加任何内容。
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('unsplash', \SocialiteProviders\Unsplash\Provider::class);
});
Laravel 10 或以下配置包的监听器以监听 `SocialiteWasCalled` 事件。

app/Providers/EventServiceProvider 中的 listen[] 数组中添加该事件。有关详细说明,请参阅基本安装指南

protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \SocialiteProviders\Unsplash\UnsplashExtendSocialite::class.'@handle',
    ],
];

使用方法

现在您应该能够像常规使用 Socialite 一样使用该提供者(假设您已安装了门面)

return Socialite::driver('unsplash')->redirect();

返回的用户字段

  • id
  • 昵称
  • 名字
  • 电子邮件
  • 头像
  • 个人资料网址