spring-boot - 使用 spring security oauth2 保护 Rest-API(Spring Security + OAuth2 + Spring Boot + STATELESS)
问题描述
我有一个 Spring-Boot 后端,它应该是一个 REST-API。我想支持社交登录。
如果我使用 Spring-Security Oauth2 Client,该类HttpSessionOAuth2AuthorizationRequestRepository
将用于在会话中存储授权请求。
http.cors();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.csrf().disable();
http.formLogin().disable();
http.httpBasic().disable();
http.addFilterBefore(tokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
http.authorizeRequests().antMatchers("/auth/**").authenticated();
http.exceptionHandling().authenticationEntryPoint(new RestAuthenticationEntryPoint());
http.oauth2Login().authorizationEndpoint().baseUri("/oauth2/authorization")
有一些解决方案使用AuthorizationRequestRepository
基于 cookie 的自定义。例如这个
然而 jgrandja 在他的评论中提到,使用 aHttpCookieRequestRepository
不会使其完全无状态,因为在 Auth-Code-Flow 期间几乎没有其他机制正在使用HttpSession
. 出于该目的使用 cookie 也可能存在一些安全漏洞。
- 如果我
HttpSessionOAuth2AuthorizationRequestRepository
用于此登录目的,API-Backend 是否仍被视为 REST? - 替代方案会是什么样子?
解决方案
推荐阅读
- c# - 带有圆角的 C# WPF ComboBox IsMouseOver 不起作用
- google-maps - 没有 Google 帐单详细信息会破坏地图吗?
- google-cloud-platform - BigQuery 中的并发查询是什么?
- unit-testing - 无论存根权限如何,带有 checkPermission 的 Apache shiro 单元测试都会通过
- typescript - TypeScript 方括号的名称?
- arduino - ESP8266 EEPROM 或 FLASH 错误:使用虚假凭据成功连接到 Wifi
- numpy - Dask 数组 from_npy_stack 缺少信息文件
- twilio - Twilio 使用 REST API 删除子账户中的频道
- laravel - Laravel - 导入新的 Vue 组件
- c - 无法解决如何将函数作为参数传递