FacebookProviderImpl.java 2.41 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.ReferenceCardinality
 *  org.apache.felix.scr.annotations.ReferencePolicy
 *  org.apache.felix.scr.annotations.Service
 *  org.scribe.builder.api.Api
 *  org.scribe.builder.api.FacebookApi
 */
package com.adobe.granite.auth.oauth.impl;

import com.adobe.granite.auth.oauth.Provider;
import com.adobe.granite.auth.oauth.ProviderExtension;
import com.adobe.granite.auth.oauth.ProviderType;
import com.adobe.granite.auth.oauth.impl.ProviderBase;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.scribe.builder.api.Api;
import org.scribe.builder.api.FacebookApi;

@Service(value={Provider.class})
@Component(metatype=1, label="%auth.oauth.provider.facebook.name", description="%auth.oauth.provider.facebook.description")
@Properties(value={@Property(name="oauth.provider.id", value={"facebook"})})
@Reference(name="providerExtension", referenceInterface=ProviderExtension.class, bind="bindProviderExtension", unbind="unbindProviderExtension", cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
public class FacebookProviderImpl
extends ProviderBase {
    public FacebookProviderImpl() {
        super(ProviderType.OAUTH2, (Api)new FacebookApi(), "https://graph.facebook.com/me");
    }

    public String mapProperty(String property) {
        if ("first_name".equals(property)) {
            return "profile/givenName";
        }
        if ("last_name".equals(property)) {
            return "profile/familyName";
        }
        if ("locale".equals(property)) {
            return "preferences/language";
        }
        return super.mapProperty(property);
    }

    public Object mapValue(String key, String value) {
        if ("profile/avatar".equals(key)) {
            return "http://graph.facebook.com/" + value + "/picture";
        }
        return super.mapValue(key, value);
    }
}