简体   繁体   English

Spring社交:OAuthException:响应正文不正确。 无法从中提取令牌

[英]Spring Social : OAuthException: Response body is incorrect. Can't extract a token from this

Can any one help me on this, please 请允许任何人帮助我

I get the following exception when I try to parse Facebook token, using spring social 当我尝试使用spring social解析Facebook令牌时,我得到以下异常

org.scribe.exceptions.OAuthException: Response body is incorrect. org.scribe.exceptions.OAuthException:响应正文不正确。 Can't extract a token from this: 无法从中提取令牌:

This is my code : 这是我的代码:

 @RequestMapping(value = "/callback", method = RequestMethod.GET)
    @ResponseBody
    public String postOnWall(@RequestParam("code") String code,
                             @RequestParam("state") String state, HttpServletRequest request,
                             HttpServletResponse response) throws Exception {

        OAuthService oAuthService = facebookServiceProvider.getService();
        Verifier verifier = new Verifier(code);

        Token accessToken = oAuthService
                .getAccessToken(Token.empty(), verifier); // here is the error

        FacebookTemplate template = new FacebookTemplate(accessToken.getToken());
        String userId = template.userOperations().getUserProfile().getId();

        Logger.logInfo(this.getClass(), "Logged in User Id : {}" + userId);

        MultiValueMap<String, Object> map = facebookUtil
                .publishLinkWithVisiblityRestriction(state);
        try {
            template.publish(userId,"feed", map);
        } catch (Exception ex) {
            Logger.logError(this.getClass(),
                    "Exception Occurred while posting a link on facebook for user Id : {}, exception is : {}",
                    ex);
            return PUBLISH_ERROR;
        }
        return PUBLISH_SUCCESS;
    }

I get the error on this line of code 我在这行代码中得到了错误

Token accessToken = oAuthService
                .getAccessToken(Token.empty(), verifier);

this is my pom.xml 这是我的pom.xml

 <!-- Spring Social -->
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-config</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-core</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-security</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-web</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.scribe</groupId>
            <artifactId>scribe</artifactId>
            <version>1.3.2</version>
        </dependency>

full Exception : 完全例外:

02-Sep-2018 01:53:40.113 SEVERE [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [action-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"access_token":"tkL7oLZCXeqasLloDyiToMp5nVaK7vSFveDc3M60sk7VmcHD8XsSdcpPtlZBBZAN7fKGlSZBgLdL9zoEnu3NyMVMZAZB2ERCAhm64YEiR5oRLuc1lIHZBOwlDkuJxIt7lJmHVO8d","token_type":"bearer","expires_in":5182686}'] with root cause
 org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract a token from this: '{"access_token":"tkL7oLZCXeqasLloDyiToMp5nVaK7vSFveDc3M60sk7VmcHD8XsSdcpPtlZBBZAN7fKGlSZBgLdL9zoEnu3NyMVMZAZB2ERCAhm64YEiR5oRLuc1lIHZBOwlDkuJxIt7lJmHVO8d","token_type":"bearer","expires_in":5182686}'
    at org.scribe.extractors.TokenExtractor20Impl.extract(TokenExtractor20Impl.java:33)
    at org.scribe.oauth.OAuth20ServiceImpl.getAccessToken(OAuth20ServiceImpl.java:37)
    at com.test.controller.FacebookController.postOnWall(FacebookController.java:79)
    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:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    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:52)
    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:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    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:316)
    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:330)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:149)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    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:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
    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)

You're using a really old version of scribe that expects the token response in a completely different format! 你正在使用一个非常古老的scribe版本,它希望令牌响应的格式完全不同!

The newest version is 5.5.0 and not 1.3.2 (the second link points you to the later version, with a changed groupId and artifactId . 最新版本是5.5.0而不是1.3.2 (第二个链接指向更高版本,更改了groupIdartifactId

The example they provide is one way to solve your problem. 他们提供示例是解决问题的一种方法。 Spring also has the necessary tools to be able to do this. Spring还拥有必要的工具来实现这一目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 客户端发送的请求在语法上不正确。 春季后端 - The request sent by the client was syntactically incorrect. Spring Backend 客户端发送的请求在语法上是不正确的。 在春天使用@RequestParam - The request sent by the client was syntactically incorrect. using @RequestParam in spring 客户端发送的请求在语法上不正确。 在@ManyToOne关系中休眠,春季 - The request sent by the client was syntactically incorrect. in @ManyToOne relation Hibernate, Spring Spring webclient如何多次提取响应体 - Spring webclient how to extract response body multiple times 无法从Spring Controller中的http帖子正文读取参数 - Can't read parameters from http post body in Spring Controller spring webflux:如何发送Mono <T> 在身体插入器的反应体 - spring webflux: how to send Mono<T> in response body with body inserters Spring Boot可以将Xml响应主体转换为Java对象,但是不能将Java对象转换为Xml请求主体 - Spring Boot can convert Xml response body to Java object, but can't convert Java object to Xml request body 使用OAuth令牌的Spring Social登录 - Spring Social login with OAuth token Spring HttpClientErrorException没有提供响应主体的详细信息 - Spring HttpClientErrorException provides no details from response body Spring ResponseEntity&AJAX错误函数:无法访问响应正文内容 - Spring ResponseEntity & AJAX error function: can't access response body content
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM