如何在cookie中传递访问令牌?

时间:2021-03-18 16:04:42

标签: c# authentication cookies identityserver4 oidc-client-js

这是我的 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 中传递访问令牌?

0 个答案:

没有答案