I need to program the login of users who have been authenticated through the Facebook API. The reason for this is that there are a number of elements that are associated with each user (for example, with a shopping cart), therefore, as soon as the user authenticates using the Facebook API, I need to register the user using spring security so that he can access his basket.
Based on my research, there are many methods for implementing it, but I could not deploy them, because I send a login request from my code, and another problem is that some people created a user object, but they did not explain how create it.
Those who created a custom object, but did not explain how to do this.
From the first example: this answer
Authentication auth = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
From the second example: this
34.User details = new User(username); 35.token.setDetails(details);
From the third example: this
Authentication authentication = new UsernamePasswordAuthenticationToken(user, null, AuthorityUtils.createAuthorityList("ROLE_USER"));
The following example , this does not help, because I need to log in from my own code, and not from the browser; so I donβt know how to populate the HttpServletRequest object.
protected void automatedLogin(String username, String password, HttpServletRequest request) {
Mycode
... if(isAuthenticatedByFB()) { login(username); return "success"; } else{ return "failed"; }