Get parameters from Stripe page redirect URL Node.js

Ad

I am using Stripe Connect and using their example code in the documentation. You redirect a user to the Stripe page, they sign up and it redirects back to your site. Stripe then sends a code in the URL for you to be able to access and charge the users account.

var CLIENT_ID = 'clientID';
var API_KEY = 'API Key';

var TOKEN_URI = 'https://connect.stripe.com/oauth/token';
var AUTHORIZE_URI = 'https://connect.stripe.com/oauth/authorize';

var qs = require('querystring');
var request = require('request');
var express = require('express');

var app = express();

app.get('/authorize', function(req,res){
    res.redirect(AUTHORIZE_URI + '?' + qs.stringify({
      response_type: 'code',
      scope: 'read_write',
      client_id: CLIENT_ID
    }));
  })

After the redirect this code is what they have in the example:

app.get('/oauth/callback', function(req, res) {

    var code = req.query.code;
    console.log('code: ', code)
    // Make /oauth/token endpoint POST request
    request.post({
      url: TOKEN_URI,
      form: {
        grant_type: 'authorization_code',
        client_id: CLIENT_ID,
        code: code,
        client_secret: API_KEY
      }
    }, function(err, r, body) {

      var accessToken = JSON.parse(body).access_token;
      console.log('access: ', accessToken)
      // Do something with your accessToken

      // For demo's sake, output in response:
      res.send({ 'Your Token': accessToken });

    });
  });

The redirect URL is https://connect.stripe.com/oauth/authorize?response_type=code&CLIENT_ID=blahblahblah. When it redirects to my site I the URL is localhost:9000/?scope=read_write&code=blahblahblah. How do I get access to this URL? Thank you!

Ad

Answer

Ad

I figured it out. In the account settings, under Connect, you have to change the redirect URI to yourURL.com/oauth/callback in order for it to work. I only had it redirecting to yourURL.com

Ad
source: stackoverflow.com
Ad