Skip to content

Commit f547f1f

Browse files
committed
Merge branch 'main' of github.com:hypervel/components
2 parents c7e93b2 + a41d4b0 commit f547f1f

18 files changed

+58
-36
lines changed

src/router/src/UrlGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ protected function getRootUrl(string $scheme): string
442442
{
443443
$root = Context::getOrSet('__request.root.uri', function () {
444444
$requestUri = $this->getRequestUri()->toString();
445-
$root = preg_replace(';^(.+://.+?)((/|\?|#).*)?$;', '\1', $requestUri);
445+
$root = preg_replace(';^([^:]+://[^/?#]+).*$;', '\1', $requestUri);
446446

447447
return new Uri($root);
448448
});

src/socialite/src/Two/AbstractProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(
7474
/**
7575
* Get the authentication URL for the provider.
7676
*/
77-
abstract protected function getAuthUrl(string $state): string;
77+
abstract protected function getAuthUrl(?string $state): string;
7878

7979
/**
8080
* Get the token URL for the provider.
@@ -114,7 +114,7 @@ public function redirect(): ResponseInterface
114114
/**
115115
* Build the authentication URL for the provider from the given base URL.
116116
*/
117-
protected function buildAuthUrlFromBase(string $url, string $state): string
117+
protected function buildAuthUrlFromBase(string $url, ?string $state): string
118118
{
119119
return $url . '?' . http_build_query($this->getCodeFields($state), '', '&', $this->encodingType);
120120
}

src/socialite/src/Two/BitbucketProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BitbucketProvider extends AbstractProvider implements ProviderInterface
2020
*/
2121
protected string $scopeSeparator = ' ';
2222

23-
protected function getAuthUrl(string $state): string
23+
protected function getAuthUrl(?string $state): string
2424
{
2525
return $this->buildAuthUrlFromBase('https://bitbucket.org/site/oauth2/authorize', $state);
2626
}

src/socialite/src/Two/FacebookProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class FacebookProvider extends AbstractProvider implements ProviderInterface
4444
*/
4545
protected bool $reRequest = false;
4646

47-
protected function getAuthUrl(string $state): string
47+
protected function getAuthUrl(?string $state): string
4848
{
4949
return $this->buildAuthUrlFromBase('https://www.facebook.com/' . $this->getGraphVersion() . '/dialog/oauth', $state);
5050
}

src/socialite/src/Two/GithubProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class GithubProvider extends AbstractProvider implements ProviderInterface
1515
*/
1616
protected array $scopes = ['user:email'];
1717

18-
protected function getAuthUrl(string $state): string
18+
protected function getAuthUrl(?string $state): string
1919
{
2020
return $this->buildAuthUrlFromBase('https://github.com/login/oauth/authorize', $state);
2121
}

src/socialite/src/Two/GitlabProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function setHost(?string $host): static
3535
return $this;
3636
}
3737

38-
protected function getAuthUrl(string $state): string
38+
protected function getAuthUrl(?string $state): string
3939
{
4040
return $this->buildAuthUrlFromBase($this->host . '/oauth/authorize', $state);
4141
}

src/socialite/src/Two/GoogleProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GoogleProvider extends AbstractProvider implements ProviderInterface
2323
'email',
2424
];
2525

26-
protected function getAuthUrl(string $state): string
26+
protected function getAuthUrl(?string $state): string
2727
{
2828
return $this->buildAuthUrlFromBase('https://accounts.google.com/o/oauth2/auth', $state);
2929
}

src/socialite/src/Two/LinkedInOpenIdProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LinkedInOpenIdProvider extends AbstractProvider implements ProviderInterfa
1818
*/
1919
protected string $scopeSeparator = ' ';
2020

21-
protected function getAuthUrl(string $state): string
21+
protected function getAuthUrl(?string $state): string
2222
{
2323
return $this->buildAuthUrlFromBase('https://www.linkedin.com/oauth/v2/authorization', $state);
2424
}

src/socialite/src/Two/LinkedInProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class LinkedInProvider extends AbstractProvider implements ProviderInterface
1919
*/
2020
protected string $scopeSeparator = ' ';
2121

22-
protected function getAuthUrl(string $state): string
22+
protected function getAuthUrl(?string $state): string
2323
{
2424
return $this->buildAuthUrlFromBase('https://www.linkedin.com/oauth/v2/authorization', $state);
2525
}

src/socialite/src/Two/OpenIdProvider.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,44 @@ abstract protected function getBaseUrl(): string;
4545
*/
4646
public function redirect(): ResponseInterface
4747
{
48+
$state = null;
49+
$nonce = null;
50+
51+
if ($this->usesState()) {
52+
$this->request->session()->put('state', $state = $this->getState());
53+
}
54+
55+
if ($this->usesPKCE()) {
56+
$this->request->session()->put('code_verifier', $this->getCodeVerifier());
57+
}
58+
4859
if ($this->usesNonce()) {
49-
$this->request->session()->put('nonce', $this->getNonce());
60+
$this->request->session()->put('nonce', $nonce = $this->getNonce());
5061
}
5162

52-
return parent::redirect();
63+
return $this->response->redirect(
64+
$this->getAuthUrl($state, $nonce)
65+
);
66+
}
67+
68+
/**
69+
* Get the authentication URL for the provider.
70+
*/
71+
protected function getAuthUrl(?string $state, ?string $nonce = null): string
72+
{
73+
return $this->buildAuthUrlFromBase(
74+
$this->getOpenIdConfig()['authorization_endpoint'],
75+
$state,
76+
$nonce
77+
);
78+
}
79+
80+
/**
81+
* Build the authentication URL for the provider from the given base URL.
82+
*/
83+
protected function buildAuthUrlFromBase(string $url, ?string $state, ?string $nonce = null): string
84+
{
85+
return $url . '?' . http_build_query($this->getCodeFields($state, $nonce), '', '&', $this->encodingType);
5386
}
5487

5588
/**
@@ -76,26 +109,15 @@ protected function getJwksUri(): string
76109
return $this->getOpenIdConfig()['jwks_uri'];
77110
}
78111

79-
/**
80-
* Get the authentication URL for the provider.
81-
*/
82-
protected function getAuthUrl(string $state): string
83-
{
84-
return $this->buildAuthUrlFromBase(
85-
$this->getOpenIdConfig()['authorization_endpoint'],
86-
$state
87-
);
88-
}
89-
90112
/**
91113
* Get the GET parameters for the code request.
92114
*/
93-
protected function getCodeFields(?string $state = null): array
115+
protected function getCodeFields(?string $state = null, ?string $nonce = null): array
94116
{
95117
$fields = parent::getCodeFields($state);
96118

97-
if ($this->usesState()) {
98-
$fields['state'] = $state;
119+
if ($this->usesNonce()) {
120+
$fields['nonce'] = $nonce;
99121
}
100122

101123
return $fields;

0 commit comments

Comments
 (0)