由于没有身份验证标头,因此无法连接到漫游器

问题描述

我正在使用“ com.microsoft.bot:bot-integration-spring:4.6.0-preview6”,由于以下响应,无法连接到bot:没有Auth Header。需要验证。

我正在尝试使用连接到本地主机的Bot Framework仿真器在本地测试我的机器人。

这不是一个自己的实现,我只是在使用以下示例:https://github.com/microsoft/botbuilder-java/tree/master/samples/02.echo-bot

这是堆栈跟踪:

2020-08-18 14:35:43.018  INFO 16852 --- [           main] io.viascom.malkin.MalkinApplication      : Starting MalkinApplication on DESKTOP-AHGVLFT with PID 16852 (C:\Development\repos\malkin\build\classes\java\main started by stankovic in C:\Development\repos\malkin)
2020-08-18 14:35:43.020  INFO 16852 --- [           main] io.viascom.malkin.MalkinApplication      : No active profile set,falling back to default profiles: default
2020-08-18 14:35:43.703  INFO 16852 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-08-18 14:35:43.711  INFO 16852 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-08-18 14:35:43.712  INFO 16852 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-08-18 14:35:43.823  INFO 16852 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-08-18 14:35:43.823  INFO 16852 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 769 ms
2020-08-18 14:35:44.044  INFO 16852 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: ServletContext resource [/index.html]
2020-08-18 14:35:44.413  INFO 16852 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-08-18 14:35:44.421  INFO 16852 --- [           main] io.viascom.malkin.MalkinApplication      : Started MalkinApplication in 1.727 seconds (JVM running for 2.761)
2020-08-18 14:36:08.538  INFO 16852 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring dispatcherServlet 'dispatcherServlet'
2020-08-18 14:36:08.538  INFO 16852 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-08-18 14:36:08.543  INFO 16852 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Completed initialization in 5 ms
2020-08-18 14:36:08.663 ERROR 16852 --- [nio-8080-exec-1] c.m.b.integration.spring.BotController   : Exception handling message

java.util.concurrent.CompletionException: com.microsoft.bot.connector.authentication.AuthenticationException: No Auth Header. Auth is required.
    at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:314) ~[na:na]
    at java.base/java.util.concurrent.CompletableFuture.uniapplyNow(CompletableFuture.java:683) ~[na:na]
    at java.base/java.util.concurrent.CompletableFuture.uniapplyStage(CompletableFuture.java:658) ~[na:na]
    at java.base/java.util.concurrent.CompletableFuture.thenApply(CompletableFuture.java:2165) ~[na:na]
    at com.microsoft.bot.connector.authentication.JwtTokenValidation.authenticateRequest(JwtTokenValidation.java:66) ~[bot-connector-4.6.0-preview6.jar:4.6.0-preview6]
    at com.microsoft.bot.builder.BotFrameworkAdapter.processActivity(BotFrameworkAdapter.java:433) ~[bot-builder-4.6.0-preview6.jar:4.6.0-preview6]
    at com.microsoft.bot.integration.BotFrameworkHttpAdapter.processIncomingActivity(BotFrameworkHttpAdapter.java:72) ~[bot-integration-core-4.6.0-preview6.jar:4.6.0-preview6]
    at com.microsoft.bot.integration.spring.BotController.incoming(BotController.java:84) ~[bot-integration-spring-4.6.0-preview6.jar:4.6.0-preview6]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
    at org.springframework.web.method.support.invocableHandlerMethod.doInvoke(invocableHandlerMethod.java:190) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.method.support.invocableHandlerMethod.invokeForRequest(invocableHandlerMethod.java:138) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletinvocableHandlerMethod.invokeAndHandle(ServletinvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.dispatcherServlet.dodispatch(dispatcherServlet.java:1040) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.dispatcherServlet.doService(dispatcherServlet.java:943) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.tomcat.util.net.socketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]
Caused by: com.microsoft.bot.connector.authentication.AuthenticationException: No Auth Header. Auth is required.
    at com.microsoft.bot.connector.authentication.JwtTokenValidation.lambda$authenticateRequest$0(JwtTokenValidation.java:75) ~[bot-connector-4.6.0-preview6.jar:4.6.0-preview6]
    at java.base/java.util.concurrent.CompletableFuture.uniapplyNow(CompletableFuture.java:680) ~[na:na]
    ... 56 common frames omitted

有人知道如何解决此问题吗?

解决方法

通过仔细阅读手册并完成将机器人与仿真器连接的以下步骤。

配置仿真器进行身份验证

如果机器人需要身份验证并显示登录对话框,则必须如下所示配置模拟器。

使用登录验证码

  1. 启动模拟器。
  2. 在模拟器中,单击左下方的齿轮图标,或在右上方单击“模拟器设置”标签。
  3. 通过使用OAuthCard的登录验证码来选中此框。
  4. 选中“绕过ngrok”复选框以获取本地地址
  5. 单击“保存”按钮。

https://docs.microsoft.com/en-us/azure/bot-service/bot-service-debug-emulator?view=azure-bot-service-4.0&tabs=csharp#configure-the-emulator-for-authentication