Java LinkedIn登录与Spring MVC web应用程序的集成
我是Spring新手,我想登录Spring MVC应用程序。与LinkedIn合作, 我使用SCRIBE登录,但当我运行应用程序时,它会抛出一个异常Java LinkedIn登录与Spring MVC web应用程序的集成,java,spring,spring-mvc,scribe,Java,Spring,Spring Mvc,Scribe,我是Spring新手,我想登录Spring MVC应用程序。与LinkedIn合作, 我使用SCRIBE登录,但当我运行应用程序时,它会抛出一个异常 <bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider"> <constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" /> &
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
我在MVC中的linkedin控制器代码如下:
@RequestMapping(value="/loginlinkedin", method=RequestMethod.GET)
public String callback(WebRequest request){
OAuthService service=linkedInServiceProvider.getService();
System.out.println("above request token");
//request token
Token requestToken=service.getRequestToken();
System.out.println(requestToken);
System.out.println("below request token");
//getting authorized url
String oauth_verif= service.getAuthorizationUrl(requestToken);
System.out.println(oauth_verif);
//verifing the requested token
Verifier verifier=new Verifier(in.nextLine());
System.out.println("below verifier"+verifier);
//get AccessToken
Token accessToken=service.getAccessToken(requestToken, verifier);
System.out.println("access tolen"+accessToken);
OAuthRequest oauthRequest=new OAuthRequest(Verb.GET, "http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,headline)");
System.out.println("outhrequest"+oauthRequest);
service.signRequest(accessToken, oauthRequest);
Response outhResponse=oauthRequest.send();
System.out.println(outhResponse.getBody());
//ModelAndView mav=new ModelAndView("redirect:loginPage");
return "result";
}
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
和链接登录的bean:
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
和OAuthServiceProvider类,用于使用linkedInServiceProvider.getService方法向OAuthService提供服务:
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
但当我登录到应用程序时,引发的异常是:
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
May 28, 2015 5:42:17 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [HelloWebHandler] in context with path [/SpringHandler] threw exception [Request processing failed; nested exception is org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=permission_unknown'] with root cause
org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=permission_unknown'
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:104)
at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:85)
at org.scribe.oauth.OAuth10aServiceImpl.getAccessToken(OAuth10aServiceImpl.java:90)
at com.spring.handler.UserController.callback(UserController.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
权限\未知:用户尚未决定是否允许
此使用者无法访问受保护的资源。通常发生在
使用者在用户完成授权之前请求访问令牌
过程
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
要跟踪并解决您的问题,请执行以下操作:
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
在ServiceBuilder上执行调试方法时启用scribe调试模式。
仔细阅读scribe java中的
检查您的代码是否存在不一致:
//正在验证请求的令牌
验证者验证者=新验证者in.nextLine;
System.out.PrintLNbellow验证器+验证器;
里面有什么?您必须验证请求令牌,就像您从scribe示例中复制了这一行一样,无论如何,很难相信您的代码能够工作,因为in没有声明
<bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider">
<constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" />
</bean
重建控制器:首先实现启动身份验证方法,获取或存储请求令牌属性,并重定向到授权url linkedin url(如果其需要服务)。getAuthorizationUrl;实现您的回调方法,在用户批准对其配置文件的访问后,他将被重定向到您的OAuthServiceConfig类中定义的回调端点,并获取oauth_验证器和请求令牌,以验证和获取accessToken,存储它,签署请求。。。等等
不可能复制,我没有在任何地方复制,是的,我遵循与上面链接相同的指南,实际上我忘了在=new ScannerSystem.in中在这里编写Scanner;当它到达Verifier时,Verifier=new Verifierin.nextLine;然后,我将LinkedIn应用程序的密钥作为参数,并在其返回验证器对象后返回。。要访问,token.在建议指南中,您从用户处获得的验证器是什么,在验证器v=您从用户处获得的新验证器;在linkedin身份验证之后,oauth_验证器是否传递给您的回调方法。不,我调试代码,代码运行正常,直到验证器之后,我发现访问令牌的问题,异常是响应体不正确,无法提取token和Secret您不了解scribe是如何工作的,您不了解oauth是如何工作的,并且您没有重建控制器,无论如何,您的应用程序将无法工作,因为您没有在会话属性中存储任何内容,很抱歉,我无法再帮助您。