使用SocialAuth在JSF中登录社交网络

时间:2014-10-15 11:45:12

标签: facebook jsf jsf-2 twitter socialauth

我正在开发JSF 2.2和socialauth中的模块,它包含通过外部oAuth提供商进行的身份验证,如Gmail,Hotmail,Yahoo,Twitter,Facebook,LinkedIn,Foursquare,MySpace。我找到了一个Facebook登录示例代码,并根据我的应用进行了调整。

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);
            }

它适用于Facebook,但当我尝试使用Twitter或Google时,我不知道属性,只需知道API KEY,API SECRET键即可。当我尝试没有Twitter和谷歌的属性时,我收到了这个错误

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

1 个答案:

答案 0 :(得分:1)

我在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");

对于这些定义,属性已添加到Twitter连接

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

它可以正常工作。感谢JavaBeigner的回复

相关问题