--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd
+ ">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>de.juplo.examples</groupId>
+ <artifactId>facebook-app</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <parent>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>1.3.1.RELEASE</version>
+ </parent>
+
+ <organization>
+ <name>juplo - Java bits from nerds for nerds</name>
+ <url>http://juplo.de</url>
+ </organization>
+
+ <properties>
+ <java.version>1.8</java.version>
+ <!-- settings for the Graph-API -->
+ <facebook.app.id>NOT_SET</facebook.app.id>
+ <facebook.app.secret>NOT_SET</facebook.app.secret>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-thymeleaf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-facebook</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
--- /dev/null
+package de.juplo.yourshouter;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+
+@SpringBootApplication
+public class Application
+{
+ public static void main(String[] args)
+ {
+ SpringApplication.run(Application.class, args);
+ }
+}
\ No newline at end of file
--- /dev/null
+package de.juplo.yourshouter;
+
+import javax.inject.Inject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.social.facebook.api.Facebook;
+import org.springframework.social.facebook.api.User;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+
+/**
+ * Controller, that handles the welcome-page.
+ *
+ * @author Kai Moritz
+ */
+@Controller
+@RequestMapping("/")
+public class HomeController
+{
+ private final static Logger LOG = LoggerFactory.getLogger(HomeController.class);
+
+
+ private final Facebook facebook;
+
+
+ @Inject
+ public HomeController(Facebook facebook)
+ {
+ this.facebook = facebook;
+ }
+
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String home(Model model)
+ {
+ boolean authorized = true;
+ try
+ {
+ authorized = facebook.isAuthorized();
+ }
+ catch (NullPointerException e)
+ {
+ LOG.debug("NPE while acessing Facebook: {}", e);
+ authorized = false;
+ }
+ if (!authorized)
+ {
+ LOG.info("no authorized user, redirecting to /connect/facebook");
+ return "redirect:/connect/facebook";
+ }
+
+ User user = facebook.userOperations().getUserProfile();
+ LOG.info("authorized user {}, id: {}", user.getName(), user.getId());
+ model.addAttribute("user", user);
+ return "home";
+ }
+}
--- /dev/null
+spring.social.facebook.appId=@facebook.app.id@
+spring.social.facebook.appSecret=@facebook.app.secret@
+
+logging.level.org.springframework.social=debug
+logging.level.de.juplo.yourshouter=info
--- /dev/null
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
+ <head>
+ <title>Connect to Facebook</title>
+ </head>
+ <body>
+ <h1>Connect to Facebook</h1>
+ <form action="#" th:action="@{/connect/facebook}" method="POST">
+ <div class="formInfo">
+ <p>
+ You aren't connected to Facebook yet.
+ Click the button to connect with your Facebook account.
+ </p>
+ </div>
+ <p><button type="submit">Connect to Facebook</button></p>
+ </form>
+ </body>
+</html>
--- /dev/null
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
+ <head>
+ <title>Connect to Facebook</title>
+ </head>
+ <body>
+ <p>Back <a href="home.html" th:href="@{/}">HOME</a></p>
+ <hr />
+ <h1>Connected to Facebook</h1>
+ <p>
+ You are now connected to your Facebook account.
+ </p>
+ </body>
+</html>
--- /dev/null
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
+ <head>
+ <title>Home</title>
+ </head>
+ <body>
+ <h1>Hello, <span th:text="${user.name}">Some User</span>!</h1>
+ <ul>
+ <li><a href="connect/facebookConnected.html" th:href="@{/connect/facebook.html}">Show connection-status</a></li>
+ </ul>
+ </body>
+</html>