gpt4 book ai didi

identityserver4 - 使用IdentityServer和JavaScript的oidc客户端登录SigninSilentCallback中没有用户

转载 作者:行者123 更新时间:2023-12-04 07:08:50 37 4
gpt4 key购买 nike

我在以下代码中得到用户未定义的信息。

我已经通过MVC对用户进行了身份验证。

但是,当我使用signinSilentCallback来获取该用户的详细信息时,使用js中的oidc-client却无法定义该用户。

它也不会给出任何错误。

        var mgr = new UserManager({
authority: "http://localhost:5000",
client_id: "js",
redirect_uri: "http://localhost:50144/signin-oidc",
silent_redirect_uri: "http://localhost:50144/signin-oidc",
response_type: "id_token token",
post_logout_redirect_uri: "http://localhost:50144/signout-callback-oidc",
});

mgr.signinSilentCallback().then(function (user) {

//**Here user is undefined.**
axios.defaults.headers.common['Authorization'] = "Bearer " + user.access_token;

});

在Identityserver 4中,客户端定义如下。
new Client
{
ClientId = "js",
ClientName = "js",
ClientUri = "http://localhost:50144",

AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RequireClientSecret = false,
AccessTokenType = AccessTokenType.Jwt,

RedirectUris =
{
"http://localhost:50144/signin-oidc",
},

PostLogoutRedirectUris = { "http://localhost:50144/signout-callback-oidc" },
AllowedCorsOrigins = { "http://localhost:50144" },

AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email
}
}

最佳答案

signinSilentCallback: Returns promise to notify the parent window of response from the authorization endpoint. https://github.com/IdentityModel/oidc-client-js/wiki



signinSilentCallback -这不是将返回您的用户对象的东西。

如果您真的需要让用户对象进行静默续订,我建议在下面的代码段中使用这种方法。这在Salesforce应用中也适用于我。
this.userManager.events.addAccessTokenExpiring(() =>
{
this.userManager.signinSilent({scope: oidcSettings.scope, response_type: oidcSettings.response_type})
.then((user: CoreApi.Authentication.Interfaces.OidcClientUser) =>
{
this.handleUser(user); // This function just set the current user
})
.catch((error: Error) =>
{
this.userManager.getUser()
.then((user: CoreApi.Authentication.Interfaces.OidcClientUser) =>
{
this.handleUser(user);
});
});
});

由于在oidc-client js中为iFrame报告的错误之一,我们也需要处理getUser。

从上面的代码着眼于 token 过期时执行静默更新的方式。

关于identityserver4 - 使用IdentityServer和JavaScript的oidc客户端登录SigninSilentCallback中没有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50416649/

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