2

I'm trying to authenticate into Stack Exchange's API with the following URL:

https://stackexchange.com/oauth/dialog?client_id=3535&scope=write_access&redirect_uri=https://stackexchange.com/oauth/login_success

This returns a redirect with access_token into queryString:

OAuth response

The problem comes when I try to get the redirection with Curl: it return 500 internal server error.

EDIT

My idea is instantiate an OAuth2 class like this:

$oauth2 = new OAuth2('key', 'client_id', 'scope', 'redirect_uri'); 
$accessToken = $oauth2->getAccessToken();

// For auth require methods
$client = new Client('key', $accessToken);

// Without auth
$client = new Client();

I don't want to obtain the access_token manually pasting the URL in the browser. I want to generate the token with this four values.

So, any suggestion on how to implement the getAccessToken() method?

5
  • Been a while since I tried this in PHP. I don't think you need cURL or to actually redirect. Just grab the response URL. It has the access_token and that's all you need from this step of the auth process. Commented Sep 8, 2014 at 11:31
  • @BrockAdams I just edit the question, can you explain your approach with an example, please?
    – 2359967
    Commented Sep 8, 2014 at 12:36
  • Why are you redirecting to stackexchange.com/oauth/login_success? Redirect to a page on your server. Or just do a self redirect and read the URL parameters on redirect. Commented Sep 8, 2014 at 13:07
  • Sorry @BrockAdams but I'm quite missing. What is the redirected_uri when I use via terminal and in the localhost?
    – 2359967
    Commented Sep 8, 2014 at 15:57
  • @BrockAdams Can you rewrite my above URL to work as Self Redirect, please?
    – 2359967
    Commented Sep 9, 2014 at 13:08

0

You must log in to answer this question.

Browse other questions tagged .