angular - 浏览器默认基本认证 spring-boot angular
问题描述
我知道有很多关于那里Angular
和basic authentication
外面的话题,我阅读了其中的大部分,但没有一个适用于我想要的行为。
我的应用程序有 2 个用例:
- 前端
spring-boot
作为静态资源打包在后端 - 前端分别在 localhost:4200 和后端分别运行在 localhost:8080
我的安全配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors()
.and().csrf().disable()
.httpBasic().authenticationEntryPoint(authEntryPoint)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.accessDecisionManager(accessDecisionManager)
.expressionHandler(expressionHandler)
.antMatchers("/api/**").authenticated()
.and()
.logout().logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
.and()
.addFilterAfter(jwtTokenFilter, BasicAuthenticationFilter.class);
}
在第一个场景中,前端和后端都在同一个端口上提供服务,我导航到http://localhost:8080/context-path
我得到浏览器的基本身份验证掩码。
但是当我转到单独运行的前端时http://localhost:4200
,我只会401 - not authenticated
弹出一个没有基本身份验证的窗口。
所以我的问题是,当前端和后端在不同的端口/网址上运行时,我怎样才能得到这个弹出窗口?或者这是不可能的?
解决方案
推荐阅读
- javascript - 对象可能为“空”。TS2531 与 TypeScript 反应
- sql - 根据字符串重写 NVL 和 select 语句
- cytoscape.js - 如何使用 cytoscape.js 中的坐标绘制折线节点
- python - 打开 CV 错误:NameError:未定义名称“left”
- excel - 结合 vba 过滤器
- c# - PHP dat 文件读取
- python - Kivy-ios:工具链构建 python3 Kivy 错误
- django - Django - get() 是懒惰的吗?
- css - Tranparent gradient to shade a div
- reactjs - Accessing API Cors in React