Azure-sdk-for-java: Cannot Get Access Token for Graph API

Created on 9 Sep 2020  路  12Comments  路  Source: Azure/azure-sdk-for-java

Copied from https://github.com/microsoft/azure-spring-boot/issues/931.

I'm not able to use Access Token.

@RequestMapping("/test")
public String test(OAuth2AuthenticationToken authentication) {

    final OAuth2AuthorizedClient authorizedClient =
                    this.authorizedClientService.loadAuthorizedClient(
                            authentication.getAuthorizedClientRegistrationId(),
                            authentication.getName());
          String accessToken=authorizedClient.getAccessToken().getTokenValue();

      System.out.println(Graph.getUser( accessToken));

          return "success";
}

Seems like the access token forma is wrong there aren't the .tipical of jwt token.
Are there other option to get the access token?

I produce the following error:

[INFO ] 2020-09-09 14:20:52  global                                                                           :45   : Setting logging level to ERROR
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204Graph service exception Error code: InvalidAuthenticationToken
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204Error message: CompactToken parsing failed with error code: 80049217
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204GET https://graph.microsoft.com/v1.0/me
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204SdkVersion : graph-java-v1.2.0
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204Authorization : Bearer PAQABAAAAAAAGV_bv21oQQ4ROqh[...]
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204401 : Unauthorized
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204[...]
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204
[ERROR] 2020-09-09 14:20:53  global                                                                           :108  : DefaultHttpProvider[send] - 204[Some information was truncated for brevity, enable debug logging for more details]
[ERROR] 2020-09-09 14:20:53  global                                                                           :110  : Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217

GET https://graph.microsoft.com/v1.0/me
SdkVersion : graph-java-v1.2.0
Authorization : Bearer PAQABAAAAAAAGV_bv21oQQ4ROqh[...]


401 : Unauthorized
[...]

[Some information was truncated for brevity, enable debug logging for more details]
[ERROR] 2020-09-09 14:20:53  com.synapseslab.bluegps.web.exception.WebExceptionHandler                        :31   : Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217

GET https://graph.microsoft.com/v1.0/me
SdkVersion : graph-java-v1.2.0
Authorization : Bearer PAQABAAAAAAAGV_bv21oQQ4ROqh[...]


401 : Unauthorized
[...]

[Some information was truncated for brevity, enable debug logging for more details]
com.microsoft.graph.http.GraphServiceException: Error code: InvalidAuthenticationToken
Error message: CompactToken parsing failed with error code: 80049217

GET https://graph.microsoft.com/v1.0/me
SdkVersion : graph-java-v1.2.0
Authorization : Bearer PAQABAAAAAAAGV_bv21oQQ4ROqh[...]


401 : Unauthorized
[...]

[Some information was truncated for brevity, enable debug logging for more details]
    at com.microsoft.graph.http.GraphServiceException.createFromConnection(GraphServiceException.java:339)
    at com.microsoft.graph.http.DefaultHttpProvider.handleErrorResponse(DefaultHttpProvider.java:388)
    at com.microsoft.graph.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:321)
    at com.microsoft.graph.http.DefaultHttpProvider.send(DefaultHttpProvider.java:204)
    at com.microsoft.graph.http.DefaultHttpProvider.send(DefaultHttpProvider.java:184)
    at com.microsoft.graph.http.BaseRequest.send(BaseRequest.java:277)
    at com.microsoft.graph.requests.extensions.UserRequest.get(UserRequest.java:52)
    at com.synapseslab.bluegps.platform.microsoft.Graph.getUser(Graph.java:42)
    at com.synapseslab.bluegps.web.test.HelloController.test(HelloController.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:118)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:158)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter.doFilterInternal(DefaultLogoutPageGeneratingFilter.java:52)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:216)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter.doFilterInternal(OAuth2AuthorizationRequestRedirectFilter.java:160)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Client azure-spring azure-spring-aad

Most helpful comment

Hi @fr4ncesco , could you check if you have updated the scopes with profile as well? This is because there some differences between v1 and v2 id_tokens: some attributes existing in v1 id_tokens by default don't appear in v2. And you can refer to this link for details.

spring.security.oauth2.client.registration.azure.scope=openid, https://graph.microsoft.com/user.read, profile

