You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to authenticate user on server side (node.js based REST API) as it described here: https://github.com/oauth-io/sdk-node#auth-method, section 'Authenticating the user from the frontend JS SDK'.
Client side (Phonegap oauth.io SDK) works OK and returns code after successful authentication.
Server side code:
// Called before auth from clientoauthioStateToken: function(req,res,next){res.json({// Our API does not use session, I pass empty object here for now.token: oauthio.generateStateToken({})});},// Called after auth from clientgoogle: function(req,res,next){if(!req.body||!req.body.code){returnnext(newBadRequestError('No Google access code found'));}// Again, empty object instead of session for now.// This call fails with Error: State is missing from responseoauthio.auth('google_plus',{},{code: req.body.code}).then(function(reqObject){returnreqObject.get("/me");}).then(function(info){res.json(info);}).fail(next);},
Trying to track down a problem I found this code (oauth.is node.js SDK, file lib/authentication.js):
authenticate: function(code,session){vardefer;defer=Q.defer();request.post({url: cache.oauthd_url+cache.oauthd_base+'/access_token',// https://oauth.io/auth/access_tokenform: {code: code,// code, received from clientkey: cache.public_key,// public key from oauth.io. I checked, it matches with client onesecret: cache.secret_key}},function(e,r,body){// Body is {"status":"fail","data":{"code":"invalid or expired"}}// Seems like `response.status=="fail"` is unhandled and it falls to// "Error State is missing from response" (see below).varresponse,_ref;if(e){defer.reject(e);return;}try{response=JSON.parse(body);}catch(_error){e=_error;defer.reject(newError('OAuth.io response could not be parsed'));return;}if((response.status!=null)&&response.status==='error'&&(response.message!=null)){defer.reject(newError('OAuth.io / oauthd responded with : '+response.message));}if(response.state==null){defer.reject(newError('State is missing from response'));return;}if(((session!=null ? session.csrf_tokens : void0)==null)||(_ref=response.state,__indexOf.call(session.csrf_tokens,_ref)<0)){defer.reject(newError('State is not matching'));}if(response.expires_in){response.expires=newDate().getTime()+response.expires_in*1000;}response=a.construct_request_object(response);if((session!=null)){session.oauth=session.oauth||{};session.oauth[response.provider]=response;}returndefer.resolve(response);});returndefer.promise;}
I double checked all settings. Public/Secret keys matching. Added localhost and * to domains whitelist (I am testing from localhost). Maybe I messed something important?
Thank you!
The text was updated successfully, but these errors were encountered:
I am trying to authenticate user on server side (node.js based REST API) as it described here: https://github.com/oauth-io/sdk-node#auth-method, section 'Authenticating the user from the frontend JS SDK'.
Client side (Phonegap oauth.io SDK) works OK and returns code after successful authentication.
Server side code:
Trying to track down a problem I found this code (oauth.is node.js SDK, file lib/authentication.js):
I double checked all settings. Public/Secret keys matching. Added localhost and * to domains whitelist (I am testing from localhost). Maybe I messed something important?
Thank you!
The text was updated successfully, but these errors were encountered: