Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Trying to perform oauth2 code => acesss_token exchange using Request class, getting redirects
  • I tried to build a method that exchanges an oauth2 code to get an access token with foursquare but I keep getting redirected and a 404 error is thrown

    class Controller_Foursquare extends Controller_Rest
    {

          public function action_exchange($code = null)
          {

                $data = array();

                $this->format = 'json';

                if ($code != null) {
                      $curl = Request::forge('https://foursquare.com/oauth2/access_token', 'curl');

                      $params = array(
                          'client_id' => Config::get('foursquare_client_id'),
                          'client_secret' => Config::get('foursquare_client_secret'),
                          'grant_type' => 'authorization_code',
                          'redirect_uri' => 'https://mydomain.com/foursquare/exchange',
                          'code' => $code
                      );

                      $curl->set_method('get');

                      $curl->set_params($params);

                      $curl->execute();

                      $data = $curl->response();
                }
                else {
                      $data = array(
                          'test'=>1234,
                      );
                }

                return $this->response($data, 200);
          }

    }

    This is a server-side exchange, I dont get why it's redirecting at all, shouldn't curl just send a request that I can get the response object?
  • It may be foursquare that is doing the redirecting? I never used it, but quite a few require you to define the redirect URL centrally for security reasons.
  • I suppose, but to me it seem like when I execute the curl request fuel takes over and since it's an external address the router decides to forward to the 404 page, but that's not how pure php based curl would work. 
  • Fuel does that neither. There is no redirect in the Curl Request class.

    Your log should tell you which URI were requested, and a tool like Live HTTP headers (in FF) can tell you exactly which requests your browser has executed. Check that and you'll see exactly what happens, and in which sequence.

    it looks to me that you're guessing now, and that doesn't get you very far...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion