使用OAuth2ClientAuthenticationProcessingFilter通过spring boot登录Google Oauth2

时间:2017-09-09 15:17:13

标签: java spring-boot spring-security oauth-2.0

1.使用spring security oauth2 dependcy.Making成功验证谷歌但我无法获得刷新令牌。我如何获得刷新令牌?ı只能从PrincapalUser对象获取访问令牌。

在WebSecurityConfigurer适配器

2

private OAuth2ClientAuthenticationProcessingFilter filter() {
        // Creating the filter for "/google/login" url
        OAuth2ClientAuthenticationProcessingFilter oAuth2Filter = new
                OAuth2ClientAuthenticationProcessingFilter(
                "/google/login");
        authorizationCodeResourceDetails.setPreEstablishedRedirectUri("http://localhost:8080/");
        List<String> scopes = authorizationCodeResourceDetails.getScope();
        authorizationCodeResourceDetails.setGrantType("authorization_code");


        // Creating the rest template for getting connected with OAuth service.
        // The configuration parameters will inject while creating the bean.
        OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(authorizationCodeResourceDetails,
                oauth2ClientContext);


        oAuth2Filter.setRestTemplate(oAuth2RestTemplate);


        // setting the token service. It will help for getting the token and
        // user details from the OAuth Service
        String userInfo = resourceServerProperties.getUserInfoUri();
        String clientId = resourceServerProperties.getClientId();

        UserInfoTokenServices tokenService = new UserInfoTokenServices(resourceServerProperties.getUserInfoUri(),
                resourceServerProperties.getClientId());
       // tokenService.setTokenType(DefaultOAuth2AccessToken.REFRESH_TOKEN);


        oAuth2Filter.setTokenServices(tokenService);
//        oAuth2Filter.setTokenServices(defaultToken());


        return oAuth2Filter;
    }

1 个答案:

答案 0 :(得分:0)

我添加了google url param requriments,spring boot application.yml社交身份验证配置。