title: LinkedIn login integration with Spring MVC web Application
body: <p>I am New to Spring ,and I want to log into a Spring MVC app. With LinkedIn ,
  I use SCRIBE for login , but when I run the application, it throws an exception.</p>
  
  <p>My controller code for linkedin in MVC is  like: </p>
  
  <pre><code>  @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";
      }
  </code></pre>
  
  <p>and beans for linked login: </p>
  
  <p>
          
          
          
          
      </p>
  
  <pre><code>&lt;bean id="linkedInServiceProvider" class="com.spring.handler.OAuthServiceProvider"&gt;
      &lt;constructor-arg name="oauthServiceConfig" ref="linkedInServiceConfig" /&gt;
  &lt;/bean
  </code></pre>
  
  <p>And  OAuthServiceConfig class for configuration of service: </p>
  
  <pre><code>  package com.spring.handler;
  import org.scribe.builder.api.Api;
  public class OAuthServiceConfig {
  private String apiKey;
  private String apiSecret;
  private String callback;
  private Class apiClass;
  
  public OAuthServiceConfig(String apiKey,String apiSecret,String callback,Class apiClass){
      super();
      this.apiKey=apiKey;
      this.apiSecret=apiSecret;
      this.callback=callback;
      this.apiClass=apiClass;
      System.out.println(apiKey+apiSecret+callback+apiClass);
  }
  
  public String getApiKey() {
      return apiKey;
  }
  
  public void setApiKey(String apiKey) {
      this.apiKey = apiKey;
  }
  
  public String getApiSecret() {
      return apiSecret;
  }
  
  public void setApiSecret(String apiSecret) {
      this.apiSecret = apiSecret;
  }
  
  public String getCallback() {
      return callback;
  }
  
  public void setCallback(String callback) {
      this.callback = callback;
  }
  
  public Class getApiClass() {
      return apiClass;
  }
  
  public void setApiClass(Class apiClass) {
      this.apiClass = apiClass;
  }
  
  
  
  }
  </code></pre>
  
  <p>and <code>OAuthServiceProvider</code> class for providing the service to <code>OAuthService</code>  using  <code>linkedInServiceProvider.getService()</code> method: </p>
  
  <pre><code>   package com.spring.handler;
  
  import org.scribe.builder.ServiceBuilder;
  import org.scribe.oauth.OAuthService;
  
  public class OAuthServiceProvider {
      OAuthServiceConfig oauthServiceConfig;
  
      public OAuthServiceProvider() {
      }
  
      public OAuthServiceProvider(OAuthServiceConfig oauthServiceConfig) {
          this.oauthServiceConfig = oauthServiceConfig;
      }
  
      public OAuthService getService() {
          System.out.println(oauthServiceConfig);
          return new ServiceBuilder().provider(oauthServiceConfig.getApiClass())
                  .apiKey(oauthServiceConfig.getApiKey())
                  .apiSecret(oauthServiceConfig.getApiSecret())
                  .callback(oauthServiceConfig.getCallback()).build();
      }
  }
  </code></pre>
  
  <p>But when I log into the application, the exception thrown is:</p>
  
  <pre><code>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)
  </code></pre>