eladmin icon indicating copy to clipboard operation
eladmin copied to clipboard

关于第三方授权登录token生成问题

Open janyyy opened this issue 5 years ago • 1 comments

我模仿PC 登录生成token,但是第三方授权登录的时候。我只能从数据库拿密码。密码并不可逆,到这一步的时候就会提示用户名和密码不正确。 UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword()); Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);

完整代码截图如下,能否给我点改造提示。有点迷。希望此贴有回复 image

janyyy avatar Jan 29 '21 10:01 janyyy

这个我改造好了。看代码 UserDetails userDetails = userDetailsService.loadUserByUsername(userInfo.getUsername());

Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());

SecurityContextHolder.getContext().setAuthentication(authentication);

shaokuuipo avatar Feb 01 '21 03:02 shaokuuipo