playframework-2.0play-authenticate

play-authenticate - getting user information on scala views or controller for logged in user


I'm using Google via play-authenticate for authentication in my java application. This is my first play-framework application.

I need data of logged-in user on scala HTML page or controller. @currentAuth does not have user-name, which is there in GoogleAuthUser and is available during authentication. Since authentication request is directly handled in play-authenticate, I dont get that information to set it on session.

What is the best way to make the user data available to scala views or controller for play-authenticate applications? Examples are using @currentAuth, which only has provider name and Id, not the user data.


Solution

  • Found the solution in an example application. Controller can have a static method that uses session information to fetch user information from session using PlayAuthenticate.getUser(final Session session)

    public static User getLocalUser(final Session session) {
      final User localUser = User.findByAuthUserIdentity(PlayAuthenticate.getUser(session));
      return localUser;
    }