将第三方登录从我的注册页面与 IdentityServer4 和 Angular 6 - 'No matching state found in storage' 集成
Integrate third party login in from my registration page with IdentityServer4 and Angular 6 - 'No matching state found in storage'
我正在尝试在我的注册页面中实施第三方身份验证,但我无法让它与 IdentityServer4 一起使用。由于 oidc 客户端正在启动登录请求,因此我在登录页面中使用它。但是 oidc 客户端不知道对我的注册页面的请求,所以当我发回身份验证令牌时,它无法识别状态并抛出异常:'No matching state found in storage'.
我知道IdentityServer4官方不支持用户注册。我已经设置了 ASP.Net 身份注册,但如果能够在我的注册页面上添加 [第三方提供商] 注册就更好了。有什么办法可以解决这个问题吗?我可以手动设置状态并将注册请求发送给我的身份提供者吗?这样,如果用户选择登录,则 oidc 客户端将具有有效状态。还有别的办法吗?谢谢
我终于找到了解决这个问题的方法。正如我在回答中所述,oidc 客户端在本地存储中维护状态信息,以便它可以验证它是否从预期服务器获得了响应。您可以通过生成安全的随机字符串并将其保存在 localStorage 中来模拟这一点。在向您的身份验证服务器发送请求以注册新用户之前执行此操作。代码如下所示:
const nonce = this.generateUniqueString();
const state = this.generateUniqueString();
const date = new Date();
const query = `${otherQueryOptions}&state=${state}&nonce=${nonce}`;
const authSessionData = {
authority: auth_server_url,
client_id: client_id,
created: date.getTime(),
id: state,
nonce: nonce,
redirect_uri: `your/return.url`
}
// You must prefix the key with 'oidc'
localStorage.setItem(`oidc.${authSessionData.id}`, JSON.stringify(authSessionData));
const registrationPath = `myServerRegistrationPath?${query}`
navigateToPage(registrationPath);
这解决了我的问题。
我正在尝试在我的注册页面中实施第三方身份验证,但我无法让它与 IdentityServer4 一起使用。由于 oidc 客户端正在启动登录请求,因此我在登录页面中使用它。但是 oidc 客户端不知道对我的注册页面的请求,所以当我发回身份验证令牌时,它无法识别状态并抛出异常:'No matching state found in storage'.
我知道IdentityServer4官方不支持用户注册。我已经设置了 ASP.Net 身份注册,但如果能够在我的注册页面上添加 [第三方提供商] 注册就更好了。有什么办法可以解决这个问题吗?我可以手动设置状态并将注册请求发送给我的身份提供者吗?这样,如果用户选择登录,则 oidc 客户端将具有有效状态。还有别的办法吗?谢谢
我终于找到了解决这个问题的方法。正如我在回答中所述,oidc 客户端在本地存储中维护状态信息,以便它可以验证它是否从预期服务器获得了响应。您可以通过生成安全的随机字符串并将其保存在 localStorage 中来模拟这一点。在向您的身份验证服务器发送请求以注册新用户之前执行此操作。代码如下所示:
const nonce = this.generateUniqueString();
const state = this.generateUniqueString();
const date = new Date();
const query = `${otherQueryOptions}&state=${state}&nonce=${nonce}`;
const authSessionData = {
authority: auth_server_url,
client_id: client_id,
created: date.getTime(),
id: state,
nonce: nonce,
redirect_uri: `your/return.url`
}
// You must prefix the key with 'oidc'
localStorage.setItem(`oidc.${authSessionData.id}`, JSON.stringify(authSessionData));
const registrationPath = `myServerRegistrationPath?${query}`
navigateToPage(registrationPath);
这解决了我的问题。