Spring OAuth2 - Custom "Auth Approval Claim" on oauth / authorize page

Recommended way to create custom pages. OAuth Approval Page:

default page

I need to completely redefine the material on the page, add styles, branding, etc. What is the right way to achieve this? Where can I see the default page source to use as a starting point?

I also need to override the / login page, but I think the approach to overriding it will be pretty much the same.

+6
source share
2 answers

The recommended way is to provide a normal Spring MVC @RequestMapping for the "/ oauth / confirm_access" parameter. You can look at WhitelabelApprovalEndpoint for a default implementation. Remember to use @SessionAttributes("authorizationRequest") .

+7
source

In addition to @DaveSyer answer , which should work for most cases. Sometimes based on configuration and configuration, the above method may not work if Framew‌orkEndpointHandlerMa‌pping from Spring Security OAuth package is in a higher order than RequestMappingHandlerMapping your application. If so, the servlet manager will never reach your match and will always display the default page.

One way to fix this is to change the display order, given that Framew‌orkEndpointHandlerMa‌pping order Order.LOWEST_PRECEDENCE - 2 .

Another way is to set the approval page to your own URL rather than being displayed using Framew‌orkEndpointHandlerMa‌pping , so the servlet manager will reach your application mapping

 @Configuration @EnableAuthorizationServer protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { @Autowired private AuthorizationEndpoint authorizationEndpoint; @PostConstruct public void init() { authorizationEndpoint.setUserApprovalPage("forward:/oauth/custom_confirm_access"); authorizationEndpoint.setErrorPage("forward:/oauth/custom_error"); } } 

With this configuration, the displays /oauth/custom_confirm_access and /oauth/custom_error will be used as a confirmation page and an error page, respectively.

+1
source

Source: https://habr.com/ru/post/984435/


All Articles