问题
Dears,
I have generated an app thanks to jHipster. However, in order to be sure that I map social profiles with local accounts, I want users to sign up their social accounts once connected only. Social Connection must be optional (users' convenience).
In brief, I want to use JWT tokens to sign up social profiles and either JWT or oAuth to signin when activated.
Technically, I thought I just had to enhance the code of both SocialUser and SocialService to match ProfileInfo (from social authentication response) to the local user login info.
Unfortunately, the social service doesn't return any authentication info (from Spring Security)and I cannot retrieve Principal.
Any idea which may help?
Sample code:
// Find user within the social repository thanks to his userId
if (StringUtils.isBlank(email) && !StringUtils.isBlank(usrId)) {
Optional<SocialUser> sUser = suDao.findOneByUsrId(usrId);
if (sUser.isPresent()) {
// Retrieve corresponding user
return Optional.of(sUser.get().getUser());
} else {
// Create Social User
Optional<User> oUsr = uDao.findOneByUsername(SecurityUtils.getCurrentUserLogin());
if (oUsr.isPresent()) {
User u = oUsr.get();
SocialUser su = new SocialUser(u.getExternalId(), usrId, providerId, u);
suDao.save(su);
log.debug("Creating social user for: {}", u);
}
}
}
来源:https://stackoverflow.com/questions/45757438/jhipster-spring-social-principal