私はちょうどUserManager.UpdateSecurityStampAsync(user.Id);
を行うことができますか?
これは間違いありません。そのためには、トークンエンドポイントを調整して、有効なトークンレスポンスを返す前にIdentityにセキュリティスタンプの検証を依頼してください。ここでは例です:
また
[HttpPost("~/connect/token"), Produces("application/json")]
public async Task<IActionResult> Exchange(OpenIdConnectRequest request) {
// ...
if (request.IsRefreshTokenGrantType()) {
// Retrieve the claims principal stored in the refresh token.
var info = await HttpContext.Authentication.GetAuthenticateInfoAsync(
OpenIdConnectServerDefaults.AuthenticationScheme);
// Retrieve the user profile and validate the
// security stamp stored in the refresh token.
var user = await _signInManager.ValidateSecurityStampAsync(info.Principal);
if (user == null) {
return BadRequest(new OpenIdConnectResponse {
Error = OpenIdConnectConstants.Errors.InvalidGrant,
ErrorDescription = "The refresh token is no longer valid."
});
}
// Ensure the user is still allowed to sign in.
if (!await _signInManager.CanSignInAsync(user)) {
return BadRequest(new OpenIdConnectResponse {
Error = OpenIdConnectConstants.Errors.InvalidGrant,
ErrorDescription = "The user is no longer allowed to sign in."
});
}
// Create a new authentication ticket, but reuse the properties stored
// in the refresh token, including the scopes originally granted.
var ticket = await CreateTicketAsync(request, user, info.Properties);
return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);
}
// ...
}
、あなたはまた、ユーザーに関連付けられているすべてのリフレッシュトークンを取り消すOpenIddictTokenManager
を使用することができます。
foreach (var token in await manager.FindBySubjectAsync("[userid]", cancellationToken)) {
await manager.RevokeAsync(token, cancellationToken);
}
それは」を解決...しかし、私のコードは少し異なっていますなぜ、あなたは 'request.IsRefreshTokenGrantType()'について言及しましたが、 'OpenIddictTokenManager'を使って' request.IsPasswordGrantType() 'に私のコードを入れました。なぜなら、私がすべてのトークンをきれいにしなければならないと思うからです。ユーザーは新しいログインを行います。それは正しいのですか、それとも間違った方法でやっていますか? – Jedi31
最初のスニペットは、リフレッシュトークンを取り消しませんが、セキュリティスタンプが変更されたために無効になっているとみなした場合です。あなたが望むものを実現するために、2番目のスニペットを実際にパスワードトークン処理コードに入れることができます。 – Pinpoint
ありがとう! – Jedi31