Answer the question
In order to leave comments, you need to log in
How to make OAuth2 authorization through Vkontakte and Odnoklassniki on Spring Security?
Hello!
Tell me how to implement OAuth2 authorization for Vkontakte and Odnoklassniki on Spring Security? Now I have these settings:
spring:
security:
oauth2:
client:
registration:
vk:
clientName: vk
clientId: clientId
clientSecret: clientSecret
redirectUriTemplate: http://localhost:8080/login/vk/success
authorizationGrantType: authorization_code
clientAuthenticationMethod: form
scope: email
provider: vk
provider:
vk:
authorizationUri: https://oauth.vk.com/authorize
tokenUri: https://oauth.vk.com/access_token
userInfoUri: https://api.vk.com/method/users.get
userNameAttribute: id
@Configuration
@EnableOAuth2Client
class SecurityConfig extends WebSecurityConfigurerAdapter {
private OAuth2ClientContextFilter oauth2ClientContextFilter;
SecurityConfig(OAuth2ClientContextFilter oauth2ClientContextFilter) {
this.oauth2ClientContextFilter = oauth2ClientContextFilter
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated().and()
.logout().logoutSuccessUrl("/").permitAll().and()
.oauth2Login()
.redirectionEndpoint()
.baseUri("/login/vk/success")
}
}
2018-08-11 10:05:17.893 DEBUG 14757 --- [nio-8080-exec-5] o.s.b.w.s.f.OrderedRequestContextFilter : Bound request context to thread: org.springframework.session.w[email protected]6a12b9e9
2018-08-11 10:05:17.893 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 1 of 14 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2018-08-11 10:05:17.893 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 2 of 14 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2018-08-11 10:05:17.894 DEBUG 14757 --- [nio-8080-exec-5] o.s.d.redis.core.RedisConnectionUtils : Opening RedisConnection
2018-08-11 10:05:17.895 DEBUG 14757 --- [nio-8080-exec-5] o.s.d.redis.core.RedisConnectionUtils : Closing Redis Connection
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] w.c.HttpSessionSecurityContextRepository : HttpSession returned null object for SPRING_SECURITY_CONTEXT
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] w.c.HttpSessionSecurityContextRepository : No SecurityContext was available from the HttpSession: org.springframework.session.web.http.SessionRepo[email protected]60ead299. A new one will be created.
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 3 of 14 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 4 of 14 in additional filter chain; firing Filter: 'CsrfFilter'
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 5 of 14 in additional filter chain; firing Filter: 'LogoutFilter'
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] o.s.s.w.u.matcher.AntPathRequestMatcher : Request 'GET /login/vk/success' doesn't match 'POST /logout
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 6 of 14 in additional filter chain; firing Filter: 'OAuth2AuthorizationRequestRedirectFilter'
2018-08-11 10:05:17.900 DEBUG 14757 --- [nio-8080-exec-5] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/login/vk/success'; against '/oauth2/authorization/{registrationId}'
2018-08-11 10:05:17.901 DEBUG 14757 --- [nio-8080-exec-5] o.s.security.web.FilterChainProxy : /login/vk/success?code=c1447fa57e60c3c927&state=yn9oFB9FPrL7ZcxpjYcrR6_CHq7wjEk_KiBA5zO93x4= at position 7 of 14 in additional filter chain; firing Filter: 'OAuth2LoginAuthenticationFilter'
2018-08-11 10:05:17.901 DEBUG 14757 --- [nio-8080-exec-5] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/login/vk/success'; against '/login/vk/success'
2018-08-11 10:05:17.901 DEBUG 14757 --- [nio-8080-exec-5] .s.o.c.w.OAuth2LoginAuthenticationFilter : Request is to process authentication
2018-08-11 10:05:17.909 DEBUG 14757 --- [nio-8080-exec-5] o.s.s.authentication.ProviderManager : Authentication attempt using org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider
2018-08-11 10:05:38.699 DEBUG 14757 --- [nio-8080-exec-5] o.s.s.authentication.ProviderManager : Authentication attempt using org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer$OidcAuthenticationRequestChecker
2018-08-11 10:05:38.704 DEBUG 14757 --- [nio-8080-exec-5] .s.o.c.w.OAuth2LoginAuthenticationFilter : Authentication request failed: org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_client] client_secret is undefined
org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_client] client_secret is undefined
at org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient.getTokenResponse(NimbusAuthorizationCodeTokenResponseClient.java:116) ~[spring-security-oauth2-client-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient.getTokenResponse(NimbusAuthorizationCodeTokenResponseClient.java:67) ~[spring-security-oauth2-client-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:121) ~[spring-security-oauth2-client-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:174) ~[spring-security-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter.attemptAuthentication(OAuth2LoginAuthenticationFilter.java:164) ~[spring-security-oauth2-client-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question