简体   繁体   English

为什么要动态获取公钥以验证 JWT 令牌 (RSA-256)

[英]why to fetch public key dynamically for verifying JWT token (RSA-256)

With JWT approach we get advantage that we don't need to call auth server every time.使用 JWT 方法,我们的优势在于我们不需要每次都调用 auth 服务器。 We need public key to verify JWT token issued via RSA-256.我们需要公钥来验证通过 RSA-256 发出的 JWT 令牌。 And public keys are getting rotated (Ref - https://www.keycloak.org/docs/latest/server_admin/#rotating-keys ) and hence I have to fetch public key from auth server every time before validating the JWT token.并且公钥正在轮换(参考 - https://www.keycloak.org/docs/latest/server_admin/#rotating-keys )因此我每次都必须在验证 JWT 令牌之前从 auth 服务器获取公钥。

Then what is the advantage of having JWT, can someone help me understanding this?那么拥有 JWT 有什么好处,有人可以帮助我理解这一点吗?

Thanks @derpirscher for answer.感谢@derpirscher 的回答。 For future moving your comment as answer为了将来将您的评论作为答案

No, you don't need to fetch the key every time.不,您不需要每次都获取密钥。 The jwt should contain a keyid if the public key.如果是公钥,jwt 应该包含一个 keyid。 So when you try to validate your token, check if you have already cached the public key.因此,当您尝试验证您的令牌时,请检查您是否已经缓存了公钥。 If not fetch a new key and cache it.如果没有获取新密钥并将其缓存。 Else use the cached key.否则使用缓存的密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM