Hi all,
I am integrating spring social into an existing spring web app that uses spring web flow.
I am having trouble just getting anything to work right.
A bit about my app:
*Uses Spring/ Spring Web Flow
* "Backend" web app for admin purposes
What my goal is:
* I need to integrate the social component for only a handful of users.
* Only AFTER the user logs into our system, THEN the user can login to Twitter / Facebook/ Instagram .
* The user can perform action specific to the SaaS provider. (can post new posts on Facebook).
* I do NOT need the log in through provider feature (ProviderSignInController).
* Save the accessToken (connection info) in a DB (postgres) for future connections.
I am using the "quickstart" sample app from github.
I have integrated the xml settings (to the best of my ability) and installed the needed jars. This appears to be configured ok, i have no errors upon deployment and the web app runs.
I have the "login" page being displayed via SWF. Its lives in folder directory "/flows/social/signin"
Screen Shot 2013-03-28 at 1.58.50 PM.png
This page displays the "log into facebook" button. Same as from the quickstart sample app.
FIRST ISSUE: When I click "login to facebook" I get a 404. Page not found error when I click this button.
Where am I messing up? And also, how is the ConnectController receiving the request parameter "facebook" in this case?
According to the reference doc, this controller automatically reads the request and takes the provider id from that, is that correct????
I am basically trying to kickoff the OAuth dance for facebook with no luck.
I have been reading the manual/ reference docs on all things Spring Social vigorously, and attacking StackOverflow and here in springsource community.... but I am stumped.
SECOND: Do I remove ProviderSignInController completely? I have commented it out.
THIRD: I have way more questions lol, first things first.
Any help would be awesome!
Thanks!
Here are my modified HomeController, WebMVC and SocialConfig classes:
HomeController.java
WebMVC:
SocialConfig.java
I am integrating spring social into an existing spring web app that uses spring web flow.
I am having trouble just getting anything to work right.
A bit about my app:
*Uses Spring/ Spring Web Flow
* "Backend" web app for admin purposes
What my goal is:
* I need to integrate the social component for only a handful of users.
* Only AFTER the user logs into our system, THEN the user can login to Twitter / Facebook/ Instagram .
* The user can perform action specific to the SaaS provider. (can post new posts on Facebook).
* I do NOT need the log in through provider feature (ProviderSignInController).
* Save the accessToken (connection info) in a DB (postgres) for future connections.
I am using the "quickstart" sample app from github.
I have integrated the xml settings (to the best of my ability) and installed the needed jars. This appears to be configured ok, i have no errors upon deployment and the web app runs.
I have the "login" page being displayed via SWF. Its lives in folder directory "/flows/social/signin"
Screen Shot 2013-03-28 at 1.58.50 PM.png
This page displays the "log into facebook" button. Same as from the quickstart sample app.
Code:
<form action="<c:url value="/app/social/signin/facebook" />" method="POST">
<button type="submit">Sign in with Facebook</button>
<input type="hidden" name="scope" value="email,publish_stream,offline_access" />
</form>
Where am I messing up? And also, how is the ConnectController receiving the request parameter "facebook" in this case?
According to the reference doc, this controller automatically reads the request and takes the provider id from that, is that correct????
I am basically trying to kickoff the OAuth dance for facebook with no luck.
I have been reading the manual/ reference docs on all things Spring Social vigorously, and attacking StackOverflow and here in springsource community.... but I am stumped.
SECOND: Do I remove ProviderSignInController completely? I have commented it out.
THIRD: I have way more questions lol, first things first.
Any help would be awesome!
Thanks!
Here are my modified HomeController, WebMVC and SocialConfig classes:
HomeController.java
Code:
@Controller
public class HomeController {
private final Facebook facebook;
@Inject
public HomeController(Facebook facebook) {
this.facebook = facebook;
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Model model) {
List<Reference> friends = facebook.friendOperations().getFriends();
model.addAttribute("friends", friends);
return "social/home";
}
}
WebMVC:
Code:
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new UserInterceptor(usersConnectionRepository));
}
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/signin");
registry.addViewController("/signout");
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/social");
//viewResolver.setSuffix(".jsp");
//commented out setSuffix()...dont think i need that for SWF???
return viewResolver;
}
private @Inject UsersConnectionRepository usersConnectionRepository;
}
SocialConfig.java
Code:
@Configuration
public class SocialConfig {
@Inject
private Environment environment;
@Inject
private DataSource dataSource;
/**
* When a new provider is added to the app, register its {@link ConnectionFactory} here.
* @see FacebookConnectionFactory
*/
@Bean
public ConnectionFactoryLocator connectionFactoryLocator() {
ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
//registry.addConnectionFactory(new FacebookConnectionFactory(environment.getProperty("facebook.clientId"),
//environment.getProperty("facebook.clientSecret")));
// hardcoded the clientId and clientSecret for dev purps
registry.addConnectionFactory(new FacebookConnectionFactory( "3210996879#####", "88092872e86eb928a36771a8c6b#####" ) );
return registry;
}
/**
* Singleton data access object providing access to connections across all users.
*/
@Bean
public UsersConnectionRepository usersConnectionRepository() {
JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
connectionFactoryLocator(), Encryptors.noOpText());
repository.setConnectionSignUp(new SimpleConnectionSignUp());
return repository;
}
/**
* Request-scoped data access object providing access to the current user's connections.
*/
@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public ConnectionRepository connectionRepository() {
User user = SecurityContext.getCurrentUser();
return usersConnectionRepository().createConnectionRepository(user.getId());
}
/**
* A proxy to a request-scoped object representing the current user's primary Facebook account.
* @throws NotConnectedException if the user is not connected to facebook.
*/
@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public Facebook facebook() {
return connectionRepository().getPrimaryConnection(Facebook.class).getApi();
}
/**
* The Spring MVC Controller that allows users to sign-in with their provider accounts.
*/
// i do not need this service so i commented it out and put the ConnectController in its place. IS THAT RIGHT?
// @Bean
// public ProviderSignInController providerSignInController() {
// return new ProviderSignInController(connectionFactoryLocator(), usersConnectionRepository(),
// new SimpleSignInAdapter());
// }
/* according to the reference doc, this controller automatically reads the request and takes the provider id from that???? */
@Bean
public ConnectController connectController(){
ConnectController controller = new ConnectController( connectionFactoryLocator(), connectionRepository() );
controller.setApplicationUrl("mygreatwebsite.com/home");
return controller;
}
}