1
我有一個使用spring-security-facebook:0.17插件通過Spring Security進行身份驗證的Grails項目(v2.4.2)。乍一看,一切似乎都很好。但是,有一大羣用戶,由於某些未知原因,我無法訪問他們的電子郵件地址。我使用春季社交來抓取電子郵件。我有權限並將其設置在範圍內。下面的代碼片段,我驗證新用戶:當權限被授予爲什麼Spring Social插件偶爾會在User類中返回空郵件?
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")
}
爲什麼我會收到一個空的電子郵件?是否有處理此行爲的首選方法(除了未通過身份驗證和僞造電子郵件地址)。非常感謝!
謝謝 - 顯然FB不必提供具體信息就是答案。我有一個AOL帳戶的兒子,因爲這個問題,我的用戶之一無法進行身份驗證。我不確定最好/最實際的處理方式應該是什麼。如果可以避免,我真的不想拒絕用戶。我想我會繼續使用虛假電子郵件進行身份驗證/創建用戶,並假設他們必須在以後通過定期檢查FB郵件是否發生了更改而在內部進行了身份驗證。 –