2
votes

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!

2
Are you looking for the redirect_uri parameter? stripe.com/docs/connect/referenceMrAnno

2 Answers

1
votes

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

0
votes
  1. Add redirect_uri to The redirect URL https://connect.stripe.com/oauth/authorize?response_type=code&CLIENT_ID=blahblahblah&redirect_uri=localhost:9000/stripe-callback
  2. Get authorization code from param "code" of redirect_uri
  3. Your site then makes a request to our OAuth token endpoint to fetch the user’s authorization credentials, storing them on your site.

Note: Input your redirect_uri on stripe dashboard setting in https://dashboard.stripe.com/account/applications/settings

Or Dashboard -> Account settings -> Connect -> Platform Settings -> Redirect URIs