All 12 comments

@chenrujun could you please take a look at this?

Thanks @saragluna to move and assign the ticket

Hi, @fr4ncesco ,
I can't reproduce your problem.
Could you please try to reproduce your problem using our sample project?
You can fork this repo, update the sample project to reproduce your problem, then share your updated project to me.

Hi, @chenrujun
I'm not able to build the SDK from repository using openjdk version "14.0.2" 2020-07-14 and Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) in my project I use SDK version 2.3.2 that work for SSO with OpenID.

following my trace:

fd-macbook:spring francesco$ mvn clean install -DskipTests
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Azure Spring Boot AutoConfigure                                    [jar]
[INFO] Azure Spring Boot Starter                                          [jar]
[INFO] Azure AD Spring Security Integration Spring Boot Starter           [jar]
[INFO] Azure AD B2C Spring Security Integration Spring Boot Starter       [jar]
[INFO] Azure Cosmos DB Spring Boot Starter                                [jar]
[INFO] Spring Data Gremlin Boot Starter                                   [jar]
[INFO] Azure Key Vault Secrets Spring Boot Starter                        [jar]
[INFO] Azure Metrics Spring Boot Starter                                  [jar]
[INFO] Azure Service Bus JMS Spring Boot Starter                          [jar]
[INFO] azure-spring-boot-test-application                                 [jar]
[INFO] azure-spring-boot-test-core                                        [jar]
[INFO] azure-spring-boot-test-aad                                         [jar]
[INFO] azure-spring-boot-test-cosmosdb                                    [jar]
[INFO] azure-spring-boot-test-keyvault                                    [jar]
[INFO] azure-spring-boot-test-servicebus-jms                              [jar]
[INFO] Spring Cloud Azure Telemetry                                       [jar]
[INFO] Spring Cloud Azure Context                                         [jar]
[INFO] Azure Spring Integration Core                                      [jar]
[INFO] Azure Spring Integration Test                                      [jar]
[INFO] Azure Spring Integration Event Hubs                                [jar]
[INFO] Azure Spring Integration Service Bus                               [jar]
[INFO] Azure Spring Integration Storage Queue                             [jar]
[INFO] Azure Spring Cloud Storage                                         [jar]
[INFO] Spring Cloud Azure Autoconfigure                                   [jar]
[INFO] Azure Spring Cloud Messaging                                       [jar]
[INFO] Azure Spring Cloud Starter Event Hubs                              [jar]
[INFO] Azure Spring Cloud Stream Binder Test                              [jar]
[INFO] Azure Spring Cloud Stream Event Hubs binder                        [jar]
[INFO] azure-spring-cloud-test-eventhubs                                  [jar]
[INFO] Azure Spring Boot Starter Sample - Azure AD Spring Security Integration [jar]
[INFO] Azure Spring Boot Starter Sample - Azure AD B2C Spring Security 5 OAuth Integration [jar]
[INFO] Azure Spring Boot Starter Sample - Azure AD Spring Security Integration [jar]
[INFO] Azure Spring Boot Starter Sample - Azure AD Spring Security Integration v2 [jar]
[INFO] Azure Spring Boot Starter Sample - Azure AD Stateless Spring Security Integration [jar]
[INFO] Azure Spring Boot Starter Sample - Cosmos DB                       [jar]
[INFO] Azure Spring Boot Starter Sample - Spring Data Gremlin             [jar]
[INFO] Azure Spring Boot Starter Sample - Key Vault Secrets               [jar]
[INFO] Azure Spring Boot Starter Sample - Media Services                  [jar]
[INFO] Azure Spring Boot Starter Sample - Service Bus                     [jar]
[INFO] Azure Spring Boot Starter Sample - Service Bus JMS Queue           [jar]
[INFO] Azure Spring Boot Starter Sample - Service Bus JMS Topic           [jar]
[INFO] Azure Spring Boot Starter Sample - Storage Blob                    [jar]
[INFO] Spring Data Gremlin                                                [jar]
[INFO] azure-spring-data-sample-gremlin                                   [jar]
[INFO] Spring Data gremlin - Web Service                                  [jar]
[INFO] Azure Cloud Foundry Service Sample                                 [jar]
[INFO] Azure Spring Cloud Starter Cache                                   [jar]
[INFO] Azure Spring Cloud Cache Sample                                    [jar]
[INFO] Azure Spring Cloud App Configuration Conversion Sample             [jar]
[INFO] Azure Spring Cloud App Configuration Conversion Sample             [jar]
[INFO] Azure Spring Cloud App Configuration Sample                        [jar]
[INFO] Azure Spring Cloud Starter Storage                                 [jar]
[INFO] Azure Spring Cloud Storage Sample                                  [jar]
[INFO] Azure Spring Cloud Event Hub Operation Sample                      [jar]
[INFO] Azure Spring Cloud Event Hub Integration Sample                    [jar]
[INFO] Azure Spring Cloud Event Hub Binder Sample                         [jar]
[INFO] Azure Spring Cloud Event Hub Multiple Binders Sample               [jar]
[INFO] Azure Spring Cloud Starter Event Hubs Kafka                        [jar]
[INFO] Azure Spring Cloud Event Hub using Kafka Binder Sample             [jar]
[INFO] Azure Spring Cloud Feature Management Sample                       [jar]
[INFO] Azure Spring Cloud Feature Management Web Sample                   [jar]
[INFO] Azure Spring Cloud Starter Service Bus                             [jar]
[INFO] Azure Spring Cloud Service Bus Operation Sample                    [jar]
[INFO] Azure Spring Cloud Service Bus Integration Sample                  [jar]
[INFO] Azure Spring Cloud Stream Service Bus Binder Core                  [jar]
[INFO] Azure Spring Cloud Stream Service Bus Queue Binder                 [jar]
[INFO] Azure Spring Cloud Service Bus Queue Binder Sample                 [jar]
[INFO] Azure Spring Cloud Stream Service Bus Topic Binder                 [jar]
[INFO] Azure Spring Cloud Service Bus Topic Binder Sample                 [jar]
[INFO] Azure Spring Cloud Starter Storage Queue                           [jar]
[INFO] Azure Spring Cloud Storage Queue Operation Sample                  [jar]
[INFO] Azure Spring Cloud Storage Queue Integration Sample                [jar]
[INFO] Azure Spring Cloud Messaging Sample                                [jar]
[INFO] Azure Spring Cloud Service Bus Queue Multiple Binders Sample       [jar]
[INFO] azure-spring-boot-service                                          [pom]
[INFO] 
[INFO] ---------------< com.microsoft.azure:azure-spring-boot >----------------
[INFO] Building Azure Spring Boot AutoConfigure 2.3.5-beta.1             [1/75]
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for jakarta.activation:jakarta.activation-api:jar:1.2.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ azure-spring-boot ---
[INFO] Deleting /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target (includes = [**], excludes = [test-classes/session-records/])
[INFO] 
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (default-cli) @ azure-spring-boot ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (prepare-agent) @ azure-spring-boot ---
[INFO] argLine set to -javaagent:/Users/francesco/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ azure-spring-boot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ azure-spring-boot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 66 source files to /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/classes
[INFO] /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolver.java: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolver.java uses or overrides a deprecated API.
[INFO] /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolver.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (base-compile) @ azure-spring-boot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 66 source files to /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/classes
[INFO] /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolver.java: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolver.java uses or overrides a deprecated API.
[INFO] /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolver.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (annotation-process-for-java-11) @ azure-spring-boot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 66 source files to /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/classes
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.5:instrument (default-instrument) @ azure-spring-boot ---
[INFO] 
[INFO] --- build-helper-maven-plugin:3.0.0:add-test-source (compile-samples-source) @ azure-spring-boot ---
[INFO] Test Source directory: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/samples/java added.
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ azure-spring-boot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 23 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ azure-spring-boot ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 64 source files to /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/test-classes
[INFO] /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolverTest.java: Some input files use or override a deprecated API.
[INFO] /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/src/test/java/com/microsoft/azure/spring/autoconfigure/b2c/AADB2CAuthorizationRequestResolverTest.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ azure-spring-boot ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.5:restore-instrumented-classes (default-restore-instrumented-classes) @ azure-spring-boot ---
[INFO] 
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ azure-spring-boot ---
[INFO] Building jar: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/azure-spring-boot-2.3.5-beta.1.jar
[INFO] 
[INFO] --- maven-javadoc-plugin:3.1.1:jar (attach-javadocs) @ azure-spring-boot ---
[ERROR] Error fetching link: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/javadoc-bundle-options. Ignored it.
[INFO] Building jar: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/azure-spring-boot-2.3.5-beta.1-javadoc.jar
[INFO] 
[INFO] >>> maven-source-plugin:3.0.1:jar (attach-sources) > generate-sources @ azure-spring-boot >>>
[INFO] 
[INFO] --- maven-enforcer-plugin:3.0.0-M3:enforce (default-cli) @ azure-spring-boot ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (prepare-agent) @ azure-spring-boot ---
[INFO] argLine set to -javaagent:/Users/francesco/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/jacoco.exec
[INFO] 
[INFO] <<< maven-source-plugin:3.0.1:jar (attach-sources) < generate-sources @ azure-spring-boot <<<
[INFO] 
[INFO] 
[INFO] --- maven-source-plugin:3.0.1:jar (attach-sources) @ azure-spring-boot ---
[INFO] Building jar: /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target/azure-spring-boot-2.3.5-beta.1-sources.jar
[INFO] 
[INFO] --- maven-antrun-plugin:1.8:run (copy) @ azure-spring-boot ---
[INFO] Executing tasks

