Spring Boot and OAuth2 client refresh token grant

1.2k views Asked by At

I want to configure spring boot with oauth2 to work in the flow Refresh token grant. All I need is to send request with grant type set as "refresh_token" and with field refresh token, where I want to put my token. In response I receive access token.

For the flow Resource owner credentials grant, I had such configuration:

@EnableOAuth2Client
@Configuration
public class AuthConfig {
    @Value("${conf.client-id}")
    private String clientId;
    @Value("${conf.client-secret}")
    private String clientSecret;
    @Value("${conf.access-token-uri}")
    private String tokenUrl;
    @Value("${conf.grant-type}")
    private String grantType;
    @Value("${conf.refresh-token}")
    private String refreshToken;
    @Value("${conf.username}")
    private String username;
    @Value("${conf.password}")
    private String password;

    @Bean
    public OAuth2ProtectedResourceDetails resourceDetails() {
        ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
        resource.setAccessTokenUri(tokenUrl);
        resource.setClientId(clientId);
        resource.setClientSecret(clientSecret);
        resource.setGrantType(grantType);
        resource.setPassword(password);
        resource.setUsername(username);
        return resource;
    }

    @Autowired
    private OAuth2ClientContext oauth2Context;

    @Bean
    public OAuth2RestTemplate oauth2RestTemplate(
        OAuth2ClientContext oauth2Context, OAuth2ProtectedResourceDetails details
    )
    {
        return new OAuth2RestTemplate(details, oauth2Context);
    }
}

Is it possible to build OAuth2ProtectedResourceDetails with refresh token and without username and password?

I'm newbie in SpringBoot but I read a lot of topics and I can't find the answer.

0

There are 0 answers