为什么 Spring 社交插件偶尔会 return 用户 class 的空电子邮件?
Why does the Spring Social plugin occasionally return an empty email on the User class?
我有一个 Grails 项目 (v2.4.2),它使用 spring-security-facebook:0.17 插件通过 Spring 安全性进行身份验证。乍一看,一切似乎都很好。但是,由于某些未知原因,我无法访问大量用户的电子邮件地址。我正在使用 spring 社交来获取电子邮件。我有权限,它在范围内设置。这是我对新用户进行身份验证的代码片段:
log.info("Create domain for facebook user $token.uid")
//Use Spring Social Facebook to load details for current user from Facebook API
log.info("create: FacebookAuthToken: $token")
log.info("created FacebookAuthToken.FacebookAccessToken = ${token.accessToken}")
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
org.springframework.social.facebook.api.User fbProfile = facebook.userOperations().getUserProfile()
// Check if email is actual granted because in production some are coming back null
boolean isEmailGranted=false
List<Permission> permissions = facebook?.userOperations()?.getUserPermissions()
String permissionString = "["
for (int i=0;i<permissions.size();i++) {
permissionString += "["+ permissions[i].getName() + ":" + permissions[i].getStatus()+"]"
if (permissions[i].getName()=="email" && permissions[i].isGranted())
isEmailGranted=true
}
permissionString += "]"
log.info("create: Facebook Permissions = " + permissionString)
def grailsWebRequest = WebUtils.retrieveGrailsWebRequest()
def flash = grailsWebRequest.flashScope
if (!isEmailGranted) {
log.warn("create: Unable to subscribe facebook user because email priviledge was not granted.")
flash.message = 'Login to Facebook failed. We must have access to your email address in order to proceed with login.'
throw new InsufficientAuthenticationException("Facebook email not accessible")
}
log.info("created: ")
String email = fbProfile.getEmail()
String firstName = fbProfile.getFirstName()
String lastName = fbProfile.getLastName()
String fullName = fbProfile.getName()
String username = firstName
String password = token.accessToken.accessToken
if (!email) {
log.error("create: Permission was granted to use facebook email but the value is null.")
flash.message = 'Login to Facebook failed. We are temporarily unable to access your email although permission has been granted'
throw new InsufficientAuthenticationException("Facebook email not accessible for unknown reason")
}
为什么我在获得许可后会收到一封空邮件?是否有处理此行为的首选方法(除了身份验证失败和伪造电子邮件地址之外)。非常感谢!
'user' 对象 ( https://developers.facebook.com/docs/reference/api/user/ ) 的 'email' 字段的文档阐明了此处的预期行为,即:
"this field will not be returned if no valid email address is available"
邮件发不出去的不同情况都有详细的解释。请检查一下:
https://developers.facebook.com/bugs/298946933534016/
希望对您有所帮助。
我有一个 Grails 项目 (v2.4.2),它使用 spring-security-facebook:0.17 插件通过 Spring 安全性进行身份验证。乍一看,一切似乎都很好。但是,由于某些未知原因,我无法访问大量用户的电子邮件地址。我正在使用 spring 社交来获取电子邮件。我有权限,它在范围内设置。这是我对新用户进行身份验证的代码片段:
log.info("Create domain for facebook user $token.uid")
//Use Spring Social Facebook to load details for current user from Facebook API
log.info("create: FacebookAuthToken: $token")
log.info("created FacebookAuthToken.FacebookAccessToken = ${token.accessToken}")
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
org.springframework.social.facebook.api.User fbProfile = facebook.userOperations().getUserProfile()
// Check if email is actual granted because in production some are coming back null
boolean isEmailGranted=false
List<Permission> permissions = facebook?.userOperations()?.getUserPermissions()
String permissionString = "["
for (int i=0;i<permissions.size();i++) {
permissionString += "["+ permissions[i].getName() + ":" + permissions[i].getStatus()+"]"
if (permissions[i].getName()=="email" && permissions[i].isGranted())
isEmailGranted=true
}
permissionString += "]"
log.info("create: Facebook Permissions = " + permissionString)
def grailsWebRequest = WebUtils.retrieveGrailsWebRequest()
def flash = grailsWebRequest.flashScope
if (!isEmailGranted) {
log.warn("create: Unable to subscribe facebook user because email priviledge was not granted.")
flash.message = 'Login to Facebook failed. We must have access to your email address in order to proceed with login.'
throw new InsufficientAuthenticationException("Facebook email not accessible")
}
log.info("created: ")
String email = fbProfile.getEmail()
String firstName = fbProfile.getFirstName()
String lastName = fbProfile.getLastName()
String fullName = fbProfile.getName()
String username = firstName
String password = token.accessToken.accessToken
if (!email) {
log.error("create: Permission was granted to use facebook email but the value is null.")
flash.message = 'Login to Facebook failed. We are temporarily unable to access your email although permission has been granted'
throw new InsufficientAuthenticationException("Facebook email not accessible for unknown reason")
}
为什么我在获得许可后会收到一封空邮件?是否有处理此行为的首选方法(除了身份验证失败和伪造电子邮件地址之外)。非常感谢!
'user' 对象 ( https://developers.facebook.com/docs/reference/api/user/ ) 的 'email' 字段的文档阐明了此处的预期行为,即: "this field will not be returned if no valid email address is available"
邮件发不出去的不同情况都有详细的解释。请检查一下: https://developers.facebook.com/bugs/298946933534016/
希望对您有所帮助。