Skip to content

Commit

Permalink
add code challenge params
Browse files Browse the repository at this point in the history
  • Loading branch information
ousid committed Nov 12, 2024
1 parent e129c9d commit c7c2dc1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/MsGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ class MsGraph
{
public function contacts(): Contacts
{
return new Contacts();
return new Contacts;
}

public function emails(): Emails
{
return new Emails();
return new Emails;
}

public function files(): Files
{
return new Files();
return new Files;
}

public function sites(): Sites
{
return new Sites();
return new Sites;
}

public function tasklists(): TaskLists
{
return new TaskLists();
return new TaskLists;
}

public function tasks(): Tasks
{
return new Tasks();
return new Tasks;
}

protected static string $baseUrl = 'https://graph.microsoft.com/v1.0/';
Expand Down Expand Up @@ -83,7 +83,7 @@ public static function setUserModel(string $model): static
{
self::$userModel = $model;

return new static();
return new static;
}

/**
Expand Down Expand Up @@ -111,7 +111,15 @@ public function connect(?string $id = null): Redirector|RedirectResponse
}

if (! request()->has('code') && ! $this->isConnected($id)) {
return redirect($provider->getAuthorizationUrl());
$codeVerifier = bin2hex(random_bytes(32));
$codeChallenge = rtrim(
strtr(base64_encode(hash('sha256', $codeVerifier, true)), '+/', '-_'), '='
);

return redirect($provider->getAuthorizationUrl([
'code_challenge' => $codeChallenge,
'code_challenge_method' => 'S256',
]));
}

if (request()->has('code')) {
Expand Down

0 comments on commit c7c2dc1

Please sign in to comment.