1

I followed this tutorial on trying to authenticate my users to my REST API, everything works and my principal returns my name, but I don't seem to get any of the other data (email, friends list etc inside the scope). How do I do this using spring?

Yaml configuration file:

    security:
  oauth2:
    client:
      clientId: CENSORED
      clientSecret: CENSORED
      accessTokenUri: https://graph.facebook.com/oauth/access_token
      userAuthorizationUri: https://www.facebook.com/dialog/oauth
      tokenName: oauth_token
      authenticationScheme: query
      clientAuthenticationScheme: form
      scope: email,user_friends,public_profile
    resource:
      userInfoUri: https://graph.facebook.com/me
  user:
    password: password

spring:
  social:
    facebook:
      app-id: CENSORED
      app-secret: CENSORED

RestController:

    @RestController
public class UserController {

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public Principal user(FixedPrincipalExtractor extractor, Principal principal)   {

        return principal;
    }
}

I need this information since I want to be able to mail my users, and also see if other 'friends' also use this application.

Thanks in advance! Please ask if something is unclear.

(I use maven as a package manager, with spring security as the authentication for my RESTFul API Which should connect to my AngularJS frontend || I'm new to Spring, I usually build REST API's using JAX-RS)

TVH7
  • 415
  • 2
  • 5
  • 19
  • 1
    i don´t know spring, but i assume that it is about declarative fields. take a look at this thread: http://stackoverflow.com/questions/32584850/facebook-js-sdks-fb-api-me-method-doesnt-return-the-fields-i-expect-in-gra – andyrandy Dec 23 '16 at 07:56

1 Answers1

4

I had the same issue where I got just the id and name fields in the response Map.

@luschn is right. We need to explicitly specify the response fields.

For email, I modified the userInfoUri property as

resource: userInfoUri: https://graph.facebook.com/me?fields=id,name,email

Use this graph explorer tool to see what fields you need in your response.

https://developers.facebook.com/tools/explorer/

Happy coding!

abhi
  • 41
  • 3