theswolf
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Plugins
In reply to: [WP OAuth Server (OAuth Authentication)] Spring-boot oauth2 authenticationI was mismatching a URL:
accessTokenUri: http://localhost:8080/wordpress?oauth=access_token
should be
accessTokenUri: http://localhost:8080/wordpress?oauth=token
and all is working good
thank you very much Justin.Forum: Plugins
In reply to: [WP OAuth Server (OAuth Authentication)] Spring-boot oauth2 authenticationYes, i have configured wp pauth server with enabled:
Authorization code and refresh code.
After that I’ve configured my spring ouath 2 as follow:wp: client: clientId: xxx clientSecret: xxx accessTokenUri: http://localhost:8080/wordpress?oauth=access_token userAuthorizationUri: http://localhost:8080/wordpress?oauth=authorize resource: userInfoUri: http://localhost:8080/wordpress/oauth/meand this is my java config:
@EnableOAuth2Client @Configuration public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired OAuth2ClientContext oauth2ClientContext; @RequestMapping("/user") public Principal user(Principal principal) { return principal; } @Override protected void configure(HttpSecurity http) throws Exception { // @formatter:off http.antMatcher("/**") .authorizeRequests() .antMatchers("/", "/login**", "/webjars/**").permitAll() .anyRequest().authenticated() .and().exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/")) .and().logout().logoutSuccessUrl("/").permitAll() .and().csrf().csrfTokenRepository(csrfTokenRepository()) .and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class) .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class); // @formatter:on } @Bean public FilterRegistrationBean oauth2ClientFilterRegistration( OAuth2ClientContextFilter filter) { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(filter); registration.setOrder(-100); return registration; } private Filter ssoFilter() { OAuth2ClientAuthenticationProcessingFilter wpFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/wp"); OAuth2RestTemplate wpTemplate = new OAuth2RestTemplate(wp(), oauth2ClientContext); wpFilter.setRestTemplate(wpTemplate); wpFilter.setTokenServices(new UserInfoTokenServices(wpResource().getUserInfoUri(), wp().getClientId())); return wpFilter; } @Bean @ConfigurationProperties("wp.client") OAuth2ProtectedResourceDetails wp() { return new AuthorizationCodeResourceDetails(); } @Bean @ConfigurationProperties("wp.resource") ResourceServerProperties wpResource() { return new ResourceServerProperties(); } private Filter csrfHeaderFilter() { return new OncePerRequestFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName()); if (csrf != null) { Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN"); String token = csrf.getToken(); if (cookie == null || token != null && !token.equals(cookie.getValue())) { cookie = new Cookie("XSRF-TOKEN", token); cookie.setPath("/"); response.addCookie(cookie); } } filterChain.doFilter(request, response); } }; } private CsrfTokenRepository csrfTokenRepository() { HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository(); repository.setHeaderName("X-XSRF-TOKEN"); return repository; }shuld be ok but every time i try to log I’ve got this message:
There was an unexpected error (type=Unauthorized, status=401).
Authentication Failed: Could not obtain access token
Viewing 2 replies - 1 through 2 (of 2 total)