Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express'),
- app = express();
- var oauth2 = require('simple-oauth2')({
- clientID: 'client_id',
- clientSecret: 'client_secret',
- site: 'https://btcjam.com',
- tokenPath: '/oauth/token',
- authorizationPath: '/oauth/authorize'
- });
- // Authorization uri definition
- var authorization_uri = oauth2.authCode.authorizeURL({
- redirect_uri: 'http://localhost:3000/callback'
- });
- // Initial page redirecting to Github
- app.get('/auth', function (req, res) {
- res.redirect(authorization_uri);
- });
- // Callback service parsing the authorization token and asking for the access token
- app.get('/callback', function (req, res) {
- var code = req.query.code;
- console.log(code);
- console.log('/callback');
- oauth2.authCode.getToken({
- code: code,
- redirect_uri: 'http://localhost:3000/callback'
- }, saveToken);
- function saveToken(error, result) {
- if (error) { console.log('Access Token Error', error.message); }
- token = oauth2.accessToken.create(result);
- // Request
- oauth2.api('GET', '/api/v1/me', {
- access_token: token.token.access_token
- }, function (err, data) {
- console.log(data);
- });
- }
- });
- app.get('/', function (req, res) {
- res.send('Hello<br><a href="/auth">Log in with BTCJam</a>');
- });
- app.listen(3000);
- console.log('Express server started on port 3000');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement