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

I had to change redirect URIs from http to https to make it work partially #38

Closed kxying-kk closed 4 years ago

kxying-kk commented 4 years ago

When I clicked “Call Obo Api” button, I got the following exception in web application, obo application did not even get the request.

2020-03-22 15:17:05.967 DEBUG 14396 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : GET "/obo_api", parameters={} 2020-03-22 15:17:05.968 DEBUG 14396 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.web.servlet.ModelAndView com.microsoft.azure.msalwebsample.AuthPageController.callOboApi(javax.servlet.http.HttpServletRequest) throws java.lang.Throwable 2020-03-22 15:17:06.294 INFO 14396 --- [onPool-worker-2] com.microsoft.aad.msal4j.HttpHelper : [Correlation ID: 166dac79-de19-46a2-8bef-a321a40fa338] Sent (166dac79-de19-46a2-8bef-a321a40fa338) Correlation Id is not same as received (null). 2020-03-22 15:17:06.295 ERROR 14396 --- [onPool-worker-2] c.m.a.m.ConfidentialClientApplication : [Correlation ID: 166dac79-de19-46a2-8bef-a321a40fa338] Execution of class com.microsoft.aad.msal4j.AcquireTokenSilentSupplier failed.

com.microsoft.aad.msal4j.MsalInteractionRequiredException: AADSTS70000: The request was denied because one or more scopes requested are unauthorized or expired. The user must first sign in and grant the client application access to the requested scope. Trace ID: 490593c9-cb73-499c-b824-36ddc62a0200 Correlation ID: 166dac79-de19-46a2-8bef-a321a40fa338 Timestamp: 2020-03-22 19:17:07Z at com.microsoft.aad.msal4j.MsalServiceExceptionFactory.fromHttpResponse(MsalServiceExceptionFactory.java:37) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.TokenRequestExecutor.createAuthenticationResultFromOauthHttpResponse(TokenRequestExecutor.java:81) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.TokenRequestExecutor.executeTokenRequest(TokenRequestExecutor.java:36) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.ClientApplicationBase.acquireTokenCommon(ClientApplicationBase.java:92) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:52) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AcquireTokenSilentSupplier.execute(AcquireTokenSilentSupplier.java:50) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:59) [msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:17) [msal4j-1.3.0.jar:1.3.0] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) [na:1.8.0_241] at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596) [na:1.8.0_241] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [na:1.8.0_241] at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [na:1.8.0_241] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [na:1.8.0_241] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [na:1.8.0_241]

then I tried to create a new application role “access_as_application” by following the link below. Then changed corresponding configuration in both application.properties https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-protected-web-api-app-registration

then I got a different exception when I clicked “Call Obo Api” button

2020-03-22 15:50:36.971 ERROR 18640 --- [onPool-worker-1] c.m.a.m.ConfidentialClientApplication : [Correlation ID: 8645bd27-6ad8-41ea-b0ec-ce6212d19e1b] Execution of class com.microsoft.aad.msal4j.AcquireTokenSilentSupplier failed.

com.microsoft.aad.msal4j.MsalServiceException: AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope 'openid profile offline_access api://5d8c32ac-7277-4286-9706-207a4733a594/access_as_application' does not exist. Trace ID: 63848667-8bc5-46f6-aee8-d733f8800200 Correlation ID: 8645bd27-6ad8-41ea-b0ec-ce6212d19e1b Timestamp: 2020-03-22 19:50:38Z at com.microsoft.aad.msal4j.MsalServiceExceptionFactory.fromHttpResponse(MsalServiceExceptionFactory.java:43) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.TokenRequestExecutor.createAuthenticationResultFromOauthHttpResponse(TokenRequestExecutor.java:81) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.TokenRequestExecutor.executeTokenRequest(TokenRequestExecutor.java:36) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.ClientApplicationBase.acquireTokenCommon(ClientApplicationBase.java:92) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:52) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AcquireTokenSilentSupplier.execute(AcquireTokenSilentSupplier.java:50) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:59) [msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:17) [msal4j-1.3.0.jar:1.3.0] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) [na:1.8.0_241] at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596) [na:1.8.0_241] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [na:1.8.0_241] at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) [na:1.8.0_241] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) [na:1.8.0_241] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) [na:1.8.0_241]

2020-03-22 15:50:36.979 DEBUG 18640 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Failed to complete request: com.microsoft.aad.msal4j.MsalServiceException: AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope 'openid profile offline_access api://5d8c32ac-7277-4286-9706-207a4733a594/access_as_application' does not exist. Trace ID: 63848667-8bc5-46f6-aee8-d733f8800200 Correlation ID: 8645bd27-6ad8-41ea-b0ec-ce6212d19e1b Timestamp: 2020-03-22 19:50:38Z 2020-03-22 15:50:36.982 ERROR 18640 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.microsoft.aad.msal4j.MsalServiceException: AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope 'openid profile offline_access api://5d8c32ac-7277-4286-9706-207a4733a594/access_as_application' does not exist. Trace ID: 63848667-8bc5-46f6-aee8-d733f8800200 Correlation ID: 8645bd27-6ad8-41ea-b0ec-ce6212d19e1b Timestamp: 2020-03-22 19:50:38Z] with root cause

com.microsoft.aad.msal4j.MsalServiceException: AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope 'openid profile offline_access api://5d8c32ac-7277-4286-9706-207a4733a594/access_as_application' does not exist. Trace ID: 63848667-8bc5-46f6-aee8-d733f8800200 Correlation ID: 8645bd27-6ad8-41ea-b0ec-ce6212d19e1b Timestamp: 2020-03-22 19:50:38Z at com.microsoft.aad.msal4j.MsalServiceExceptionFactory.fromHttpResponse(MsalServiceExceptionFactory.java:43) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.TokenRequestExecutor.createAuthenticationResultFromOauthHttpResponse(TokenRequestExecutor.java:81) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.TokenRequestExecutor.executeTokenRequest(TokenRequestExecutor.java:36) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.ClientApplicationBase.acquireTokenCommon(ClientApplicationBase.java:92) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:52) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AcquireTokenSilentSupplier.execute(AcquireTokenSilentSupplier.java:50) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:59) ~[msal4j-1.3.0.jar:1.3.0] at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:17) ~[msal4j-1.3.0.jar:1.3.0] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) ~[na:1.8.0_241] at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1596) ~[na:1.8.0_241] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_241] at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_241] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_241] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_241]

2020-03-22 15:50:36.988 DEBUG 18640 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for GET "/error", parameters={} 2020-03-22 15:50:36.988 DEBUG 18640 --- [nio-8080-exec-7] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.web.servlet.ModelAndView com.microsoft.azure.msalwebsample.ErrorHandlerController.returnErrorPage(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2020-03-22 15:50:36.989 DEBUG 18640 --- [nio-8080-exec-7] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, /;q=0.8] 2020-03-22 15:50:36.992 DEBUG 18640 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 500 2020-03-22 15:50:39.929 DEBUG 18640 --- [on(3)-127.0.0.1] o.s.c.e.PropertySourcesPropertyResolver : Found key 'local.server.port' in PropertySource 'server.ports' with value of type Integer

can anybody help me my issues?

thanks Kelly

sangonzal commented 4 years ago

Duplicate of https://github.com/Azure-Samples/ms-identity-java-webapi/issues/8