Grails facebook spring 安全性返回 null

Grails facebook spring security returning null

我正在使用与“:spring-security-core 集成的“:spring-security-facebook:0.17” :2.0-RC5”。 我已经实施了 facebookAuthService.groovy 进行自定义。但是令牌未经过身份验证,fbProfile 返回 null,id 和 name 除外。

FacebookUser create(FacebookAuthToken token) {
    log.info("Create domain for facebook user $token.uid")

    //Use Spring Social Facebook to load details for current user from Facebook API
    Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
    FacebookProfile fbProfile = facebook.userOperations().userProfile
    FacebookProfile fbProfile2 = facebook.userOperations().getUserProfile()
    def ff = facebook.userOperations().userPermissions
    String email = fbProfile.email
    String username = fbProfile.username
    String firstName = fbProfile.firstName
    String lastName = fbProfile.lastName

    println fbProfile as JSON
    println token as JSON
    println fbProfile.email

    User person = new User(
            username: 'jgf',
            password: token.accessToken.accessToken, //not really necessary
            enabled: true,
            accountExpired:  false,
            accountLocked: false,
            passwordExpired: false,

            //fill with data loaded from Facebook API
            email: email
    )
    person.save(failOnError: true)
    UserRole.create(person, AuthRole.findByAuthority('ROLE_USER'))
    UserRole.create(person, AuthRole.findByAuthority('ROLE_FACEBOOK'))
    FacebookUser fbUser = new FacebookUser(
            uid: token.uid,
            accessToken: token.accessToken.accessToken,
            accessTokenExpires: token.accessToken.expireAt,
            user: person
    )
    fbUser.save(failOnError: true)
    return fbUser
}

回复如下: 访问令牌:

{"accessToken":{"accessToken":"CAAHt52DpmkIBAH34zFdy0PZC3a9y3JZARvfrVckTHN9xMZCOgL6QHzxNIna07ZBa5ZBXw2BZCwyflvCIIkPzn3pNk8QHFNqZCts8tAHZB1wK4AEJZBEPNHqFRWssPZBuIOCa6vk7U5W3K0ilIZB7GWx0MJCZC7UBy5mhb5W5RLkZB1wTn09Qs4NIGU9KDi22OPWbpEKQJoERr9fSfJwZDZD","expireAt":"2016-02-01T06:58:46Z"},"authenticated":false,"authorities":[],"code":"AQD3IrrusGkBsF91yaD68T81S4s-TO4qG17DARQepzB-y2q4vmWSFkoTmMX_ObJHjbOg83YcSE0DwsNjvKS7U2JH_O2C6XjVGM5vG8ZvxpXTo57RFhAzvTxd0NMIVL4Qypto2VRDcLeNIIW8dCQHNqhzJ-0l3_4BQfHk4ygXFEBFTmZA6wkFspnLr9awL5qL8t0m6h5AZbkydM6KhQCYmL_xmy8Evl22NSjYRG-G-edjVNo4t4Fn9AQt7AXEjG_xjytdUoBPa0Zpl5AGM1-VpeYOvhKDPGvXQ3fFkS-8oSe8dyj1T6gAc8BG2yQ4bycPftVqfNt3uCGpesYIkI-dnwxd","credentials":1026180034068785,"details":null,"name":"","principal":null,"redirectUri":"http://localhost:8080/j_spring_security_facebook_check","uid":1026180034068785}

和 fbProfile:

{"about":null,"bio":null,"birthday":null,"class":"org.springframework.social.facebook.api.FacebookProfile","education":null,"email":null,"favoriteAtheletes":null,"favoriteTeams":null,"firstName":null,"gender":null,"hometown":null,"id":"1026180034068785","inspirationalPeople":null,"interestedIn":null,"languages":null,"lastName":null,"link":null,"locale":null,"location":null,"middleName":null,"name":"Sanjib Maharjan","political":null,"quotes":null,"relationshipStatus":null,"religion":null,"significantOther":null,"sports":null,"thirdPartyId":null,"timezone":null,"updatedTime":null,"username":null,"website":null,"work":null}

这里的问题是一切都是空的,我不知道为什么。

PS:所有的facebook凭证都是正确的,也提供了权限(public_profile,电子邮件和user_about_me)。 是因为令牌未经过身份验证,还是我有其他事情 missing.Any 帮助是 appreciated.Thank 你。

我终于明白为什么除了名称和 ID 之外的所有内容都是空的。

自 2015 年 7 月 8 日起,Facebook 已更改 api - API 2.4 版: https://developers.facebook.com/docs/apps/changelog#v2_4

据此,我们必须指定要返回的每个字段和边,例如

https://graph.facebook.com/me?access_token=kjhgfgfhgghjhghj&fields=id,name,email,firstname

facebook.userOperations().getUserProfile() 提供除 id 和 name.So 之外的空字段解决方案是使用不同的 api 允许设置字段或者我们可以手动设置通过点击 uri(https://graph.facebook.com/me?access_token=kjhgfgfhgghjhghj&fields=id,name,email,firstname).