<!-- settings for the Graph-API -->
<facebook.app.id>NOT_SET</facebook.app.id>
<facebook.app.secret>NOT_SET</facebook.app.secret>
+ <facebook.app.canvas>NOT_SET</facebook.app.canvas>
</properties>
<dependencies>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-facebook-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-crypto</artifactId>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
<build>
import org.springframework.social.connect.web.SignInAdapter;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
+import org.springframework.social.facebook.web.CanvasSignInController;
/**
return controller;
}
+ /**
+ * Configure the {@link CanvasSignInController} to enable sign-in through
+ * the <code>signed_request</code>, that Facebook sends to the canvas-page.
+ *
+ * @param factoryLocator The {@link ConnectionFactoryLocator} will be injected by Spring.
+ * @param repository The {@link UserConnectionRepository} will be injected by Spring.
+ * @param env The {@link Environment}, to read additional parameters from.
+ * @return The configured {@link CanvasSignInController}
+ */
+ @Bean
+ public CanvasSignInController canvasSignInController(
+ ConnectionFactoryLocator factoryLocator,
+ UsersConnectionRepository repository,
+ Environment env
+ )
+ {
+ return
+ new CanvasSignInController(
+ factoryLocator,
+ repository,
+ new UserCookieSignInAdapter(),
+ env.getProperty("facebook.app.id"),
+ env.getProperty("facebook.app.secret"),
+ env.getProperty("facebook.app.canvas")
+ );
+ }
+
/**
* Configure a scoped bean named <code>facebook</code>, that enables
* access to the Graph-API in the name of the current user.
import java.io.IOException;
import java.util.Collections;
+import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
{
private final static Logger LOG =
LoggerFactory.getLogger(UserCookieInterceptor.class);
+ private final static Pattern PATTERN = Pattern.compile("^/signin|canvas");
private final UsersConnectionRepository repository;
throws
IOException
{
- if (request.getServletPath().startsWith("/signin"))
+ if (PATTERN.matcher(request.getServletPath()).find())
return true;
String user = UserCookieGenerator.INSTANCE.readCookieValue(request);
facebook.app.id=@facebook.app.id@
facebook.app.secret=@facebook.app.secret@
+facebook.app.canvas=@facebook.app.canvas@
+
+server.port: 8443
+server.ssl.key-store: keystore
+server.ssl.key-store-password: secret
spring.thymeleaf.prefix=/thymeleaf/
spring.thymeleaf.cache=false