on 2018 Feb 15 1:23 AM
We're working with Hybris 6.2, we are required to offer users the login option with Facebook or Google.
Since the login authentication is handled by either Facebook or Google, how do we handle the authentication? Since username and password are required to authenticate in Hybris, how do we authorize users who logged through any of these two methods?
We are generating a new customer model and saving it, but we understand there won't be credentials stored in this customer, but credentials are required to authenticate a user in Hybris.
How do we handle this scenario?
Request clarification before answering.
Hi Agustin,
Hope I can answer your question as I have implemented both login feature in our storefront
Once authentication done by google and facebook, They give us customer Firstname, lastname and email id. fetching this information you can register them in hybris as customer with your own customergroup(SocialUser or whatever). However I am not able to give whole code, just give you a hint which may help you. look at the below methods to get the idea.
private void autoLoginForCustomer(final UserModel hybrisUser, final HttpServletRequest request,
final HttpServletResponse response)
{
final de.hybris.platform.jalo.user.User sessionUser = JaloSession.getCurrentSession().getUserManager()
.getUserByLogin(hybrisUser.getUid());
final String cusomerRole = "ROLE_" + GoogleaddonWebConstants.Permission.CUSTOMER_USERGROUP.toUpperCase();
JaloSession.getCurrentSession().setUser(sessionUser);
userService.setCurrentUser(hybrisUser);
final UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(hybrisUser.getUid(),
"auth", Arrays.asList(new SimpleGrantedAuthority(cusomerRole)));
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
getCustomerFacade().loginSuccess();
getGuidCookieStrategy().setCookie(request, response);
}
private GoogleUser getGoogleUserInfo(GoogleIdToken.Payload payLoad)
{
final GoogleUser googleUser = new GoogleUser();
final String userId = payLoad.getSubject();
System.out.println("User ID: " + userId);
// Get profile information from payload
final String email = payLoad.getEmail();
final String name = (String) payLoad.get("name");
final String familyName = (String) payLoad.get("family_name");
final String givenName = (String) payLoad.get("given_name");
// Use or store profile information
// ...
googleUser.setId(userId);
googleUser.setFirstName(givenName);
googleUser.setLastName(familyName);
googleUser.setEmail(email);
return googleUser;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.