Skip to content

Commit

Permalink
Merge pull request #92 from bshaffer/issue-91
Browse files Browse the repository at this point in the history
adds redirect uri exception for 'postmessage'
  • Loading branch information
bshaffer committed Feb 9, 2016
2 parents eb4aaf0 + 0f115fa commit 3e508c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,14 @@ public function setRedirectUri($uri)
$this->redirectUri = null;
return;
}
// redirect URI must be absolute
if (!$this->isAbsoluteUri($uri)) {
throw new \InvalidArgumentException(
// "postmessage" is a reserved URI string in Google-land
// @see https://developers.google.com/identity/sign-in/web/server-side-flow
if ('postmessage' !== (string) $uri) {
throw new \InvalidArgumentException(
'Redirect URI must be absolute');
}
}
$this->redirectUri = (string) $uri;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/OAuth2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public function testIncludesTheScope()
$this->assertEquals('scope1 scope2', $q['scope']);
}

public function testRedirectUriPostmessageIsAllowed()
{
$o = new OAuth2([
'authorizationUri' => 'https://accounts.test.org/insecure/url',
'redirectUri' => 'postmessage',
'clientId' => 'aClientID'
]);
$this->assertEquals('postmessage', $o->getRedirectUri());
$url = $o->buildFullAuthorizationUri();
$parts = parse_url((string) $url);
parse_str($parts['query'], $query);
$this->assertArrayHasKey('redirect_uri', $query);
$this->assertEquals('postmessage', $query['redirect_uri']);
}
}

class OAuth2GrantTypeTest extends \PHPUnit_Framework_TestCase
Expand Down

0 comments on commit 3e508c2

Please sign in to comment.