Laravel Socialite和Office365:Manager.php第90行中的InvalidArgumentException:不支持驱动程序[microsoft]

时间:2016-06-20 18:40:00

标签: php laravel driver office365

所以我绝对无法绕过这一个。我在这里遵循Laravel 5.2教程。

http://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-facebook-login.html#.V2gUIrgrJPY

并在标题中获得上面列出的错误。我的路线看起来像这样:

Route::get('/', function () {
    if(Auth::check()) return view('auth/register');
    return view('auth/login');
});

Route::get('/redirect', 'MailAuthController@redirect');
Route::get('/callback', 'MailAuthController@callback');

控制器看起来像这样:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Socialite;

class MailAuthController extends Controller
{
    //
    public function redirect()
      {
          return \Socialite::with('microsoft')->redirect();
      }

    public function callback()
      {
          // when microsoft calls with token
      }

    public function user()
      {

      }
}

而services.php看起来像这样:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Third Party Services
    |--------------------------------------------------------------------------
    |
    | This file is for storing the credentials for third party services such
    | as Stripe, Mailgun, Mandrill, and others. This file provides a sane
    | default location for this type of information, allowing packages
    | to have a conventional place to find your various credentials.
    |
    */

    'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],

    'mandrill' => [
        'secret' => env('MANDRILL_SECRET'),
    ],

    'ses' => [
        'key' => env('SES_KEY'),
        'secret' => env('SES_SECRET'),
        'region' => 'us-east-1',
    ],

    'sparkpost' => [
        'secret' => env('SPARKPOST_SECRET'),
    ],

    'stripe' => [
        'model' => App\User::class,
        'key' => env('STRIPE_KEY'),
        'secret' => env('STRIPE_SECRET'),
    ],

    'microsoft' => [
        'client_id' => env('MICROSOFT_CLIENT_ID'),
        'client_secret' => env('MICROSOFT_CLIENT_SECRET'),
        'redirect' => env('http://localhost:8000/callback'),
    ],

];

除此之外,我不知道哪里可能出错。点亮我的方式!

2 个答案:

答案 0 :(得分:3)

我建议您使用Microsoft Graph包中的Socialite Providers提供程序。

通过composer.json文件提取Microsoft-Graph提供程序:

"require": {
    ...

    "laravel/socialite": "^2.0",
    "socialiteproviders/microsoft-graph": "dev-master"
},

运行composer update

接下来,将连接凭据添加到config/services.php

...

'graph' => [
    'client_id'     => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxx',
    'redirect'      => 'https://my-app.dev',
],

*注意:如果将config/services.php提交到公共存储库,请将这些值提取到.env文件中并通过env helper method引用它们;

config/app.php中将SocialiteProviders/Generators服务提供商添加到providers数组中:

'providers' => [
    ...

    /*
    * Package Service Providers...
    */
    Laravel\Socialite\SocialiteServiceProvider::class,

    // This is a dependency of the socialiteproviders/microsoft-graph provider, and will be installed with the provider via it's composer.json file
    SocialiteProviders\Manager\ServiceProvider::class,

注册Socialize外观(也在config/app.php中):

'aliases' => [
    ...

    'Socialize' => 'Laravel\Socialite\Facades\Socialite',

],

app/Providers/EventServiceProvider.php注册一个事件监听器:

protected $listen = [
    ...

    'SocialiteProviders\Manager\SocialiteWasCalled' => [
        'SocialiteProviders\Graph\GraphExtendSocialite@handle'
    ],
];

创建控制器以处理请求:

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Socialize;

class AuthController extends \App\Http\Controllers\Controller
{

    /**
     * Redirect the user to the Graph authentication page.
     *
     * @return Response
     */
    public function redirectToProvider()
    {
        return Socialize::with('graph')->redirect();

    }

    /**
     * Obtain the user information from graph.
     *
     * @return Response
     */
    public function handleProviderCallback(Request $request)
    {
        $user = Socialize::with('graph')->user();

        // $user->token;
    }
}

最后在routes/web.php中添加您的路线:

<?php

Route::get('auth/graph', 'Auth\AuthController@redirectToProvider');
Route::get('auth/graph/callback','Auth\AuthController@handleProviderCallback');

答案 1 :(得分:0)

如果仍然有人出现相同错误但仍使用SocialiteProviders Microsoft provider到达这里,则:
检查是否正确设置了库。

  1. 确保从作曲家安装socialiteproviders/microsoft
  2. 将SocialiteProviders Manager添加到您的config/providers.php\SocialiteProviders\Manager\ServiceProvider::class
  3. 将事件监听器添加到您的app/Providers/EventServiceProvider.php中:
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        [SocialiteProviders\Microsoft\MicrosoftExtendSocialite::class, 'handle'],
    ],
    

最后一步很重要,这是导致我出错的原因,因为我不知道事件监听器是必需的(而不仅仅是扩展提供程序的可选方法)。