google-calendar-api 与 java spring boot

问题描述 投票:0回答:1

我正在开发一个java Springboot Web应用程序。其中我有多个用户使用地址邮件和密码登录。登录成功。

@Override
protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().antMatchers("/error.xhtml").permitAll().antMatchers("/error-404.xhtml").permitAll()
            .anyRequest().authenticated().accessDeniedPage("/accessDenied.xhtml");
    ;
    // login
    http.formLogin().loginPage("/login").permitAll().failureUrl("/login?error=1");
    // logout
    http.logout().logoutSuccessUrl("/login").invalidateHttpSession(true).deleteCookies("JSESSIONID");

    http.formLogin().defaultSuccessUrl("/dashboard", true);

    http.csrf().disable();
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
    authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

我不需要谷歌登录。我需要将他们的谷歌日历集成到应用程序帐户,所以嘿无法使用他们的 Gmail ID 创建活动和会议。

有什么方法可以将他们的谷歌帐户集成到应用程序中,只需在设置中仅获得用户一次同意。

enter image description here

java spring-boot google-oauth google-calendar-api google-api-java-client
1个回答
0
投票

您应该看看官方样本

// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
    .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
    .setAccessType("offline")
    .build();

如果 FileDataStoreFactory 配置正确,它将存储每个用户的凭据,那么您只需要请求访问一次。

© www.soinside.com 2019 - 2024. All rights reserved.