何时为 oauth2 流程中的非交互式客户端请求新的 access_token?

When to request new access_token for non interactive clients in oauth2 flow?

我有与非交互式客户端相关的问题,例如基于 oauth2 流程的后端应用程序。

https://auth0.com/docs/api-auth/grant/client-credentials

根据非交互式客户端的 oauth2,流程是:

基于此,我的问题是:

Backend applications should store the access_token locally or request a new access_token for the same client each time the client uses the application?

对于客户端凭据授予流程,决定是频繁续订还是 "cache" 返回的 JWT 访问令牌将取决于您的要求 - 例如,如果范围经常更改,则获取新的可能有意义经常访问令牌以确保反映这些更改。从个人经验来看,通常情况并非如此,因此在令牌过期期间缓存令牌是有意义的,并且可以节省对 Auth0 的额外调用以在每次请求时获取新令牌。

If access_token is stored locally what happened with expiration time?

您可以选择每次请求前检查过期时间,过期后获取新的access token,或者不做检查直接尝试使用access token,收到后再尝试续订使用现有令牌时失败。

Access_token for non interactive clients should have the same expiration time compared with access_token for interactive users (login web) ?

与第一个问题类似。由于使用客户端凭证授权流程通常表示机密/受信任的客户端(您正在存储客户端秘密)——并且经常用于机器对机器的场景——使用更长的到期时间可能是有意义的。但是,如前所述,如果范围可能会发生变化等,那么短期到期会导致更快地获取配置更改(范围)。