dcblogdev / laravel-microsoft-graph

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

Request for Calendar API Integration #56

Closed alekbless closed 2 months ago

alekbless commented 1 year ago

Would you be open to integrating the Calendar part of the Microsoft Graph API into your package? If needed, i'm willing to contribute and submit pull requests to help implement this feature.

Please let me know your thoughts. Thank you.

Specifically: https://learn.microsoft.com/en-us/graph/api/calendar-list-events?view=graph-rest-1.0&tabs=http

dcblogdev commented 1 year ago

Hi yes, I have this in the admin side, I've just noticed its missing from my docs, I will need to add that.

Happy to receive your PR.

I'm in the middle of working on version 4 which solves some problems of the inner workings of the MsGraph class. I'm hoping to have this released in the next day or 2.

Needs to be a version bump as I will be removing a try catch from a method which means the user land code can catch errors.

I've so far tested this from a login as a user using Graph only, I will need to test using it with existing users too.

Having said that it won't affect resource classes.

alekbless commented 1 year ago

Ah, cool! Just saw that the methods where added on the AdminResource.

I will try to add it to the Resource for users and see how it goes. Looking forward to your next version as well.

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);
    }
}

I managed to keep the public API the same so no need for a v4 release.