Spring验证两种类型的客户端

时间:2019-08-21 12:03:01

标签: java spring spring-boot spring-security spring-data-jpa

如何在同一路径/api上使用会话cookie(启用了csrf)和使用令牌(禁用了csrf)来对Web客户端进行身份验证,而不必为每种客户端类型创建两个不同的API?

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    //Cookie based auth for react app
    auth.userDetailsService(detailService).passwordEncoder(passwordEncoder());

   //Token based auth for mobile app
} 

例如,向/api/privatedata发出请求可以检查用户是否正在使用会话cookie或令牌,验证用户身份并在用户正在使用令牌时自动禁用csrf。

0 个答案:

没有答案