适用于 Laravel Socialite 的 Dropbox OAuth2 提供者

4.2.1 2020-12-01 23:10 UTC

This package is auto-updated.

Last update: 2024-08-26 21:29:35 UTC


README

composer require socialiteproviders/dropbox

安装与基本使用

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

将配置添加到 config/services.php

'dropbox' => [    
  'client_id' => env('DROPBOX_CLIENT_ID'),  
  'client_secret' => env('DROPBOX_CLIENT_SECRET'),  
  'redirect' => env('DROPBOX_REDIRECT_URI') 
],

添加提供者事件监听器

Laravel 11+

在 Laravel 11 中,默认的 EventServiceProvider 提供者已被移除。相反,您可以在您的 AppServiceProviderboot 方法中使用 Event 门面上的 listen 方法添加监听器。

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

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

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

用法

现在您应该可以使用提供者,就像您通常会使用 Socialite 一样(假设您已安装了门面)

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

返回的用户字段

  • id
  • name
  • email
  • avatar