c# - 如何在 cookie 中传递访问令牌?
问题描述
这是我的 WebAPI 配置:
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication("Bearer", options =>
{
options.Authority = "https://localhost:44305/";
options.ApiName = "ApiOne";
options.ApiSecret = "secret1";
});
以下是它在 JavaScript 中的使用方式(使用 oidc-client):
var config = {
userStore: new Oidc.WebStorageStateStore({ store: window.localStorage }),
authority: "https://localhost:44305/",
client_id: "client_id_js",
redirect_uri: "https://localhost:44345/Home/SignIn",
post_logout_redirect_uri: "https://localhost:44345/Home/Index",
response_type: "id_token token",
scope: "openid rc.scope ApiOne ApiTwo"
};
var userManager = new Oidc.UserManager(config);
userManager.getUser().then(user => {
console.log("user:", user);
if (user) {
axios.defaults.headers.common["Authorization"] = "Bearer " + user.access_token;
}
});
如果可能的话,我该如何修改它以在 cookie 中传递访问令牌?
解决方案
推荐阅读
- string - VB.NET - 查找一个字符后跟一个句点并删除句点
- javascript - 如何在 JS 中获取所有匹配的数据?
- typescript - 使用 Pick 为具有索引类型的对象构造类型
- python - 使用列表和多个数据框查找数据框
- c++ - QLineEdit 中输入的小数如何进行乘法运算?
- reporting-services - SSRS 报告 | 使用不同数据集的多个工作表
- python - 在 for 循环中使用 append 获得正确的输出顺序
- node.js - 节点中未定义的 HTTP Post
- javascript - 如何替换 div 子元素?
- python - 为什么 groupby 方法在 Pandas 的滚动总和计算中不起作用,我该如何解决?