对于少数微服务的后端,我有API网关(Spring ),在此我想验证用户从前端发送的azure令牌在路由微服务之前是否有效。到目前为止,无论是否添加有效的令牌,我都只能得到401响应。
我的安全配置类:
@EnableWebFluxSecurity
public class SecurityConfiguration {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeExchange(exchanges -> exchanges
.anyExchange().authenticated()
)
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(withDefaults())
);
return http.build();
}
}Application.properties
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://login.microsoftonline.com/{tenant_id}/v2.0pom.xml
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter-active-directory-b2c</artifactId>
</dependency>如果我已经有了访问令牌,并且只想在传递到服务之前在网关上验证它,我就找不到任何帮助。
发布于 2022-08-29 16:11:53
如果登录/身份验证是通过azure活动目录进行的,请检查将以下com.azure.spring : spring-cloud-azure-starter-active-directory maven依赖项添加到pom.xml文件中。
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter-active-directory</artifactId>
<version>4.3.0</version>
</dependency>v2 endpoint,则accessTokenAcceptedVersion应设置为2,否则将设置为0或1。

另外,尝试给一些时间,并请检查解码令牌的受众是否等于应用程序的clientId或appId uri,以及是否授予范围管理许可。
此外,请检查this SO reference
https://stackoverflow.com/questions/73520392
复制相似问题