Skip to content

Commit 96be9c0

Browse files
authored
Added Microsoft Graph to Extended Install
Added the Microsoft Graph SDK and then using the access token, created a graph request to get user details that can contain a multitude of different pieces of data.
1 parent 11b37ed commit 96be9c0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ The out-of-the-box implementation let's you login users. However, let's say we
4646
namespace App\Http\Middleware;
4747

4848
use RootInc\LaravelAzureMiddleware\Azure as Azure;
49+
use Microsoft\Graph\Graph;
50+
use Microsoft\Graph\Model;
4951

5052
use Auth;
5153

@@ -55,11 +57,18 @@ class AppAzure extends Azure
5557
{
5658
protected function success($request, $access_token, $refresh_token, $profile)
5759
{
58-
$email = strtolower($profile->unique_name);
60+
$graph = new Graph();
61+
$graph->setAccessToken($access_token);
62+
63+
$graph_user = $graph->createRequest("GET", "/me")
64+
->setReturnType(Model\User::class)
65+
execute();
66+
67+
$email = strtolower($graph_user->getUserPrincipalName());
5968

6069
$user = User::updateOrCreate(['email' => $email], [
61-
'firstName' => $profile->given_name,
62-
'lastName' => $profile->family_name,
70+
'firstName' => $graph_user->getGivenName(),
71+
'lastName' => $graph_user->getSurname(),
6372
]);
6473

6574
Auth::login($user, true);

0 commit comments

Comments
 (0)