【问题标题】:Laravel Socialite and Office365: InvalidArgumentException in Manager.php line 90: Driver [microsoft] not supportedLaravel Socialite 和 Office365:Manager.php 第 90 行中的 InvalidArgumentException:不支持驱动程序 [microsoft]
【发布时间】:2016-06-20 18:39:59
【问题描述】:

所以我绝对不能围绕这个问题。我在这里学习 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'),
    ],

];

除此之外,我不知道我可能会出错。照亮我的路!

【问题讨论】:

  • 您正在尝试使用 Microsoft。但错误显示“不支持驱动程序 [microsoft]”。同样根据 Socialite 文档,Socialite 目前支持使用 Facebook、Twitter、LinkedIn、Google、GitHub 和 Bitbucket 进行身份验证。
  • 那么如何创建自定义驱动程序以支持微软?

标签: php laravel driver office365


【解决方案1】:

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

通过您的 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 提交到公共 repo,请将这些值提取到您的 .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');

【讨论】:

  • 非常感谢。这是有史以来最有帮助的
【解决方案2】:

如果有人仍然带着同样的错误到达这里,但已经使用SocialiteProviders Microsoft provider
检查您是否已正确设置库。

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

最后一步很重要,是什么导致了我的错误,因为我不明白事件监听器是必需的(而不仅仅是扩展提供程序的可选方式)。

【讨论】:

    猜你喜欢
    • 2016-01-27
    • 2016-02-13
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多