gpt4 book ai didi

reactjs - 如何将 Bearer token 添加到从 openapi-generator-cli 生成的 api 端点的 header

转载 作者:行者123 更新时间:2023-12-03 08:39:22 26 4
gpt4 key购买 nike

我正在测试 openapi-generator-cliswagger.json 文件为 React 客户端应用生成服务。

现在,某些路由受到保护,并需要 header 中的承载 token 。登录后返回token。

在调用 protected 路由的生成方法时是否可以将它们添加为配置或 header 参数?

最佳答案

在我的组件中,我使用将配置作为参数的服务来实现 Api。

myToken 是一个局部变量,我之前在其中存储了 token 。

import * as Api from '../../api/src';
const configParameters: Api.ConfigurationParameters = {
headers: {
'Authorization': 'Bearer ' + myToken,
},
};
const configuration = new Api.Configuration(configParameters);
const myService = new Api.MyApi(configuration);

关于reactjs - 如何将 Bearer token 添加到从 openapi-generator-cli 生成的 api 端点的 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63015498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com