首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >必须为客户端注册指定提供者ID“azure”?

必须为客户端注册指定提供者ID“azure”?
EN

Stack Overflow用户
提问于 2022-04-07 11:38:46
回答 1查看 1.2K关注 0票数 1

当我升级到SpringBoot2.6.6时,这个应用程序显示了如下错误:我的pom.xml有这个依赖项

代码语言:javascript
运行
复制
  <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-security</artifactId>
      </dependency>
      <dependency>
         <groupId>com.azure.spring</groupId>
         <artifactId>spring-cloud-azure-starter-active-directory</artifactId>
      </dependency>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-oauth2-client</artifactId>
      </dependency>
   </dependencies>
   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-dependencies</artifactId>
            <version>${spring-cloud-azure.version}</version>
            <type>pom</type>
            <scope>import</scope>
         </dependency>
      </dependencies>
   </dependencyManagement>

在我的application.properties上的这个配置:

代码语言:javascript
运行
复制
azure.activedirectory.tenant-id=*******.
spring.security.oauth2.client.registration.azure.client-id=*********.
azure.activedirectory.client-id=************.
spring.security.oauth2.client.registration.azure.client-secret=*************.
azure.activedirectory.client-secret=*************.

安全配置类是

代码语言:javascript
运行
复制
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/**").authenticated();
    http.authorizeRequests().anyRequest().permitAll();
    http.addFilterBefore(jwtTokenFilterBean(),UsernamePasswordAuthenticationFilter.class);
     http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class);
    http.csrf().disable() ;
}

这是bean类

代码语言:javascript
运行
复制
  @Bean
        public FilterRegistrationBean<CorsFilter> simpleCorsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            CorsConfiguration config = new CorsConfiguration();
            config.setAllowCredentials(true);
            config.setAllowedOrigins(Collections.singletonList("*"));
            config.setAllowedMethods(Collections.singletonList("*"));
            config.setAllowedHeaders(Collections.singletonList("*"));
            source.registerCorsConfiguration("/**", config);
            FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new 
            CorsFilter(source));
            bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
            return bean;
        }   

当我试图运行应用程序时,请给我以下错误:

代码语言:javascript
运行
复制
Caused by: java.lang.IllegalStateException: Provider ID must be specified for client registration 'azure'
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getBuilder(OAuth2ClientPropertiesRegistrationAdapter.java:95) ~[spring-boot-autoconfigure-2.6.6.jar:2.6.6]
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistration(OAuth2ClientPropertiesRegistrationAdapter.java:61) ~[spring-boot-autoconfigure-2.6.6.jar:2.6.6]
    at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.lambda$getClientRegistrations$0(OAuth2ClientPropertiesRegistrationAdapter.java:53) ~[spring-boot-autoconfigure-2.6.6.jar:2.6.6]
    at java.util.HashMap.forEach(Unknown Source) ~[?:1.8.0_65]

为什么会发生这种事?我该怎么做才能解决这个问题?

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-04-07 20:11:01

请检查应用程序属性是否配置了提供程序并为所需的api具有正确的范围。

下面提供了一些应用程序properties.Please,检查缺少的应用程序,或者是否一切都是正确的。

ex:application.properties

代码语言:javascript
运行
复制
spring.security.oauth2.client.registration.azure.client-id=XXXXXXXXXX
spring.security.oauth2.client.registration.azure.client-secret=XXXXXXXXXX
spring.security.oauth2.client.registration.azure.scope=openid,profile,email,offline_access  //here provide required scopes ex:
spring.security.oauth2.client.registration.azure.redirect-uri-template=’{baseUrl}/login/oauth2/code/{registrationId}’
spring.security.oauth2.client.registration.azure.client-name=xxxxxxxxx
spring.security.oauth2.client.registration.azure.provider=xxxxxxxxx
spring.security.oauth2.client.registration.azure.client-authentication-method=basic
spring.security.oauth2.client.registration. azure.authorization-grant-type=authorization_code

spring.security.oauth2.client.provider. azure.authorization-uri=https://login.microsoftonline.com/<tenantid>/oauth2/v2/authorize
spring.security.oauth2.client.provider. azure.token-uri= https://login.microsoftonline.com/xxxxxxxxxxxxxx/oauth2/v2/token
spring.security.oauth2.client.provider.xxxxxxxxx.user-info-uri=https://login.microsoftonline.com/xxxxxxxxxxxxxx/openid/userinfo   
spring.security.oauth2.client.provider. azure.user-name-attribute=name
spring.security.oauth2.client.provider. azure.user-info-authentication-method=header
spring.security.oauth2.client.provider. azure.jwk-set-uri=https://login.microsoftonline.com/xxxxxxxxxxxxxx/discovery/v2/keys

如果api是图api,则作用域可以是https://graph.microsoft.com/user.read,如果不是图形api,请确保公开api并给予适当的权限,并授予管理员对相同的权限。

另外,请检查清单以查看accesstokenacceptedversion,如果清单为null或1,则tr将其更改为2,反之亦然,并进行相同的配置,即;

如果v2属性spring.security.oauth2.client.provider. azure.authorization-uri=https://login.microsoftonline.com/<tenantid>/oauth2/v2/authorize

if v1 spring.security.oauth2.client.provider.azure.authorization-uri=https://login.microsoftonline.com/<tenantid>/oauth2/authorize

参考资料:

  1. spring boot -stack overflow
  2. -reduce-the-standard-scope-authorization-requst-spring-boot-sends-to-azure
  3. clientregistrationrepository-bean-is-not-found-SO
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71781499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档