Announcement Announcement Module
Collapse
No announcement yet.
Problem With Connecting... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem With Connecting...

    I am able to get a connection going to facebook and twitter -- however, the problem is that once I connect and authenticate with the provider that instead of being sent back to my URL that I am specifying in my connect controller, it is being sent back to my application with the suffix /connect/{provider}. What am I missing in the configuration below that is keeping it from sending it to the application URL that I am specifying in the controller? Any help is greatly appreciated it.


    Code:
    @Configuration
    public class SocialConfig implements InitializingBean {
    
    	private static Logger log = Logger.getLogger(LoginController.class);
    
    	@Inject
    	PropertiesFactoryBean appProperties;
    
    	@Inject
    	DataSource dataSource;
    
    	@Bean
    	public ConnectionFactoryLocator connectionFactoryLocator() {
    		String facebookClientId = "";
    		String facebookClientSecret = "";
    		String twitterConsumerKey = "";
    		String twitterConsumerSecret = "";
    		try {
    			facebookClientId = appProperties.getObject().getProperty(
    					"facebook.clientId");
    			facebookClientSecret = appProperties.getObject().getProperty(
    					"facebook.clientSecret");
    			twitterConsumerKey = appProperties.getObject().getProperty(
    					"twitter.consumerKey");
    			twitterConsumerSecret = appProperties.getObject().getProperty(
    					"twitter.consumerSecret");
    
    		} catch (IOException e) {
    
    		}
    		log.info("getting connectionFactoryLocator");
    		ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
    		registry.addConnectionFactory(new FacebookConnectionFactory(
    				facebookClientId, facebookClientSecret));
    		registry.addConnectionFactory(new TwitterConnectionFactory(
    				twitterConsumerKey, twitterConsumerSecret));
    		return registry;
    	}
    
    	/**
    	 * Singleton data access object providing access to connections across all
    	 * users.
    	 */
    	@Bean
    	public UsersConnectionRepository usersConnectionRepository() {
    		return new JdbcUsersConnectionRepository(dataSource,
    				connectionFactoryLocator(), Encryptors.noOpText());
    		// return usersConnectionRepositiory;
    	}
    
    	@Bean
    	@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    	public ConnectionRepository connectionRepository() {
    		Authentication authentication = SecurityContextHolder.getContext()
    				.getAuthentication();
    		if (authentication == null) {
    			throw new IllegalStateException(
    					"Unable to get a ConnectionRepository: no user signed in");
    		}
    		return usersConnectionRepository().createConnectionRepository(
    				authentication.getName());
    	}
    
    	@Bean
    	@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    	public Facebook facebook() {
    		Facebook api = connectionRepository().getPrimaryConnection(
    				Facebook.class).getApi();
    		// socialContext().setFacebook(api);
    		// socialContext().setCookies(request.getCookies());
    		return api;
    	}
    
    	@Bean
    	@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
    	public Twitter twitter() {
    		Twitter api = connectionRepository()
    				.getPrimaryConnection(Twitter.class).getApi();
    		// socialContext().setTwitter(api);
    		// socialContext().setCookies(request.getCookies());
    		return api;
    	}
    
    	// @Bean
    	// public SocialContext socialContext() {
    	// SocialContext socialContext = new
    	// SocialContext(usersConnectionRepository());
    	// return socialContext;
    	// }
    
    	@Bean
    	public ConnectController connectController() {
    		ConnectController connectController = new ConnectController(
    				connectionFactoryLocator(), connectionRepository());
    		// connectController.addInterceptor(new FacebookInterceptor());
    		connectController.setApplicationUrl("http://{myurl}:8080/market/secure/callback"); 
    		return connectController;
    	}
    
    	@Bean
    	public ProviderSignInController providerSignInController() {
    		return new ProviderSignInController(connectionFactoryLocator(),
    				usersConnectionRepository(), new SimpleSignInAdapter());
    	}
    
    	@Override
    	public void afterPropertiesSet() throws Exception {
    
    	}
    }

  • #2
    The application URL is not to be interpreted as a post-connection URL. Application URL is the base URL for your application, but Facebook *must* redirect back to something at /connect/Facebook (likewise for Twitter with /connect/Twitter) because that's where ConnectController is listening and ready to complete the connection.

    ConnectController uses the applicationUrl property to create the page that Facebook/Twitter should redirect to after successful authorization. It is the base URL for your app and ConnectController will attach its own URL to it to create the full redirect URL.

    Under usual circumstances, you don't need to specify the applicationUrl property, because it can be derived from the request. Only in some special circumstances would you need to explicitly set it. For example, if your server is one among many nodes in a load-balancing situation, then the request may be rewritten before it gets to your server. In that case, you may want to set applicationUrl to the external URL for your app so that the redirect URL won't be created with your node's internal URL.

    If you need to redirect to elsewhere in your application, you can subclass ConnectController and override the connectionStatusRedirect() method to have it redirect anywhere you'd like. The default behavior is to redirect to /connect/{provider ID}, as described in the JavaDoc for that method.

    Comment


    • #3
      Craig -- thank you sir, you gave me some good food for thought on this, and I have found a good work around by just going ahead and super classing the ConnectController instead. I appreciate your prompt response and suggestion on this.

      Originally posted by habuma View Post
      The application URL is not to be interpreted as a post-connection URL. Application URL is the base URL for your application, but Facebook *must* redirect back to something at /connect/Facebook (likewise for Twitter with /connect/Twitter) because that's where ConnectController is listening and ready to complete the connection.

      ConnectController uses the applicationUrl property to create the page that Facebook/Twitter should redirect to after successful authorization. It is the base URL for your app and ConnectController will attach its own URL to it to create the full redirect URL.

      Under usual circumstances, you don't need to specify the applicationUrl property, because it can be derived from the request. Only in some special circumstances would you need to explicitly set it. For example, if your server is one among many nodes in a load-balancing situation, then the request may be rewritten before it gets to your server. In that case, you may want to set applicationUrl to the external URL for your app so that the redirect URL won't be created with your node's internal URL.

      If you need to redirect to elsewhere in your application, you can subclass ConnectController and override the connectionStatusRedirect() method to have it redirect anywhere you'd like. The default behavior is to redirect to /connect/{provider ID}, as described in the JavaDoc for that method.

      Comment

      Working...
      X