facebookjsfjsf-2twittersocialauth

Social network login in JSF using SocialAuth


I'm developing a module in JSF 2.2 and socialauth, it contains users authentication through external oAuth providers like Gmail, Hotmail, Yahoo, Twitter, Facebook, LinkedIn, Foursquare, MySpace. I found a sample code for Facebook login and adapted to my app.

public void socialConnect() throws Exception { 
     // Put your keys and secrets from the providers here 
    Properties props = System.getProperties();
    props.put("graph.facebook.com.consumer_key", FACEBOOK_APP_ID);
    props.put("graph.facebook.com.consumer_secret", FACEBOOK_APP_SECRET);
    // Define your custom permission if needed
    props.put("graph.facebook.com.custom_permissions", publish_stream,email,user_birthday,user_location,offline_access");
    // Initiate required components
    SocialAuthConfig config = SocialAuthConfig.getDefault();
    config.load(props);
    manager = new SocialAuthManager();
    manager.setSocialAuthConfig(config);
    // 'successURL' is the page you'll be redirected to on successful login
    ExternalContext externalContext   = FacesContext.getCurrentInstance().getExternalContext();
    String   successURL        =baseURL+"/socialLoginSuccess.xhtml"; 
    String  authenticationURL = manager.getAuthenticationUrl(providerID, successURL);
    FacesContext.getCurrentInstance().getExternalContext().redirect(authenticationURL);
            }

It works for Facebook but when I try for Twitter or Google I don't know properties , just know API KEY,API SECRET keys. When I tried with no properties for Twitter and Google, I got this error

org.brickred.socialauth.exception.SocialAuthException: twitter is not a provider or valid OpenId URL

Solution

  • I found this code in AuthProviderFactory.java

    domainMap = new HashMap<String, String>();
        domainMap.put("google", "www.google.com");
        domainMap.put("yahoo", "api.login.yahoo.com");
        domainMap.put("twitter", "twitter.com");
        domainMap.put("facebook", "graph.facebook.com");
        domainMap.put("hotmail", "consent.live.com");
        domainMap.put("linkedin", "api.linkedin.com");
        domainMap.put("foursquare", "foursquare.com");
        domainMap.put("myspace", "api.myspace.com");
    

    For these definitons, properties was added to Twitter connection

    Properties props = System.getProperties();
                props.put("twitter.com.consumer_key", TWITTER_APP_KEY);
                props.put("twitter.com.consumer_secret", TWITTER_APP_SECRET);
    

    It works fine specified domains.Thanks JavaBeigner for replys