English 中文(简体)
Laravel Socialite and Office365: Invalid ArgumentException in Manager. php项目 90:没有支持的司机[软]
原标题:Laravel Socialite and Office365: InvalidArgumentException in Manager.php line 90: Driver [microsoft] not supported

So I definitely can t wrap my head around this one. I m following a Laravel 5.2 tutorial here.

并且将上述错误列入标题。 我的路线就是这样:

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 AppHttpControllers;

use IlluminateHttpRequest;

use AppHttpRequests;
use AppHttpControllersController;
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()
      {

      }
}

服务。 网址是:

<?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  => AppUser::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 ),
    ],

];

除此以外,我对我可能错失之处没有想法。 Light!

问题回答

我建议使用Microsoftgraph提供者,来自

微软-Graph提供商通过composer.json 文档进行包装:

"require": {
    ...

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

页: 1

其次,在<代码>config/services.php上添加联系证书:

...

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

* 说明:如果承诺config/services.php至一份公共文件,将这些数值摘至您的.env文档,并通过env helpermeth查阅;

In config/app.php add the SocialiteProviders/Generators service provider to the providers array:

 providers  => [
    ...

    /*
    * Package Service Providers...
    */
    LaravelSocialiteSocialiteServiceProvider::class,

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

登记Socialize facade(也载于config/app.php):

 aliases  => [
    ...

     Socialize  =>  LaravelSocialiteFacadesSocialite ,

],

Register an event listener in app/Providers/EventServiceProvider.php:

protected $listen = [
    ...

     SocialiteProvidersManagerSocialiteWasCalled  => [
         SocialiteProvidersGraphGraphExtendSocialite@handle 
    ],
];

3. 创建你的控制员,处理各项要求:

<?php

namespace AppHttpControllersAuth;

use IlluminateHttpRequest;
use Socialize;

class AuthController extends AppHttpControllersController
{

    /**
     * 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 ,  AuthAuthController@redirectToProvider );
Route::get( auth/graph/callback , AuthAuthController@handleProviderCallback );

If anyone still arrives here with the same error, but using the SocialiteProviders Microsoft provider already:
Check if you have set up the library correctly.

  1. Make sure to install socialiteproviders/microsoft from composer
  2. Add the SocialiteProviders Manager to your config/providers.php: SocialiteProvidersManagerServiceProvider::class
  3. Add the event listener to your app/Providers/EventServiceProvider.php:
    SocialiteProvidersManagerSocialiteWasCalled::class => [
        [SocialiteProvidersMicrosoftMicrosoftExtendSocialite::class,  handle ],
    ],
    

最后一步是重要的,给我造成错误的原因何在,因为我不理解事件听取者的需要(而不仅仅是扩大提供者的一种选择方式)。

So this might seem obvious but both in my case and judging from the info provided in the question, this step is also missing. I changed from the current Microsoft to the Graph and still got the same error, however I then realized this error happens when the Driver is not registered in the service provider. Make sure you are using the same spelling of the service provider in vendor and that you include the Service provider, in my case:

    <?php
    
    namespace AppProviders;
    
    use IlluminateAuthEventsRegistered;
    use IlluminateAuthListenersSendEmailVerificationNotification;
    use IlluminateFoundationSupportProvidersEventServiceProvider as ServiceProvider;
    use IlluminateSupportFacadesEvent;
    
    class EventServiceProvider extends ServiceProvider
    {
        /**
         * The event to listener mappings for the application.
         *
         * @var array<class-string, array<int, class-string>>
         */
        protected $listen = [
            Registered::class => [
                SendEmailVerificationNotification::class,
            ],
    
            SocialiteProvidersManagerSocialiteWasCalled::class => [
                // ... other providers
/*--- I forgot this --->*/SocialiteProvidersGraphGraphExtendSocialite::class. @handle ,
            ],
    
        ];
    
        /**
         * Register any events for your application.
         *
         * @return void
         */
        public function boot()
        {
            //
        }
    
        /**
         * Determine if events and listeners should be automatically discovered.
         *
         * @return bool
         */
        public function shouldDiscoverEvents()
        {
            return false;
        }
    }

添加了缩微胶片,司机:https://github.com/Socialiteproviders/Microsoft-Graph

I never got to try with the listed driver "Microsoft" on socialiteproviders.com and as of the time of this writing Graph was removed from that website, however all I care is that it works and it worked as expected!

Sometimes compiled events and codes cause the problem. Clear Laravel cache and try again:

php artisan clear-compiled
php artisan event:clear
php artisan route:clear
php artisan optimize:clear




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签