0

I am getting HTTP response code 307 Temporary Redirect while trying to get access token from google access token endpoint with HTTP_Request2 Library

//$accessTokenExchangeUrl = "http://accounts.google.com/o/oauth2/token"; //here it is access token end point url
    $request = new HTTP_Request2($accessTokenExchangeUrl);
    $request->setMethod(HTTP_Request2::METHOD_POST)
    ->addPostParameter(array('client_id' => '****40537585-7alm02hqa1j4sh3p9rfrldm7dqt1945h.apps.googleusercontent.com','client_secret' => '****dEwpzTN_OykbwwyLXeJF','grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => $redirect)); //multiple
        try
        {
    $response =  $request->send();
      if (200 == $response->getStatus()) {
        echo "</br>";
        echo "Request Send";
    }
    else
    {
        echo "</br>";
        echo "Request Error";
         echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .$response->getReasonPhrase();
    }   
    }
    catch (HTTP_Request2_Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • Is there a option Google oAuth endpoint for redirection after authenticating? – Prav Sep 25 '17 at 13:19
  • what URL are you trying to access? Does the documentation say in what circumstances a 307 will be sent? Is there a pre-written Google Client Library for PHP for the API you want to access? There are libraries for a lot of the APIs. It might be easier than trying to write your own client. – ADyson Sep 25 '17 at 13:45
  • @ADyson This URL i am trying to access :- https://accounts.google.com/o/oauth2/token with POST parameters :- client_id=****40537585-7alm02hqa1j4sh3p9rfrldm7dqt1945h.apps.googleusercontent.com&client_secret=****dEwpzTN_OykbwwyLXeJF&grant_type=authorization_code&code=**yw9-9WMI2Aw75NvdbhgjPmsZ07wjeR234y9qyQONbd4&redirect_uri=http://127.0.0.1/page_name.php – Ankit Kushwah Sep 27 '17 at 18:54
  • @ADyson this is documentation of google related to 307 http response code: temporaryRedirect Resource temporarily located elsewhere according to the Location header. Among other reasons, this can occur when cookie-based authentication is being used, e.g., when using the Storage Browser, and it receives a request to download content... I already checked same url with a same parameter with Burpsuite and in burp suite response i am getting 200 http response code – Ankit Kushwah Sep 27 '17 at 18:54
  • @ADyson Yaa there is pre-written Google Client Library, but i want to test my own code – Ankit Kushwah Sep 27 '17 at 18:56
  • @PraveenM Yaa there is option of redirection in authorization endpoint but i am getting problem in token requests endpoint and i don't think there is redirection option in it.. – Ankit Kushwah Sep 27 '17 at 19:02
  • maybe one idea is to use a tool like Fiddler to compare your request with the one that burpsuite makes. If you compare the headers, content etc you might spot a difference giving you a clue as to why you get a different response – ADyson Sep 27 '17 at 19:38

0 Answers0