You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently ran into a strange problem with the Google OAuth and this package.
For some unknown reason having + replaced with %2B in a redirect to a Google OAuth URL results in an error where the scopes query parameter is not properly picked up.
Note the only change is from &scope=openid+profile+email to &scope=openid%2Bprofile%2Bemail
Undoubtedly this an issue Google should fix rather than Spatie. However it does seem it would be preferable to have the option to get an unencoded string both for edge cases like this and it would probably be preferable to display the unencoded version when displaying a URL to a user on a page.
I would like to propose the following changes and am posting it as an issue first incase it needs further discussion but will happily do a pull request.
QueryParameterBag.php
From
public function __toString()
{
$keyValuePairs = Arr::map($this->parameters, function ($value, $key) {
return "{$key}=".rawurlencode($value);
});
return implode('&', $keyValuePairs);
}
public function __toString()
{
return $this->getString(true);
}
public function getString(bool $encoded = true)
{
$keyValuePairs = Arr::map($this->parameters, function ($value, $key) use ($encoded) {
return "{$key}=".($encoded ? rawurlencode($value) : $value);
});
return implode('&', $keyValuePairs);
}
And in Url.php
public function __toString()
{
return $this->getString(true);
}
public function getString(bool $encoded = true)
{
{
$url = '';
if ($this->getScheme() !== '' && $this->getScheme() != 'mailto') {
$url .= $this->getScheme().'://';
}
if ($this->getScheme() === 'mailto' && $this->getPath() !== '') {
$url .= $this->getScheme().':';
}
if ($this->getScheme() === '' && $this->getAuthority() !== '') {
$url .= '//';
}
if ($this->getAuthority() !== '') {
$url .= $this->getAuthority();
}
if ($this->getPath() !== '/') {
$url .= $this->getPath();
}
if ($this->getQuery() !== '') {
$url .= '?'.$this->query->getString($encoded);
}
if ($this->getFragment() !== '') {
$url .= '#'.$this->getFragment();
}
return $url;
}
For the sake of other searchers this is the error message that lead me to this:
Authorization Error
Error 400: invalid_scope
Some requested scopes were invalid. {invalid=[openid+profile+email]}
This discussion was converted from issue #57 on December 14, 2022 09:58.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I recently ran into a strange problem with the Google OAuth and this package.
For some unknown reason having
+
replaced with%2B
in a redirect to a Google OAuth URL results in an error where the scopes query parameter is not properly picked up.So this will work:
but this does not
Note the only change is from
&scope=openid+profile+email
to&scope=openid%2Bprofile%2Bemail
Undoubtedly this an issue Google should fix rather than Spatie. However it does seem it would be preferable to have the option to get an unencoded string both for edge cases like this and it would probably be preferable to display the unencoded version when displaying a URL to a user on a page.
I would like to propose the following changes and am posting it as an issue first incase it needs further discussion but will happily do a pull request.
QueryParameterBag.php
From
And in
Url.php
For the sake of other searchers this is the error message that lead me to this:
Beta Was this translation helpful? Give feedback.
All reactions