main:
     [copy] Copying 1 file to /Users/francesco/Documents/cristina/GitHub/azure-sdk-for-java/sdk/spring/azure-spring-boot/target
[INFO] Executed tasks
[INFO] 
[INFO] --- build-helper-maven-plugin:3.0.0:attach-artifact (attach-artifacts) @ azure-spring-boot ---
[INFO] 
[INFO] --- maven-checkstyle-plugin:3.1.0:check (default) @ azure-spring-boot ---
[WARNING] The POM for com.azure:sdk-build-tools:jar:1.0.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Azure Spring Boot AutoConfigure 2.3.5-beta.1 ....... FAILURE [ 20.688 s]
[INFO] Azure Spring Boot Starter 2.3.5-beta.1 ............. SKIPPED
[INFO] Azure AD Spring Security Integration Spring Boot Starter 2.3.5-beta.1 SKIPPED
[INFO] Azure AD B2C Spring Security Integration Spring Boot Starter 2.3.5-beta.1 SKIPPED
[INFO] Azure Cosmos DB Spring Boot Starter 2.3.5-beta.1 ... SKIPPED
[INFO] Spring Data Gremlin Boot Starter 2.3.5-beta.1 ...... SKIPPED
[INFO] Azure Key Vault Secrets Spring Boot Starter 2.3.5-beta.1 SKIPPED
[INFO] Azure Metrics Spring Boot Starter 2.3.5-beta.1 ..... SKIPPED
[INFO] Azure Service Bus JMS Spring Boot Starter 2.3.5-beta.1 SKIPPED
[INFO] azure-spring-boot-test-application 1.0.0 ........... SKIPPED
[INFO] azure-spring-boot-test-core 1.0.0 .................. SKIPPED
[INFO] azure-spring-boot-test-aad 1.0.0 ................... SKIPPED
[INFO] azure-spring-boot-test-cosmosdb 1.0.0 .............. SKIPPED
[INFO] azure-spring-boot-test-keyvault 1.0.0 .............. SKIPPED
[INFO] azure-spring-boot-test-servicebus-jms 1.0.0 ........ SKIPPED
[INFO] Spring Cloud Azure Telemetry 1.2.8-beta.1 .......... SKIPPED
[INFO] Spring Cloud Azure Context 1.2.8-beta.1 ............ SKIPPED
[INFO] Azure Spring Integration Core 1.2.8-beta.1 ......... SKIPPED
[INFO] Azure Spring Integration Test 1.2.8-beta.1 ......... SKIPPED
[INFO] Azure Spring Integration Event Hubs 1.2.8-beta.1 ... SKIPPED
[INFO] Azure Spring Integration Service Bus 1.2.8-beta.1 .. SKIPPED
[INFO] Azure Spring Integration Storage Queue 1.2.8-beta.1  SKIPPED
[INFO] Azure Spring Cloud Storage 1.2.8-beta.1 ............ SKIPPED
[INFO] Spring Cloud Azure Autoconfigure 1.2.8-beta.1 ...... SKIPPED
[INFO] Azure Spring Cloud Messaging 1.2.8-beta.1 .......... SKIPPED
[INFO] Azure Spring Cloud Starter Event Hubs 1.2.8-beta.1 . SKIPPED
[INFO] Azure Spring Cloud Stream Binder Test 1.2.8-beta.1 . SKIPPED
[INFO] Azure Spring Cloud Stream Event Hubs binder 1.2.8-beta.1 SKIPPED
[INFO] azure-spring-cloud-test-eventhubs 1.0.0 ............ SKIPPED
[INFO] Azure Spring Boot Starter Sample - Azure AD Spring Security Integration 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Azure AD B2C Spring Security 5 OAuth Integration 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Azure AD Spring Security Integration 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Azure AD Spring Security Integration v2 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Azure AD Stateless Spring Security Integration 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Cosmos DB 1.0.0 . SKIPPED
[INFO] Azure Spring Boot Starter Sample - Spring Data Gremlin 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Key Vault Secrets 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Media Services 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Service Bus 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Service Bus JMS Queue 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Service Bus JMS Topic 1.0.0 SKIPPED
[INFO] Azure Spring Boot Starter Sample - Storage Blob 1.0.0 SKIPPED
[INFO] Spring Data Gremlin 2.3.1-beta.1 ................... SKIPPED
[INFO] azure-spring-data-sample-gremlin 1.0.0 ............. SKIPPED
[INFO] Spring Data gremlin - Web Service 2.3.3.RELEASE .... SKIPPED
[INFO] Azure Cloud Foundry Service Sample 1.0.0 ........... SKIPPED
[INFO] Azure Spring Cloud Starter Cache 1.2.8-beta.1 ...... SKIPPED
[INFO] Azure Spring Cloud Cache Sample 1.2.8-beta.1 ....... SKIPPED
[INFO] Azure Spring Cloud App Configuration Conversion Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud App Configuration Conversion Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud App Configuration Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Starter Storage 1.2.8-beta.1 .... SKIPPED
[INFO] Azure Spring Cloud Storage Sample 1.2.8-beta.1 ..... SKIPPED
[INFO] Azure Spring Cloud Event Hub Operation Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Event Hub Integration Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Event Hub Binder Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Event Hub Multiple Binders Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Starter Event Hubs Kafka 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Event Hub using Kafka Binder Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Feature Management Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Feature Management Web Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Starter Service Bus 1.2.8-beta.1  SKIPPED
[INFO] Azure Spring Cloud Service Bus Operation Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Service Bus Integration Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Stream Service Bus Binder Core 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Stream Service Bus Queue Binder 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Service Bus Queue Binder Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Stream Service Bus Topic Binder 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Service Bus Topic Binder Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Starter Storage Queue 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Storage Queue Operation Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Storage Queue Integration Sample 1.2.8-beta.1 SKIPPED
[INFO] Azure Spring Cloud Messaging Sample 1.2.8-beta.1 ... SKIPPED
[INFO] Azure Spring Cloud Service Bus Queue Multiple Binders Sample 1.2.8-beta.1 SKIPPED
[INFO] azure-spring-boot-service 1.0.0 .................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  22.084 s
[INFO] Finished at: 2020-09-10T11:01:38+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (default) on project azure-spring-boot: Execution default of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check failed: Plugin org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0 or one of its dependencies could not be resolved: Failure to find com.azure:sdk-build-tools:jar:1.0.0 in https://oss.sonatype.org/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of ossrh has elapsed or updates are forced -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

