splix / grails-facebook-authentication-example

Grails 2.0 Spring Security Facebook Plugin Example
12 stars 14 forks source link

NPE when creating user #9

Open john-london opened 9 years ago

john-london commented 9 years ago

There is a NPE generated when creating a user as a result of the username field returned by FB being null (link below details this).

http://stackoverflow.com/questions/23957280/no-username-returned-in-facebook-profile/23986618#23986618

FacebookAuthService:

    String username = fbProfile.username // this is null, see link above, but username cannot be blank or nullable
    String firstName = fbProfile.firstName
    String lastName = fbProfile.lastName

    User person = new User(
            username: username,
            password: token.accessToken.accessToken, 
            enabled: true,
            accountExpired:  false,
            accountLocked: false,
            passwordExpired: false,

            //fill with data loaded from Facebook API
            name: [firstName, lastName].join(' '),
            email: email
    )
    person.save(failOnError: true) // if you add failOnError: true then the code will fail here and you see   the exception