SocialAuth - Facebook身份验证 - 指定请求的访问权限

时间:2013-06-20 23:17:34

标签: java facebook authentication oauth socialauth

我想在我的网站上通过facebook实现简单的登录。我使用了SocialAuth,它工作得非常好。但是,如果我通过Facebook登录,Facebook应用程序需要确认许多访问权限,如张贴到墙上等等。

我不需要这些权利。我可以以某种方式定义,请求哪些权利(基本上我不需要 - 只是登录)。这是我的代码:

//Create an instance of SocialAuthConfgi object
   SocialAuthConfig config = SocialAuthConfig.getDefault();

  //load configuration. By default load the configuration from oauth_consumer.properties. 
  //You can also pass input stream, properties object or properties file name.
   config.load();

  //Create an instance of SocialAuthManager and set config
  SocialAuthManager manager = new SocialAuthManager();
  manager.setSocialAuthConfig(config);

  //URL of YOUR application which will be called after authentication
  String successUrl = "http://opensource.brickred.com/socialauthdemo/socialAuthSuccessAction.do";

  // get Provider URL to which you should redirect for authentication.
  // id can have values "facebook", "twitter", "yahoo" etc. or the OpenID URL
  String url = manager.getAuthenticationUrl(id, successUrl);

  // Store in session
  session.setAttribute("authManager", manager);

我的配置看起来像这样。我能以某种方式在这里定义吗?

#facebook
graph.facebook.com.consumer_key =   152190004803645
graph.facebook.com.consumer_secret = 64c94bd02180b0ade85889b44b2ba7c4
graph.facebook.com.secure = true
graph.facebook.com.request_token_url = /oauth/access_token
graph.facebook.com.authorization_url = /oauth/authorize
graph.facebook.com.access_token_url = /me
graph.facebook.com.signature_method = HMAC-SHA1
graph.facebook.com.transport_name = GET

1 个答案:

答案 0 :(得分:2)

您可以像这样添加自定义权限。

graph.facebook.com.consumer_key =   152190004803645
graph.facebook.com.consumer_secret = 64c94bd02180b0ade85889b44b2ba7c4
graph.facebook.com.custom_permission = email,user_birthday,user_location

无需设置其他属性。但是,如果要设置其他属性,则只能设置request_token_url(对于OAuth1.0),authentication_url和access_token_url。此功能可从socialauth-4.2

获得
graph.facebook.com.authentication_url
graph.facebook.com.access_token_url