Answer the question
In order to leave comments, you need to log in
How to get access token for Google services API with OAuth 2.0 on Spring?
OAuth 2.0 configured, it seems to work. The user in the Security context is saved. The Google API documentation says that in order to create an object of a service, you need to pass an access-token to it, but how can you get this token from? At the moment, the application yaml for the OAuth configuration and the WebSecurityConfig itself are described:
Web Security Config
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login();
}
}
spring:
security:
oauth2:
client:
provider:
google:
client-id: ****
client-secret: ****
scope:
- email
- profile
- https://www.googleapis.com/auth/calendar
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Credential credential = (Credential) authentication.getCredentials();
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