@Test public void oauth1Callback() throws Exception { ConnectionFactoryRegistry connectionFactoryLocator = new ConnectionFactoryRegistry(); ConnectionFactory<TestApi1> connectionFactory = new StubOAuth1ConnectionFactory("clientId", "clientSecret"); connectionFactoryLocator.addConnectionFactory(connectionFactory); StubConnectionRepository connectionRepository = new StubConnectionRepository(); ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository); List<ConnectInterceptor<?>> interceptors = getConnectInterceptor(); connectController.setConnectInterceptors(interceptors); connectController.afterPropertiesSet(); MockMvc mockMvc = standaloneSetup(connectController).build(); assertEquals(0, connectionRepository.findConnections("oauth2Provider").size()); mockMvc.perform(get("/connect/oauth1Provider") .sessionAttr("oauthToken", new OAuthToken("requestToken", "requestTokenSecret")) .param("oauth_token", "requestToken") .param("oauth_verifier", "verifier")) .andExpect(redirectedUrl("/connect/oauth1Provider")); List<Connection<?>> connections = connectionRepository.findConnections("oauth1Provider"); assertEquals(1, connections.size()); assertEquals("oauth1Provider", connections.get(0).getKey().getProviderId()); TestConnectInterceptor<?> testInterceptor1 = (TestConnectInterceptor<?>)(interceptors.get(0)); assertTrue(testInterceptor1.postConnectInvoked); assertFalse(((TestConnectInterceptor<?>)(interceptors.get(1))).postConnectInvoked); }
@RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") public RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request) { try { OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId); Connection<?> connection = connectSupport.completeConnection(connectionFactory, request); addConnection(connection, connectionFactory, request); } catch (Exception e) { sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e); logger.warn("Exception while handling OAuth1 callback (" + e.getMessage() + "). Redirecting to " + providerId +" connection status page."); } return connectionStatusRedirect(providerId, request); }
ConnectController implements InitializingBean { @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") public RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request) { try { OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId); Connection<?> connection = connectSupport.completeConnection(connectionFactory, request); addConnection(connection, connectionFactory, request); } catch (Exception e) { sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e); logger.warn("Exception while handling OAuth1 callback (" + e.getMessage() + "). Redirecting to " + providerId +" connection status page."); } return connectionStatusRedirect(providerId, request); } }
ConnectController implements InitializingBean { @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") public RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request) { try { OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId); Connection<?> connection = connectSupport.completeConnection(connectionFactory, request); addConnection(connection, connectionFactory, request); } catch (Exception e) { sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e); logger.warn("Exception while handling OAuth1 callback (" + e.getMessage() + "). Redirecting to " + providerId +" connection status page."); } return connectionStatusRedirect(providerId, request); } @Inject  ConnectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository); }
ConnectController implements InitializingBean { @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") public RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request) { try { OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId); Connection<?> connection = connectSupport.completeConnection(connectionFactory, request); addConnection(connection, connectionFactory, request); } catch (Exception e) { sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e); logger.warn("Exception while handling OAuth1 callback (" + e.getMessage() + "). Redirecting to " + providerId +" connection status page."); } return connectionStatusRedirect(providerId, request); } @Inject  ConnectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository); @Deprecated void setInterceptors(List<ConnectInterceptor<?>> interceptors); void setConnectInterceptors(List<ConnectInterceptor<?>> interceptors); void setDisconnectInterceptors(List<DisconnectInterceptor<?>> interceptors); void setApplicationUrl(String applicationUrl); void setViewPath(String viewPath); void setConnectionStatusUrlPath(String connectionStatusUrlPath); void setSessionStrategy(SessionStrategy sessionStrategy); void addInterceptor(ConnectInterceptor<?> interceptor); void addDisconnectInterceptor(DisconnectInterceptor<?> interceptor); @RequestMapping(method=RequestMethod.GET) String connectionStatus(NativeWebRequest request, Model model); @RequestMapping(value="/{providerId}", method=RequestMethod.GET) String connectionStatus(@PathVariable String providerId, NativeWebRequest request, Model model); @RequestMapping(value="/{providerId}", method=RequestMethod.POST) RedirectView connect(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="code") RedirectView oauth2Callback(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="error") RedirectView oauth2ErrorCallback(@PathVariable String providerId, 
			@RequestParam("error") String error, 
			@RequestParam(value="error_description", required=false) String errorDescription,
			@RequestParam(value="error_uri", required=false) String errorUri,
			NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.DELETE) RedirectView removeConnections(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}/{providerUserId}", method=RequestMethod.DELETE) RedirectView removeConnection(@PathVariable String providerId, @PathVariable String providerUserId, NativeWebRequest request); void afterPropertiesSet(); }
ConnectController implements InitializingBean { @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") public RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request) { try { OAuth1ConnectionFactory<?> connectionFactory = (OAuth1ConnectionFactory<?>) connectionFactoryLocator.getConnectionFactory(providerId); Connection<?> connection = connectSupport.completeConnection(connectionFactory, request); addConnection(connection, connectionFactory, request); } catch (Exception e) { sessionStrategy.setAttribute(request, PROVIDER_ERROR_ATTRIBUTE, e); logger.warn("Exception while handling OAuth1 callback (" + e.getMessage() + "). Redirecting to " + providerId +" connection status page."); } return connectionStatusRedirect(providerId, request); } @Inject  ConnectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository); @Deprecated void setInterceptors(List<ConnectInterceptor<?>> interceptors); void setConnectInterceptors(List<ConnectInterceptor<?>> interceptors); void setDisconnectInterceptors(List<DisconnectInterceptor<?>> interceptors); void setApplicationUrl(String applicationUrl); void setViewPath(String viewPath); void setConnectionStatusUrlPath(String connectionStatusUrlPath); void setSessionStrategy(SessionStrategy sessionStrategy); void addInterceptor(ConnectInterceptor<?> interceptor); void addDisconnectInterceptor(DisconnectInterceptor<?> interceptor); @RequestMapping(method=RequestMethod.GET) String connectionStatus(NativeWebRequest request, Model model); @RequestMapping(value="/{providerId}", method=RequestMethod.GET) String connectionStatus(@PathVariable String providerId, NativeWebRequest request, Model model); @RequestMapping(value="/{providerId}", method=RequestMethod.POST) RedirectView connect(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="oauth_token") RedirectView oauth1Callback(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="code") RedirectView oauth2Callback(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.GET, params="error") RedirectView oauth2ErrorCallback(@PathVariable String providerId, 
			@RequestParam("error") String error, 
			@RequestParam(value="error_description", required=false) String errorDescription,
			@RequestParam(value="error_uri", required=false) String errorUri,
			NativeWebRequest request); @RequestMapping(value="/{providerId}", method=RequestMethod.DELETE) RedirectView removeConnections(@PathVariable String providerId, NativeWebRequest request); @RequestMapping(value="/{providerId}/{providerUserId}", method=RequestMethod.DELETE) RedirectView removeConnection(@PathVariable String providerId, @PathVariable String providerUserId, NativeWebRequest request); void afterPropertiesSet();  }