Azure-Samples / ms-identity-java-webapp

A Java web application calling Microsoft graph that is secured using the Microsoft identity platform
MIT License
118 stars 105 forks source link

Issue in ms-identity-java-webapp: Failed to validate data received from Authorization service - could not validate state #57

Closed Ranbir-Sinha closed 3 years ago

Ranbir-Sinha commented 3 years ago

I downloaded ms-identity-java-webapp archive and updated the application.properties file with the Azure AD details. When I started the Spring Boot application, I got a login page. After clicking login button, I got a microsoft login page and after logging in with the user account, I got the following log lines with an error page:

:: Spring Boot :: (v2.1.4.RELEASE)

2020-09-23 16:53:06.982 INFO 708 --- [ main] c.m.a.m.MsalWebSampleApplication : Starting MsalWebSampleApplication on LT497530 with PID 708 (C:\Users\rasinha\Downloads\ms-identity-java-webapp-master\msal-java-webapp-sample\target\classes started by rasinha in C:\Users\rasinha\Downloads\ms-identity-java-webapp-master\msal-java-webapp-sample) 2020-09-23 16:53:06.985 INFO 708 --- [ main] c.m.a.m.MsalWebSampleApplication : No active profile set, falling back to default profiles: default 2020-09-23 16:53:08.466 INFO 708 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2020-09-23 16:53:08.497 INFO 708 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-09-23 16:53:08.497 INFO 708 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17] 2020-09-23 16:53:08.646 INFO 708 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-09-23 16:53:08.647 INFO 708 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1613 ms 2020-09-23 16:53:08.967 INFO 708 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :

Using generated security password: 970ff480-0c7d-4cd0-b657-000c23a68ab4

2020-09-23 16:53:09.148 INFO 708 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6813a331, org.springframework.security.web.context.SecurityContextPersistenceFilter@27494e46, org.springframework.security.web.header.HeaderWriterFilter@68105edc, org.springframework.security.web.csrf.CsrfFilter@6e4ea0bd, org.springframework.security.web.authentication.logout.LogoutFilter@3e598df9, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1e411d81, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@75504cef, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@1bd81830, org.springframework.security.web.session.SessionManagementFilter@470a9030, org.springframework.security.web.access.ExceptionTranslationFilter@28782602] 2020-09-23 16:53:09.373 INFO 708 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 2020-09-23 16:53:09.561 INFO 708 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index 2020-09-23 16:53:09.710 INFO 708 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2020-09-23 16:53:09.715 INFO 708 --- [ main] c.m.a.m.MsalWebSampleApplication : Started MsalWebSampleApplication in 3.211 seconds (JVM running for 4.717) 2020-09-23 16:53:29.556 INFO 708 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet' 2020-09-23 16:53:29.556 INFO 708 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2020-09-23 16:53:29.562 INFO 708 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms Failed to validate data received from Authorization service - could not validate state

Has anyone faced this issue? How can I resolve this?

Capture_MSAL
Ranbir-Sinha commented 3 years ago

Workaround: keytool -genkeypair -alias testCert -keyalg RSA -storetype PKCS12 -keystore keystore.p12 -storepass password

application.properties file server.port=8443 server.servlet.session.cookie.secure=true server.ssl.key-store=classpath:keystore.p12 server.ssl.key-store-password=password server.ssl.key-store-type=PKCS12 server.ssl.key-alias=testCert

sean-m-oleary commented 2 years ago

Workaround: keytool -genkeypair -alias testCert -keyalg RSA -storetype PKCS12 -keystore keystore.p12 -storepass password

application.properties file server.port=8443 server.servlet.session.cookie.secure=true server.ssl.key-store=classpath:keystore.p12 server.ssl.key-store-password=password server.ssl.key-store-type=PKCS12 server.ssl.key-alias=testCert

Can you explain what this does? As in the root issue and why this solved it? I have the same error.