Keine Beschreibung

google-client.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. require_once NSL_PATH . '/includes/oauth2.php';
  3. class NextendSocialProviderGoogleClient extends NextendSocialOauth2 {
  4. protected $access_token_data = array(
  5. 'access_token' => '',
  6. 'expires_in' => -1,
  7. 'created' => -1
  8. );
  9. private $accessType = 'offline';
  10. private $prompt = 'select_account';
  11. protected $scopes = array(
  12. 'email',
  13. 'profile'
  14. );
  15. protected $endpointAuthorization = 'https://accounts.google.com/o/oauth2/auth';
  16. protected $endpointAccessToken = 'https://accounts.google.com/o/oauth2/token';
  17. protected $endpointRestAPI = 'https://www.googleapis.com/oauth2/v2/';
  18. protected $defaultRestParams = array(
  19. 'alt' => 'json'
  20. );
  21. /**
  22. * @param string $access_token_data
  23. */
  24. public function setAccessTokenData($access_token_data) {
  25. $this->access_token_data = json_decode($access_token_data, true);
  26. }
  27. public function createAuthUrl() {
  28. $args = array(
  29. 'access_type' => urlencode($this->accessType)
  30. );
  31. if ($this->prompt != '') {
  32. $args['prompt'] = urlencode($this->prompt);
  33. }
  34. return add_query_arg($args, parent::createAuthUrl());
  35. }
  36. /**
  37. * @param string $prompt
  38. */
  39. public function setPrompt($prompt) {
  40. $this->prompt = $prompt;
  41. }
  42. /**
  43. * @param $response
  44. *
  45. * @throws Exception
  46. */
  47. protected function errorFromResponse($response) {
  48. if (isset($response['error']['message'])) {
  49. throw new Exception($response['error']['message']);
  50. }
  51. }
  52. }