dayanstef/microsoft-graph

Microsoft Graph OAuth2 Provider for Laravel Socialite

dev-master 2020-12-11 13:26 UTC

This package is auto-updated.

Last update: 2021-10-11 15:33:16 UTC


README

composer require dayanstef/microsoft-graph

Installation & Basic Usage

Add configuration to config/services.php

'graph' => [    
  'tenant' => env('MICROSOFT_TENANT_ID'),
  'client_id' => env('MICROSOFT_CLIENT_ID'),  
  'client_secret' => env('MICROSOFT_CLIENT_SECRET'),  
  'redirect' => env('MICROSOFT_REDIRECT_URI') 
],

Add provider event listener

Configure the package's listener to listen for SocialiteWasCalled events.

Add the event to your listen[] array in app/Providers/EventServiceProvider.

use SocialiteProviders\Manager\SocialiteWasCalled;

protected $listen = [
    SocialiteWasCalled::class => [
        'SocialiteProviders\\Graph\\GraphExtendSocialite@handle',
    ],
];

Usage

Socialite::driver('graph')->stateless()->redirect();

// OR
// Some Applications require specific tenant definition
Socialite::driver('graph')->setTenantId('MICROSOFT_TENANT_ID')->stateless()->redirect();

// Get a user basic details
$user = Socialite::driver('graph')->setTenantId('MICROSOFT_TENANT_ID')->stateless()->user();

// Get user groups
$userGroups = Socialite::driver('graph')->getUserGroupsByToken($user, $user->token);