从Stripe页面重定向URL Node.js获取参数 [英] Get parameters from Stripe page redirect URL Node.js

查看:95
本文介绍了从Stripe页面重定向URL Node.js获取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Stripe Connect并在文档中使用其示例代码.您将用户重定向到条带化"页面,他们进行了注册,然后将其重定向回到您的站点.然后,Stripe在URL中发送代码,以便您能够访问用户帐户并向其收费.

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 });

    });
  });

重定向URL为 https://connect.stripe.com/oauth/authorize?response_type = code& CLIENT_ID = blahblahblah .当它重定向到我的网站时,URL为localhost:9000/?scope = read_write& code = blahblahblah.如何获得此URL的访问权限?谢谢!

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!

推荐答案

我知道了.在帐户设置的连接"下,您必须将重定向URI更改为yourURL.com/oauth/callback才能起作用.我只有重定向到yourURL.com

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

这篇关于从Stripe页面重定向URL Node.js获取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