简体   繁体   English

Spring Security调用以编程方式登录

[英]Spring Security call login programmatically

I am developing an application and I am using Spring Security. 我正在开发一个应用程序,并且正在使用Spring Security。 My question is - is there a way to call the exact logic that is run when I send a post request to /login (default), but from within the programme? 我的问题是-当我从程序内部向/ login发送后置请求(默认)时,是否可以调用运行的确切逻辑?

Normally, I post my LoginUserDto object to /login endpoint to login. 通常,我将我的LoginUserDto对象发布到/ login端点以进行登录。 However, I am implementing facebook login now, so I am constructing my LoginUserDto on the server side from whatever data I get from facebook based on user's access token. 但是,我现在正在实现Facebook登录,因此我将根据用户访问令牌从Facebook获得的任何数据在服务器端构造我的LoginUserDto。 Now I just need to call the same logic that I would normally call with the rest call to /login, but from within the code in order to return tokens. 现在,我只需要调用正常情况下与/ login的其余调用相同的逻辑,但是从代码内部调用,以便返回令牌。

Does anyone know how this can be done? 有谁知道该怎么做? Thanks 谢谢

You should look at Spring Security 5's inbuilt support for OAuth2, as this will be the easiest way to incorporate Facebook as an external Authorization Server. 您应该查看Spring Security 5对OAuth2的内置支持,因为这将是将Facebook集成为外部授权服务器的最简单方法。 There is some good documentation which walks through what is necessary via OAuth2 Login. 有一些很好的文档 ,介绍了通过OAuth2登录进行必要的操作。 Additionally, I found working with the oauth2login sample code from the Spring Security Repository extremely helpful to understand how the application should be configured, and it has a section for integrating with Facebook. 另外,我发现使用Spring Security Repository中的oauth2login示例代码对理解如何配置应用程序非常有帮助,并且其中有一个用于与Facebook集成的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM