Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added presenting the profile of the logged in user

  • Loading branch information...
commit b20f5a09fd8e11f6a5433e52b179c11f2cbc7f01 1 parent 23ad735
Jettro Coenradie authored
30 src/main/java/nl/gridshore/samples/springoauth/web/ConnectController.java
View
@@ -97,20 +97,38 @@ public String authorizeCallback(@RequestParam(value = "oauth_verifier", defaultV
*/
@RequestMapping(value = "linkedin/connections", method = RequestMethod.GET)
public String connections(WebRequest request) {
+ LinkedInTemplate template = createLinkedInTemplate(request);
+
+ List<LinkedInProfile> connections = template.getConnections();
+ request.setAttribute("connections", connections, WebRequest.SCOPE_REQUEST);
+
+ return "connections";
+ }
+
+ /**
+ * Handles the request to obtain the profile of the current logged in user
+ * @param request Spring provided WebRequest
+ * @return String representing the name of the view to show
+ */
+ @RequestMapping(value = "linkedin/profile", method = RequestMethod.GET)
+ public String profile(WebRequest request) {
+ LinkedInTemplate template = createLinkedInTemplate(request);
+
+ LinkedInProfile userProfile = template.getUserProfile();
+ request.setAttribute("profile", userProfile, WebRequest.SCOPE_REQUEST);
+ return "profile";
+ }
+
+ private LinkedInTemplate createLinkedInTemplate(WebRequest request) {
Token accessToken = obtainAccessTokenFromSession(request);
if (accessToken == null) {
throw new RuntimeException("An access token must be available here");
}
- LinkedInTemplate template = new LinkedInTemplate(
+ return new LinkedInTemplate(
apiKey,
apiSecret,
accessToken.getToken(),
accessToken.getSecret());
-
- List<LinkedInProfile> connections = template.getConnections();
- request.setAttribute("connections", connections, WebRequest.SCOPE_REQUEST);
-
- return "connections";
}
private Token obtainRequestTokenFromSession(WebRequest request) {
1  src/main/webapp/WEB-INF/views/connect/linkedin_connected.jsp
View
@@ -4,5 +4,6 @@
<p>Now you are connected to linkedin, you can ask the following thinks:</p>
<ul>
<li><a href="<c:url value="/connect/linkedin/connections" />">Connections</a></li>
+ <li><a href="<c:url value="/connect/linkedin/profile" />">My Profile</a></li>
</ul>
<jsp:include page="../inc/footer.jsp"/>
3  src/main/webapp/WEB-INF/views/connections.jsp
View
@@ -1,5 +1,6 @@
-<jsp:include page="inc/header.jsp"/>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<jsp:include page="inc/header.jsp"/>
+<jsp:include page="inc/navigation.jsp"/>
<table>
<c:forEach items="${connections}" var="connection">
<tr>
5 src/main/webapp/WEB-INF/views/inc/navigation.jsp
View
@@ -0,0 +1,5 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<div>
+ <span><a href="<c:url value="/connect/linkedin/connections" />">Connections</a></span>
+ <span><a href="<c:url value="/connect/linkedin/profile" />">My Profile</a></span>
+</div>
26 src/main/webapp/WEB-INF/views/profile.jsp
View
@@ -0,0 +1,26 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<jsp:include page="inc/header.jsp"/>
+<jsp:include page="inc/navigation.jsp"/>
+<table>
+ <tr>
+ <td>First name</td>
+ <td><c:out value="${profile.firstName}" /></td>
+ </tr>
+ <tr>
+ <td>Last name</td>
+ <td><c:out value="${profile.lastName}" /></td>
+ </tr>
+ <tr>
+ <td>headline</td>
+ <td><c:out value="${profile.headline}" /></td>
+ </tr>
+ <tr>
+ <td>PublicProfileUrls</td>
+ <td><c:out value="${profile.publicProfileUrl}" /></td>
+ </tr>
+ <tr>
+ <td>Industry</td>
+ <td><c:out value="${profile.industry}" /></td>
+ </tr>
+</table>
+<jsp:include page="inc/footer.jsp"/>
Please sign in to comment.
Something went wrong with that request. Please try again.