dcblogdev / laravel-microsoft-graph

Laravel package for Microsoft Graph API (Microsoft365)
https://dcblog.dev/docs/laravel-microsoft-graph
Other
120 stars 51 forks source link

Identity provider exception #55

Closed Edvinaz closed 1 year ago

Edvinaz commented 1 year ago

Hi, I had service to upload/download files to oneDrive, everything worked fine, but this week i noticed (i dont really know when it started), but msgraph:keep-alive command throws error:

League\OAuth2\Client\Provider\Exception\IdentityProviderException 

  invalid_grant

  at /home/service/fservice/vendor/league/oauth2-client/src/Provider/GenericProvider.php:222
    218▕             $code  = $this->responseCode && !empty($data[$this->responseCode])? $data[$this->responseCode] : 0;
    219▕             if (!is_int($code)) {
    220▕                 $code = intval($code);
    221▕             }
  ➜ 222▕             throw new IdentityProviderException($error, $code, $data);
    223▕         }
    224▕     }
    225▕ 
    226▕     /**

      +18 vendor frames 
  19  /home/service/fservice/artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

maybe someone have idea why this happend? Nothing changed, tokens valid.

dcblogdev commented 1 year ago

Yes, I'm working on a fix for this, it will be ready shortly. Part of a bigger re-write.

dcblogdev commented 1 year ago

I've just released https://github.com/dcblogdev/laravel-microsoft-graph/releases/tag/v3.2.0. the only changes required are updating the listener to the following if you're using the provided listener.

<?php

namespace App\Listeners;

use App\Models\User;
use Dcblogdev\MsGraph\MsGraph;
use Illuminate\Support\Facades\Auth;

class NewMicrosoft365SignInListener
{
    public function handle($event)
    {
        $user  = User::firstOrCreate([
            'email' => $event->token['info']['mail'],
        ], [
            'name'     => $event->token['info']['displayName'],
            'email'    => $event->token['info']['mail'] ?? $event->token['info']['userPrincipalName'],
            'password' => '',
        ]);

        (new MsGraph())->storeToken(
            $event->token['accessToken'],
            $event->token['refreshToken'],
            $event->token['expires'],
            $user->id,
            $user->email
        );

        Auth::login($user);
    }
}

Also updated the docs to make them more clear.