Just some indication other indication:

If I use POSTMAN with a call like https://login.microsoftonline.com/{{TenantID}}/oauth2/v2.0/tokenI receive the following access token:

{
    "token_type": "Bearer",
    "scope": "email openid profile https://graph.microsoft.com/Calendars.Read https://graph.microsoft.com/Calendars.Read.Shared <... etc >",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "eyJ0eXAiOiJKV1QiLCJub25jZSI6InVsNWVfTl9yWnpLWFhQbDVNWmNqTTBGY25GUzdCLXlpQjJBT2xNSVQ5Wm8iLCJhbGciOiJSUzI1NiIsIng1dCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyIsImtpZCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyJ9.<body>.<signature>",
    "id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImppYk5ia0ZTU2JteFBZck45Q0ZxUms0SzRndyJ9.<body>.<signature>"
}

Instead from SDK version 2.3.3. with following code:

    @RequestMapping("/test")
    public String test(OAuth2AuthenticationToken authentication) {

         final OAuth2AuthorizedClient authorizedClient =
                    this.authorizedClientService.loadAuthorizedClient(
                            authentication.getAuthorizedClientRegistrationId(),
                            authentication.getName());

        return authorizedClient.getAccessToken().getTokenValue();
    }

I print a token like:

PAQABAAAAAAAGV_bv21oQQ4ROqh0_1-tAT018lkU9G4IukPUM0plEuO3YN_MoXrwx3tvZNrkz_YRweYAtFBOEOp2Kx... <(next omitted>

Not in JWT format.
The idToken is in the right format.

Hi, @fr4ncesco .

I'm not able to build the SDK from repository

You do not need to build them all, just build target sample project and it's related project.

Not in JWT format.

I tried your code in this sample PR, the value is a valid JWT.

Hi @fr4ncesco , thanks for your reporing. The azure-active-directory-spring-boot-starter uses AAD v1.0 endpoints for default and uses spring security oauth2 to implement the authorization process. And we find that the authorization request constructed by spring oauth2 are not compromised with AAD v1.0 authorization endpoint, which results in the access token cannot be base64 decoded but the whole oauth process can still work.

So you could update the default AAD endpoints to v2.0 if possible, and here is our PR to update endpoints.

Besides, would you share the reason why you need to parse the access token? For most of the cases, I think ID token can meet the requirements.

Hello @yiliuTo
thanks for the fix I'll check the behaviur and provide you feedback.

About your question I need to access GraphAPI like
https://graph.microsoft.com/v1.0/me/events
https://graph.microsoft.com/v1.0/me

Using postman collection I saw that I need the access token to access this kind of API.
Is it possible in different way and though Azure Spring Boot SDK?

Thanks for the help.

Hi @fr4ncesco , yes Microsoft Graph API requires access tokens to allow access of the resource.

And you can refer to our sample for the usage of azure-active-directory-spring-boot-starter to access Microsoft Graph API. Please refer to this link to see the detailed App permissions you will need.

Thanks @yiliuTo.

I just tested your fix with Auth2.0 API and it work as expected.

Thanks.

About the App Permission I able to perform all the task trough postman so I think now I can do all also through API.

Thanks for the perfect support.

Just last question I tried to implement the fix also with the version on public maven of the SDK v2.3.5 but if I change my application.yaml as follow

spring:
  security:
    oauth2:
      client:
        provider:
          azure:
            authorization-uri: https://login.microsoftonline.com/common/oauth2/v2.0/authorize
            token-uri: https://login.microsoftonline.com/common/oauth2/v2.0/token
            user-info-uri: https://graph.microsoft.com/oidc/userinfo
            jwk-set-uri: https://login.microsoftonline.com/common/discovery/v2.0/keys

The SDK v2.3.5 give me the following error:

[ERROR] 2020-09-21 10:42:23  com.microsoft.aad.msal4j.ConfidentialClientApplication                           :145  : [Correlation ID: 6874fe0d-cb55-47da-9f3d-3ea6aadfeed6] Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed.
com.microsoft.aad.msal4j.MsalInteractionRequiredException: AADSTS50058: A silent sign-in request was sent but no user is signed in.
Trace ID: 50923e43-e44f-42a6-b11f-cb1255e23e00
Correlation ID: 6874fe0d-cb55-47da-9f3d-3ea6aadfeed6
Timestamp: 2020-09-21 08:42:23Z
....... complete trace omitted

Is it possible to use public maven version or I have to wait for an update?

Hi @fr4ncesco , could you check if you have updated the scopes with profile as well? This is because there some differences between v1 and v2 id_tokens: some attributes existing in v1 id_tokens by default don't appear in v2. And you can refer to this link for details.

spring.security.oauth2.client.registration.azure.scope=openid, https://graph.microsoft.com/user.read, profile

Perfect! :-D

It work also on v2.3.5

@saragluna for me the issue is completely solved feel free to close it.

Was this page helpful?
0 / 5 - 0 ratings