Guest User

Untitled

a guest
Apr 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Libraries\OAuth;
  4.  
  5. class ImplicitGrantWithPostmessage extends \League\OAuth2\Server\Grant\ImplicitGrant
  6. {
  7. public function completeAuthorizationRequest(\League\OAuth2\Server\RequestTypes\AuthorizationRequest $authorizationRequest) {
  8. $response = parent::completeAuthorizationRequest($authorizationRequest);
  9.  
  10. $reflectionClassResponse = new \ReflectionClass($response);
  11. $reflectionProperty = $reflectionClassResponse->getProperty('redirectUri');
  12. $reflectionProperty->setAccessible(true);
  13.  
  14. $redirectUri = $reflectionProperty->getValue($response);
  15. if (empty($redirectUri)) throw new \Exception('Invalid redirect');
  16.  
  17. // Parse response
  18. $redirectUriExploded = explode('#', $redirectUri, 2);
  19.  
  20. $redirectUriOne = current($redirectUriExploded);
  21. $redirectUriTwo = end($redirectUriExploded);
  22.  
  23. if (empty($redirectUriOne)) throw new \Exception('Invalid redirect');
  24.  
  25. $urlComponents = parse_url($redirectUriOne);
  26. $domain = $urlComponents['scheme'] . '://' . $urlComponents['host'];
  27. if (isset($urlComponents['port'])) $domain .= ':' . $urlComponents['port'];
  28.  
  29. parse_str($redirectUriTwo, $data);
  30. $data = json_encode($data);
  31.  
  32. echo "<script>
  33. if (window.opener != null) {
  34. window.opener.postMessage($data, '$domain');
  35. window.close();
  36. } else {
  37. window.location.href = '$redirectUri';
  38. }
  39. </script>";
  40.  
  41. exit;
  42. }
  43.  
  44. public function getIdentifier() {
  45. return 'token';
  46. }
  47. }
Add Comment
Please, Sign In to add comment