File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ var express = require ( 'express' ) ;
2+ var bodyParser = require ( 'body-parser' ) ;
3+ var FitbitClient = require ( 'fitbit-client-oauth2' ) ;
4+
5+ var app = express ( ) ;
6+
7+ var clientId = 'YOUR_CLIENT_ID' ;
8+ var clientSecret = 'YOUR_CLIENT_SECRET' ;
9+
10+ var client = new FitbitClient ( clientId , clientSecret ) ;
11+ var redirect_uri = 'http://localhost:3000/auth/fitbit/callback' ;
12+
13+ app . use ( bodyParser ( ) ) ;
14+
15+ app . get ( '/auth/fitbit' , function ( req , res ) {
16+
17+ var auth_url = client . getAuthorizationUrl ( 'http://localhost:3000/auth/fitbit/callback' ) ;
18+
19+ res . redirect ( auth_url ) ;
20+
21+ } ) ;
22+
23+ app . get ( '/auth/fitbit/callback' , function ( req , res , next ) {
24+
25+ client . getToken ( req . query . code , redirect_uri )
26+ . then ( function ( token ) {
27+
28+ // ... save your token on session or db ...
29+
30+ // then redirect
31+ //res.redirect(302, '/user');
32+
33+ res . send ( token ) ;
34+
35+ } )
36+ . catch ( function ( err ) {
37+ // something went wrong.
38+ res . send ( 500 , err ) ;
39+
40+ } ) ;
41+
42+ } ) ;
43+
44+ app . listen ( 3000 ) ;
You can’t perform that action at this time.
0 commit comments