wordpress - Google OAuth2.0 returns 'invalid_request' when getting access_token with PHP cURL -


i'm experiencing same issue described here" post using curl in php gives invalid request error. before coming across post code setup accepted answer.

// first access code function get_oauth_code($wpoa) {     $params = array(         'response_type' => 'code',         'client_id' => client_id,         'scope' => scope,         'state' => uniqid('', true),         'redirect_uri' => redirect_uri,     );     $_session['wpoa']['state'] = $params['state'];     $url = url_auth . http_build_query($params);     header("location: $url");     exit; }  $params = array(     'grant_type' => 'authorization_code',     'client_id' => client_id,     'client_secret' => client_secret,     'code' => $_get['code'],     'redirect_uri' => redirect_uri, ); $url_params = http_build_query($params); $url = url_token . $url_params; $curl = curl_init(); curl_setopt($curl, curlopt_url, $url); curl_setopt($curl, curlopt_returntransfer, 1); curl_setopt($curl, curlopt_post, 1); curl_setopt($curl, curlopt_postfields, $params); curl_setopt($curl, curlopt_ssl_verifypeer, (get_option('wpoa_http_util_verify_ssl') == 1 ? 1 : 0)); curl_setopt($curl, curlopt_ssl_verifyhost, (get_option('wpoa_http_util_verify_ssl') == 1 ? 2 : 0));         $result = curl_exec($curl); 

when first attempt login works fine, if logout , reattempt (not every time, consistently enough), return following error response

array ( [error] => invalid_request ) 

because of following comment on answer thought perhaps access_code being reused how ran unset make sure , problem still persist. here proof when receive invalid_request error in fact have access code:

array(      [state] => 57c8b107a5a021.27458568      [code] => 4/q8bsww3yhej6tlfqntd-pkfg6zvdbmk9uehgror7f60  ) 

i'm new oauth in general have been dealing week getting pretty familiar hoping out there knows more me me figure out. want make sure user never experience issue logging in because of session details within server side script.

note: in collaboration perry butler's wp-oauth plugin

i'm not familiar google oauth i'd to answer question authority, few problems see code.

1, have lot of defines outside of scope of code. 2, url being appended params supposed applied post of request.

first thing i'd try change line:

$url = url_token . $url_params; 

to:

$url = url_token; 

add debugging in request well, , show $url that's being called. there doesn't appear outside of norm.


Comments