【发布时间】:2020-12-10 00:47:06
【问题描述】:
我有一个 React 前端,Firebase 后端尝试完成 Stripe OAuth 流程。重定向 URI 已返回(返回到 https://mywebsitename.com/oauth_return),并且我在该页面上打开的反应组件解析该 URL 并访问身份验证代码和状态。 (请看下文)
在“oauth_return.js”文件中
import React from 'react';
import queryString from 'query-string';
const oauth_redirect = () => {
//Parsing over URL
const value=queryString.parse(window.location.search);
const code=value.code;
console.log('code:', code)
const state=value.state;
console.log('state:', state)
}
export default (oauth_redirect)
我遇到的困难是试图弄清楚如何使 firebase HTTP 函数通过 POST 方法返回身份验证代码。我所有的 firebase 函数都存在于函数目录的“index.js”文件中。我看到的所有教程都展示了在 Typescript 中构建此函数的各种方法,但我的代码需要用 Javascript 编写。
在“functions/index.js”文件中
(...)
exports.stripeCreateOathResponseToken = functions.https.onRequest((req, res) => {
(...) Not sure what to write in this function to return the authorization code. All tutorials I've found are written in Typescript.
});
不幸的是,我不明白如何触发这个 HTTP 函数首先被调用(即我是否需要在“oauth_return.js”文件中显式调用它?如何将授权代码传递给它? 最重要的是,它如何将授权码发回给 Stripe?
我们将不胜感激。
【问题讨论】:
-
您在下面已经有一个很好的答案,我认为值得探索。但我想指出的是,Stripe 为标准/快速帐户提供了一个新的入职流程,不需要 OAuth。这可能值得研究。你可以在这里阅读更多内容:stripe.com/docs/connect/standard-accounts, stripe.com/docs/connect/express-accounts
-
谢谢 ttmarek!我肯定也会研究这个解决方案。
标签: reactjs firebase oauth google-cloud-functions stripe-payments