一、OAuth2
1.1、使用github以授权码方式
1.1.1、注册应用程序
1.1.2、测试代码
pom依赖
org.springframework.boot spring-boot-starter-oauth2-client
spring: security: oauth2: client: registration: github: client-id: Ov23liQnQPka0x1qX6ZI client-secret: 278f3ad4ecdd8dad4b318d7bd8d33f2bb9428019
@Controller public class IndexController { @GetMapping("/") public String index(Model model, @RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient, @AuthenticationPrincipal OAuth2User oauth2User) { model.addAttribute("userName", oauth2User.getName()); model.addAttribute("clientName", authorizedClient.getClientRegistration().getClientName()); model.addAttribute("userAttributes", oauth2User.getAttributes()); return "index"; } }
Spring Security - OAuth 2.0 Login User:
OAuth 2.0 Login with Spring Security
You are successfully logged in via the OAuth 2.0 Client User Attributes:- :
还没有评论,来说两句吧...