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

fitbit.authorizeURL() not working while using res.redirect #3

Open
gurpreets89 opened this issue Feb 5, 2016 · 4 comments
Open

fitbit.authorizeURL() not working while using res.redirect #3

gurpreets89 opened this issue Feb 5, 2016 · 4 comments

Comments

@gurpreets89
Copy link

Hi Team,
Greetings
We have facing an issue while using res.redirect(fitbit.authorizeURL()). But if i call the URL through web browser it gets invoked and called the redirect URL which has been set in fitbit application
settings. Please troubleshoot our problem.
Thanks for your co-operation.
screenshot from 2016-02-05 20 45 32

@peebles
Copy link
Owner

peebles commented Feb 5, 2016

Are you trying to use this library in the browser? This library is designed to be used in your webserver backend to make calls to the fitbit api, not in your webclient.

Send me the code where you are actually using and calling this library and perhaps I can assist you better.

@gurpreets89
Copy link
Author

I am using the code snippet running in Node.js with express. Here is my code
authorize = function(req, res){
console.log('\n---------\n',fitbit.authorizeURL());
//res.json(fitbit.authorizeURL());
var url = fitbit.authorizeURL();
res.redirect(url);
}

@gurpreets89
Copy link
Author

@peebles When i called my webserver API through REST console, Its working fine. But when i called through azax call using AngularJs. it gives CORS error. Any suggestions?

@peebles
Copy link
Owner

peebles commented Feb 9, 2016

Add the following to your webserver (assuming its written in node/express):

     // CORS support
     app.use( function( req, res, next ) {
         res.header('Access-Control-Allow-Origin', req.headers.origin);
         res.header('Access-Control-Allow-Methods', 

'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Origin,
X-Requested-With, Content-Type, Accept, Final-Length, Offset,
Content-Range, Content-Disposition');
res.header('Access-Control-Allow-Credentials', 'true' );
if ( req.method == 'OPTIONS' ) {
res.send( 200 );
}
else {
next();
}
});

On 2/9/16 7:10 AM, gurpreets89 wrote:

@peebles https://github.com/peebles When i called my webserver API
through REST console, Its working fine. But when i called through azax
call using AngularJs. it gives CORS error. Any suggestions?


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

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