001/*
002 * (C) Copyright 2006-2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nelson Silva <nelson.silva@inevo.pt> - initial API and implementation
016 *     Nuxeo
017 */
018package org.nuxeo.ecm.platform.oauth2.openid.auth.facebook;
019
020import java.util.Date;
021
022import org.joda.time.DateTime;
023import org.joda.time.format.DateTimeFormatter;
024import org.joda.time.format.ISODateTimeFormat;
025import org.nuxeo.ecm.platform.oauth2.openid.auth.DefaultOpenIDUserInfo;
026
027import com.google.api.client.util.Key;
028
029public class FacebookUserInfo extends DefaultOpenIDUserInfo {
030
031    @Key("id")
032    protected String id;
033
034    @Key("first_name")
035    protected String firstName;
036
037    @Key("link")
038    protected String link;
039
040    @Key("birthday")
041    protected Date birthday;
042
043    @Key("verified")
044    protected boolean verified;
045
046    @Override
047    public String getSubject() {
048        return id;
049    }
050
051    @Override
052    public String getGivenName() {
053        return firstName;
054    }
055
056    @Override
057    public String getProfile() {
058        return link;
059    }
060
061    @Override
062    public Date getBirthdate() {
063        return birthday;
064    }
065
066    @Override
067    public boolean isEmailVerified() {
068        return verified;
069    }
070
071    @Override
072    public Date getUpdatedTime() {
073        Date date;
074        try {
075            DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
076            DateTime dateTime = parser.parseDateTime(updatedTime);
077            date = dateTime.toDate();
078        } catch (IllegalArgumentException e) {
079            return null;
080        }
081        return date;
082    }
083
084}