001/* 002 * (C) Copyright 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nelson Silva <[email protected]> - initial API and implementation 018 * Nuxeo 019 */ 020package org.nuxeo.ecm.platform.oauth2.openid.auth.facebook; 021 022import java.util.Date; 023 024import org.joda.time.DateTime; 025import org.joda.time.format.DateTimeFormatter; 026import org.joda.time.format.ISODateTimeFormat; 027import org.nuxeo.ecm.platform.oauth2.openid.auth.DefaultOpenIDUserInfo; 028 029import com.google.api.client.util.Key; 030 031public class FacebookUserInfo extends DefaultOpenIDUserInfo { 032 033 @Key("id") 034 protected String id; 035 036 @Key("first_name") 037 protected String firstName; 038 039 @Key("link") 040 protected String link; 041 042 @Key("birthday") 043 protected Date birthday; 044 045 @Key("verified") 046 protected boolean verified; 047 048 @Override 049 public String getSubject() { 050 return id; 051 } 052 053 @Override 054 public String getGivenName() { 055 return firstName; 056 } 057 058 @Override 059 public String getProfile() { 060 return link; 061 } 062 063 @Override 064 public Date getBirthdate() { 065 return birthday; 066 } 067 068 @Override 069 public boolean isEmailVerified() { 070 return verified; 071 } 072 073 @Override 074 public Date getUpdatedTime() { 075 Date date; 076 try { 077 DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); 078 DateTime dateTime = parser.parseDateTime(updatedTime); 079 date = dateTime.toDate(); 080 } catch (IllegalArgumentException e) { 081 return null; 082 } 083 return date; 084 } 085 086}