使用 NodeJS,如何使用 Spring Security OAuth2 制作的 JWT 检索存储在 PostgreSQL 中的会话信息?

Using NodeJS, how can I retrieve session information stored in PostgreSQL using the JWT made by Spring Security OAuth2?

我有一个 Java spring 后端,它使用 LDAP 作为用户帐户并使用 spring-security 进行身份验证。

我还使用 spring-security-oauth2 进行客户端身份验证,并且我有一个使用 JWT 进行身份验证的客户端。

使用该 JWT,我如何使用 NodeJS 解密 JWT 并在我的数据库中检索会话信息(用户和角色)?

我也有一个X-XSRF-TOKEN我想我需要验证(cookie)。

可能吗?

I have a Java spring backend that is using LDAP for user accounts and spring-security for authentication.

I also use spring-security-oauth2 for client authentication and I have a client authenticated with a JWT.

JWT 的整体思想是它是无状态的(无会话)。如果您有一个独特的解决方案,其中会话以某种方式与 JWT 相关联,您应该包括图表或更多描述。

Using that JWT, how can I use NodeJS to decrypt the JWT and retrieve the session information (user and roles) in my database?

您可以在主题字段中使用 JsonWebToken library 和 store/retrieve 用户名(或其他类型的用户或会话标识令牌)。

I also have a X-XSRF-TOKEN I think I need to verify (cookie).

CSRF/XSRF 通常在 JWT 应用程序中被禁用(请参阅此处接受的答案 CSRF Token necessary when using Stateless(= Sessionless) Authentication?)。在 spring 引导中,中间件默认启用,但可以像这样禁用:

@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable();
    }
}