cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to authenticate users if storefront has to offer login with Facebook or Google?

Former Member
0 Kudos
944

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?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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;
     }
Former Member
0 Kudos

Thanks you for the answer, you've given us an idea on what to do, we'll try our solution and let you know how does it perform.

Answers (0)