Skip to content

Commit

Permalink
Fix: diffrent request resposne from diffrent hosts (#1311)
Browse files Browse the repository at this point in the history
* Better error throwing for invalid request

* Normalize requests to . instead of _ and added missing consts

* Corrected const prefix

* Normalize with collection and mapWithKeys
  • Loading branch information
realpoke authored Jan 3, 2025
1 parent 860cc08 commit 6395d69
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ class Provider extends AbstractProvider
/**
* @var string
*/
public const OPENID_SIG = 'openid_sig';
public const OPENID_SIG = 'openid.sig';

/**
* @var string
*/
public const OPENID_SIGNED = 'openid_signed';
public const OPENID_SIGNED = 'openid.signed';

/**
* @var string
*/
public const OPENID_ASSOC_HANDLE = 'openid_assoc_handle';
public const OPENID_ASSOC_HANDLE = 'openid.assoc_handle';

/**
* @var string
Expand All @@ -60,7 +60,17 @@ class Provider extends AbstractProvider
/**
* @var string
*/
public const OPENID_ERROR = 'openid_error';
public const OPENID_ERROR = 'openid.error';

/**
* @var string
*/
public const OPENID_RETURN_TO = 'openid.return_to';

/**
* @var string
*/
public const OPENID_CLAIMED_ID = 'openid.claimed_id';

/**
* {@inheritdoc}
Expand Down Expand Up @@ -160,11 +170,13 @@ private function buildUrl()
*/
public function validate()
{
$this->normalizeOpenidKeys();

if (! $this->requestIsValid()) {
return false;
throw new OpenIDValidationException('A critical openid parameter is missing from the request');
}

if (! $this->validateHost($this->request->get('openid_return_to'))) {
if (! $this->validateHost($this->request->get(self::OPENID_RETURN_TO))) {
throw new OpenIDValidationException('Invalid return_to host');
}

Expand Down Expand Up @@ -200,6 +212,20 @@ private function requestIsValid()
&& $this->request->has(self::OPENID_SIG);
}

/**
* Normlize openid keys from diffrent requests
*
* @return void
*/
private function normalizeOpenidKeys()
{
$normalized = $this->request->collect()->mapWithKeys(function ($value, $key) {
return [preg_replace('/^openid_/', 'openid.', $key) => $value];
})->all();

$this->request->replace($normalized);
}

/**
* @return array
*/
Expand Down Expand Up @@ -238,7 +264,7 @@ public function getParams()
$signedParams = explode(',', $this->request->get(self::OPENID_SIGNED));

foreach ($signedParams as $item) {
$value = $this->request->get('openid_'.str_replace('.', '_', $item));
$value = $this->request->get('openid.'.str_replace('.', '_', $item));
$params['openid.'.$item] = $value;
}

Expand Down Expand Up @@ -277,7 +303,7 @@ public function parseSteamID()
{
preg_match(
'#^https?://steamcommunity.com/openid/id/([0-9]{17,25})#',
$this->request->get('openid_claimed_id'),
$this->request->get(self::OPENID_CLAIMED_ID),
$matches
);

Expand Down

0 comments on commit 6395d69

Please sign in to comment.