Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update the token in the database #5

Open
balajijana opened this issue Mar 13, 2016 · 4 comments
Open

How to update the token in the database #5

balajijana opened this issue Mar 13, 2016 · 4 comments

Comments

@balajijana
Copy link

Hi,

I need an urgent help. I am fetching the token and updating the token in the Mongodb but its not getting updated. I have used UPDATE command from the mongodb but i feel thats async call is interrupting the save command.Please tell me how to update and save the token.

@peebles
Copy link
Owner

peebles commented Mar 13, 2016

Post the code you have that is not working and I'll take a look.
a

On 3/13/16 7:52 AM, Balaji wrote:

Hi,

I need an urgent help. I am fetching the token and updating the token
in the Mongodb but its not getting updated. I have used UPDATE command
from the mongodb but i feel thats async call is interrupting the save
command.Please tell me how to update and save the token.


Reply to this email directly or view it on GitHub
#5.

@balajijana
Copy link
Author

exports.callback = function (req, res) {
var config = {
'fitbit': {
'timeout': 10000,
'creds': {
'clientID': '227G8N',
'clientSecret': '5ba01cecb354b35c9bc422ed292fb1f6'
},
'uris': {
'authorizationUri': 'https://www.fitbit.com',
'authorizationPath': '/oauth2/authorize',
'tokenUri': 'https://api.fitbit.com',
'tokenPath': '/oauth2/token'
},
'authorization_uri': {
'redirect_uri': callbackUrl,
'response_type': 'code',
'scope': 'activity nutrition profile settings sleep social weight heartrate',
'state': req.query.state
}
}
};
if (!req.query.code) {
//res.status(403);
//return res.status(403).end()
//console.log(err);
return res.status(500).send({'error':'invalid code'});
}

var fitbit = new Fitbit(config.fitbit);
var code = req.query.code;
fitbit.fetchToken(code, function( err, token ) {
  if (err || !token) {
    console.log(err);
    return res.status(500).send({error:err.toString()});
  }
  var parseData = token;
  console.log(parseData);
  var oAuthFitBitAccess = {
    'attributes.oauthSettings.fitbit': {
      'access': {
        token: parseData.access_token,
        tokenSecret: parseData.refresh_token,
        providerUserId: parseData.user_id
      },
      'userId': req.query.state
    }
  };
   User.update({_id:req.query.state}, oAuthFitBitAccess, function (err,result) {
   if (err) {
   console.log(err);
   return res.status(500).send(err);
   }       
  if(result.n > 0) {
   var state = req.query.state;
   return res.status(200).send({state: state});
   }
   else {
   return res.status(500).send({'error':'no update'});
   }
   });
});

};
This is the code i have written in which you can find the update query. Sometimes its get saved and sometimes its not got saved. please let me know what is the issue

@peebles
Copy link
Owner

peebles commented Mar 14, 2016

I don't know. I don't use MongoDB, but the code you show below looks
reasonable.
a

On 3/14/16 4:20 AM, Balaji wrote:

exports.callback = function (req, res) {
var config = {
'fitbit': {
'timeout': 10000,
'creds': {
'clientID': '227G8N',
'clientSecret': '5ba01cecb354b35c9bc422ed292fb1f6'
},
'uris': {
'authorizationUri': 'https://www.fitbit.com',
'authorizationPath': '/oauth2/authorize',
'tokenUri': 'https://api.fitbit.com',
'tokenPath': '/oauth2/token'
},
'authorization_uri': {
'redirect_uri': callbackUrl,
'response_type': 'code',
'scope': 'activity nutrition profile settings sleep social weight
heartrate',
'state': req.query.state
}
}
};
if (!req.query.code) {
//res.status(403);
//return res.status(403).end()
//console.log(err);
return res.status(500).send({'error':'invalid code'});
}

|var fitbit = new Fitbit(config.fitbit); var code = req.query.code;
fitbit.fetchToken(code, function( err, token ) { if (err || !token) {
console.log(err); return res.status(500).send({error:err.toString()});
} var parseData = token; console.log(parseData); var oAuthFitBitAccess
= { 'attributes.oauthSettings.fitbit': { 'access': { token:
parseData.access_token, tokenSecret: parseData.refresh_token,
providerUserId: parseData.user_id }, 'userId': req.query.state } };
User.update({_id:req.query.state}, oAuthFitBitAccess, function
(err,result) { if (err) { console.log(err); return
res.status(500).send(err); } if(result.n > 0) { var state =
req.query.state; return res.status(200).send({state: state}); } else {
return res.status(500).send({'error':'no update'}); } }); }); |

};
This is the code i have written in which you can find the update
query. Sometimes its get saved and sometimes its not got saved. please
let me know what is the issue


Reply to this email directly or view it on GitHub
#5 (comment).

@balajijana
Copy link
Author

Thanks for your comment. I am currently looking for the subscription and notification code from the application side i.e from node js side. Do you have any workflow details can you please suggest me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants