2016-11-21 43 views
0

我已經部署了我的春天啓動的應用程序使用代理(目前阿帕奇但將是相同的使用nginx的或清漆,...),所以我收到春季引導社會連接器

The redirect URI in the request, http://localhost:8080/signin/google, does not match the ones authorized for the OAuth client. 

或多或少對Facebook等其他社交類似。

你應該配置這樣

@Configuration 
public class SocialConfig { 

    @Bean 
    public ConnectController connectController() { 
     ConnectController controller = new ConnectController(connectionFactoryLocator(), connectionRepository()); 
     controller.setApplicationUrl(environment.getProperty("application.url"); 
     return controller; 
    } 
} 

該文檔的狀態看http://docs.spring.io/spring-social/docs/current/reference/htmlsingle/#creating-connections-with-connectcontroller

如何,我是不是應該去從connectionFactoryLocation()

我的代碼是:

/** 
* Basic Spring Social configuration. 
* 
* <p>Creates the beans necessary to manage Connections to social services and 
* link accounts from those services to internal Users.</p> 
*/ 
@Configuration 
@EnableSocial 
public class SocialConfiguration implements SocialConfigurer { 
    private final Logger log = LoggerFactory.getLogger(SocialConfiguration.class); 

    @Inject 
    private SocialUserConnectionRepository socialUserConnectionRepository;  

    @Override 
    public void addConnectionFactories(ConnectionFactoryConfigurer connectionFactoryConfigurer, Environment environment) { 

     // Google configuration 
     String googleClientId = environment.getProperty("spring.social.google.clientId"); 
     String googleClientSecret = environment.getProperty("spring.social.google.clientSecret"); 
     if (googleClientId != null && googleClientSecret != null) { 
      log.debug("Configuring GoogleConnectionFactory"); 
      connectionFactoryConfigurer.addConnectionFactory(
       new GoogleConnectionFactory(
        googleClientId, 
        googleClientSecret 
       ) 
      ); 
     } else { 
      log.error("Cannot configure GoogleConnectionFactory id or secret null"); 
     } 

     // Facebook configuration 
     String facebookClientId = environment.getProperty("spring.social.facebook.clientId"); 
     String facebookClientSecret = environment.getProperty("spring.social.facebook.clientSecret"); 
     if (facebookClientId != null && facebookClientSecret != null) { 
      log.debug("Configuring FacebookConnectionFactory"); 
      connectionFactoryConfigurer.addConnectionFactory(
       new FacebookConnectionFactory(
        facebookClientId, 
        facebookClientSecret 
       ) 
      ); 
     } else { 
      log.error("Cannot configure FacebookConnectionFactory id or secret null"); 
     } 

     // Twitter configuration 
     String twitterClientId = environment.getProperty("spring.social.twitter.clientId"); 
     String twitterClientSecret = environment.getProperty("spring.social.twitter.clientSecret"); 
     if (twitterClientId != null && twitterClientSecret != null) { 
      log.debug("Configuring TwitterConnectionFactory"); 
      connectionFactoryConfigurer.addConnectionFactory(
       new TwitterConnectionFactory(
        twitterClientId, 
        twitterClientSecret 
       ) 
      ); 
     } else { 
      log.error("Cannot configure TwitterConnectionFactory id or secret null"); 
     } 

     // jhipster-needle-add-social-connection-factory 
    } 

    @Override 
    public UserIdSource getUserIdSource() { 
     return new AuthenticationNameUserIdSource(); 
    } 

    @Override 
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) { 
     return new CustomSocialUsersConnectionRepository(socialUserConnectionRepository, connectionFactoryLocator); 
    } 

    @Bean 
    public SignInAdapter signInAdapter() { 
     return new CustomSignInAdapter(); 
    } 

    @Inject 
    Environment environment; 

    @Bean 
    public ProviderSignInController providerSignInController(ConnectionFactoryLocator connectionFactoryLocator, UsersConnectionRepository usersConnectionRepository, SignInAdapter signInAdapter) throws Exception { 
     ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, signInAdapter); 
     providerSignInController.setSignUpUrl("/social/signup"); 
     providerSignInController.setApplicationUrl(environment.getProperty("spring.application.url")); 

     return providerSignInController; 
    } 

    @Bean 
    public ProviderSignInUtils getProviderSignInUtils(ConnectionFactoryLocator connectionFactoryLocator, UsersConnectionRepository usersConnectionRepository) { 
     return new ProviderSignInUtils(connectionFactoryLocator, usersConnectionRepository); 
    } 
} 

回答

0

感謝https://stackoverflow.com/a/27593526/509565我已經重寫connectController()作爲

@Bean 
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, 
     ConnectionRepository connectionRepository) { 

    ConnectController controller = new ConnectController(connectionFactoryLocator, connectionRepository); 
    controller.setApplicationUrl(environment.getProperty("application.url")); 
    return controller; 
}