@Inject
private Repository<User> repository;
//public void registerUser(@Observes SocialEvent<OAuthSession> event) { https://issues.jboss.org/browse/AGOVA-53
public void registerUser(@Observes SuccessfulAuthentication event) {
TwitterProfile profile = (TwitterProfile)event.getProfile();
User user = repository.get(profile.getScreenName());
if(user == null) {
user = new User(profile.getScreenName());
}
user.setName(profile.getFullName());
user.setBio(profile.getDescription());
user.setAvatarUrl(profile.getProfileImageUrl());
OAuthToken token = event.getToken();
user.setAccessToken(token.getSecret() + "|" + token.getToken());
if(user.getApiToken() == null) {
user.setApiToken(UUID.randomUUID().toString());
}