Skip to content

Commit c7c2dc1

Browse files
committed
add code challenge params
1 parent e129c9d commit c7c2dc1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/MsGraph.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ class MsGraph
2828
{
2929
public function contacts(): Contacts
3030
{
31-
return new Contacts();
31+
return new Contacts;
3232
}
3333

3434
public function emails(): Emails
3535
{
36-
return new Emails();
36+
return new Emails;
3737
}
3838

3939
public function files(): Files
4040
{
41-
return new Files();
41+
return new Files;
4242
}
4343

4444
public function sites(): Sites
4545
{
46-
return new Sites();
46+
return new Sites;
4747
}
4848

4949
public function tasklists(): TaskLists
5050
{
51-
return new TaskLists();
51+
return new TaskLists;
5252
}
5353

5454
public function tasks(): Tasks
5555
{
56-
return new Tasks();
56+
return new Tasks;
5757
}
5858

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

86-
return new static();
86+
return new static;
8787
}
8888

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

113113
if (! request()->has('code') && ! $this->isConnected($id)) {
114-
return redirect($provider->getAuthorizationUrl());
114+
$codeVerifier = bin2hex(random_bytes(32));
115+
$codeChallenge = rtrim(
116+
strtr(base64_encode(hash('sha256', $codeVerifier, true)), '+/', '-_'), '='
117+
);
118+
119+
return redirect($provider->getAuthorizationUrl([
120+
'code_challenge' => $codeChallenge,
121+
'code_challenge_method' => 'S256',
122+
]));
115123
}
116124

117125
if (request()->has('code')) {

0 commit comments

Comments
 (0)