Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Libraries\OAuth;
- class ImplicitGrantWithPostmessage extends \League\OAuth2\Server\Grant\ImplicitGrant
- {
- public function completeAuthorizationRequest(\League\OAuth2\Server\RequestTypes\AuthorizationRequest $authorizationRequest) {
- $response = parent::completeAuthorizationRequest($authorizationRequest);
- $reflectionClassResponse = new \ReflectionClass($response);
- $reflectionProperty = $reflectionClassResponse->getProperty('redirectUri');
- $reflectionProperty->setAccessible(true);
- $redirectUri = $reflectionProperty->getValue($response);
- if (empty($redirectUri)) throw new \Exception('Invalid redirect');
- // Parse response
- $redirectUriExploded = explode('#', $redirectUri, 2);
- $redirectUriOne = current($redirectUriExploded);
- $redirectUriTwo = end($redirectUriExploded);
- if (empty($redirectUriOne)) throw new \Exception('Invalid redirect');
- $urlComponents = parse_url($redirectUriOne);
- $domain = $urlComponents['scheme'] . '://' . $urlComponents['host'];
- if (isset($urlComponents['port'])) $domain .= ':' . $urlComponents['port'];
- parse_str($redirectUriTwo, $data);
- $data = json_encode($data);
- echo "<script>
- if (window.opener != null) {
- window.opener.postMessage($data, '$domain');
- window.close();
- } else {
- window.location.href = '$redirectUri';
- }
- </script>";
- exit;
- }
- public function getIdentifier() {
- return 'token';
- }
- }
Add Comment
Please, Sign In to add comment