Контроллер
@Controller
public class ControllerWeb
{
@RequestMapping("/securedPage")
public String securedPage(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 "securedPage";
}
/*
* @RequestMapping("/") public String index(Model model, Principal principal) {
* return "index"; }
*/
}
Конфигурация
@Configuration
public class SecurityConfiq extends WebSecurityConfigurerAdapter
{
@Override
public void configure(HttpSecurity http) throws Exception
{
http.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**")
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2Login();
}
}
yml
okta:
oauth2:
issuer: https://dev-183012.okta.com/oauth2/default
client-id: 0oa19etgkSVJXgZid4x6
client-secret: jNWytO6XMNjcT4tHuDlbLk51o1jqIpGspTrlrk7w
spring:
thymeleaf:
cache: false