i trying access_token google in titanium application access google+ api. have registered android oauth2.0 client in google api console have client id , couple of redirect uris generated google: ["urn:ietf:wg:oauth:2.0:oob","http://localhost"]. trying follow authorization code flow, have made authorization request endpoint "https://accounts.google.com/o/oauth2/v2/auth" following parameters query strings:
client_id = encodeuri(<app id>) redirect_uri = encodeuri("urn:ietf:wg:oauth:2.0:oob") response_type = "code", state = <random generated number> scope = "https://www.googleapis.com/auth/plus.me"
then create webview , redirect authorization endpoint appendend query strings. google login screen opens , can login , grant access application. in return url authorization code embedded can extract use next call.
to access_token make post request "https://accounts.google.com/o/oauth2/v2/auth" endpoint. function:
function getaccesstoken(code) { ti.api.warn("authorization code: " + code); var auth_data = { code : code, client_id : client_id, redirect_uri : redirect_uri, grant_type : "authorization_code", }; var client = ti.network.createhttpclient({ onload: function() { var response_data = json.parse(this.responsetext); var access_token = response_data["access_token"]; var expires_in = response_data["expires_in"]; }, onerror: function() { ti.api.error("httpclient: error occurred."); ti.api.error(this.responsetext); } }); var body = ""; (var key in auth_data) { if (body.length) { body += "&"; } body += key + "="; body += encodeuricomponent(auth_data[key]); } client.open("post", "https://accounts.google.com/o/oauth2/v2/auth"); client.setrequestheader('content-type', 'application/x-www-form-urlencoded'); client.send(body); }
but got status code of 400 following message: "required parameter missing: response_type".
i not sure why getting this, since oauth 2.0 specification required parameters access token request grant_type, code, client_id , redirect_uri. have tried add response_type = "token" should implicit flow if understand correctly.
any advice?
it seems found problem, endpoint token exchange not correct. should "https://accounts.google.com/o/oauth2/token", @ least 1 worked me.
i point out in latest documentation of google endpoint token exchange one: "https://accounts.google.com/o/oauth2/v2/token" reason doesn't work me (the response says url not supported server). hope can people similar issue.
Comments
Post a Comment