pulkitjalan / google-apiclient

Google api php client wrapper with Cloud Platform and Laravel support
MIT License
246 stars 75 forks source link

Dynamic redirect url #41

Open robertmylne opened 4 years ago

robertmylne commented 4 years ago

The following code does not allow for dynamic redirect_url which means that if I have more than one domain running the website it will not work.

  public function fetchAccessTokenWithAuthCode($code)
  {
    if (strlen($code) == 0) {
      throw new InvalidArgumentException("Invalid code");
    }

    $auth = $this->getOAuth2Service();
    $auth->setCode($code);
    $auth->setRedirectUri($this->getRedirectUri());

    $httpHandler = HttpHandlerFactory::build($this->getHttpClient());
    $creds = $auth->fetchAuthToken($httpHandler);
    if ($creds && isset($creds['access_token'])) {
      $creds['created'] = time();
      $this->setAccessToken($creds);
    }

    return $creds;
  }

Can we have the above changed to this:

  public function fetchAccessTokenWithAuthCode($code, $redirectUrl = null)
  {
    if (strlen($code) == 0) {
      throw new InvalidArgumentException("Invalid code");
    }

    $auth = $this->getOAuth2Service();
    $auth->setCode($code);
    $auth->setRedirectUri($redirectUrl ?? $this->getRedirectUri());

    $httpHandler = HttpHandlerFactory::build($this->getHttpClient());
    $creds = $auth->fetchAuthToken($httpHandler);
    if ($creds && isset($creds['access_token'])) {
      $creds['created'] = time();
      $this->setAccessToken($creds);
    }

    return $creds;
  }
github-actions[bot] commented 6 days ago

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days