简体   繁体   English

使用 oauth2 + JWT 的 Springboot 社交登录

[英]Springboot Social login with oauth2 + JWT

I am developing a REST monolith service.我正在开发一个 REST 整体服务。 With it i need to be able to register users through social networks, store them internally in my database and authorize them with certain authorities.有了它,我需要能够通过社交网络注册用户,将它们内部存储在我的数据库中,并通过某些权限授权它们。 After which i need the service to use JWT for security, the service needs to run in STATELESS mode.之后我需要该服务使用 JWT 以确保安全,该服务需要以无状态模式运行。

I've read a lot of articles over the past week but they either explain only a small part of it or they don't explain what they are using and why.在过去的一周里,我读了很多文章,但他们要么只解释了一小部分,要么没有解释他们正在使用什么以及为什么。

I am using spring security 5 which enables "easy" integration for session login with social networks which i managed to pull of by using我正在使用 spring 安全 5,它可以“轻松”集成 session 登录与社交网络,我设法通过使用

.oauth2Login()

in my configure method of WebSecurityConfigurerAdapter, but it utilizes session creation.在我的 WebSecurityConfigurerAdapter 配置方法中,但它利用 session 创建。 If i tell it to be STATELESS it will not function.如果我告诉它是无状态的,它不会是 function。

Also, I managed to set up JWT security where my service issues tokens, but I do not know how to connect those two.此外,我设法设置了 JWT 安全性,我的服务在其中发布令牌,但我不知道如何连接这两者。 I've seen that我已经看到了

oauth2ResourceServcer()

method has jwt method but I canot grasp on how i should implement it.方法有 jwt 方法,但我无法掌握我应该如何实现它。

Does anyone have any suggestion or an example that I could follow?有没有人有任何建议或我可以遵循的例子? Any help would be much appreciated.任何帮助将非常感激。

Kind Regards亲切的问候

Social logins are implemented one by one, there is no library that will provide with with seamless out-of-the-box solution that will include all social platforms.社交登录是一一实现的,没有库可以提供无缝的开箱即用解决方案,包括所有社交平台。

Enabling spring security will give you nothing more than extra layer of protection and the ability to manage the users yourself, without social logins if you want to.启用 spring 安全性只会为您提供额外的保护层和自行管理用户的能力,如果您愿意,无需社交登录。

For my projects with social login I have been using keycloak .对于我的社交登录项目,我一直在使用keycloak It will handle all the security for you and has nice integration with spring boot .它将为您处理所有安全问题,并与 spring boot 很好地集成 Furthermore it provides login form (without social login), so you will give your users full flexibility.此外,它提供登录表单(没有社交登录),因此您将为您的用户提供充分的灵活性。

Main drawback for me is that the UI is a real pain to customise and I had trouble running it behind nginx https reverse proxy, but it is doable and there are plenty of resources out threre.对我来说主要的缺点是 UI 很难定制,而且我在 nginx https 反向代理后面运行它时遇到了麻烦,但它是可行的,并且有很多资源可供使用。

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

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