我有一个 React 前端,Firebase 后端尝试完成 Stripe OAuth 过程。重定向 URI 回来了(返回到https://mywebsitename.com/oauth_return)并且我在该页面上打开的 react 组件解析该 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?
对此问题的任何澄清将不胜感激。