ceramicthree
@ceramicthree

Как получить access token для API Google сервисов при OAuth 2.0 на Spring?

OAuth 2.0 сконфигурировал, вроде работает. Пользователь в контексте Security сохраняется. В документации Google API написано, что для создания объекта какого-либо сервиса нужно передать в него access-token, а как откуда этот токен взять? На данным момент описан application yaml для конфигурации OAuth и сам WebSecurityConfig:
Web Security Config
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .anyRequest().authenticated()
            .and()
            .oauth2Login();
    }
}

Application.yaml
spring:
  security:
    oauth2:
      client:
        provider:
          google:
            client-id: ****
            client-secret: ****
            scope:
            - email
            - profile
            - https://www.googleapis.com/auth/calendar


Как теперь в методе достать после аутентификации пользователя его credentials или access-token? Кастить Credential из SecurityContext до Credential представленные в библиотеки Google не получилось(
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Credential credential = (Credential) authentication.getCredentials();
  • Вопрос задан
  • 239 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