Twitch Oauth User Retrieval 401 with Spring Boot 2+

The following is my temporary solution. I had to create a custom authenticator instead of the default one and then assign it to the RestTemplate.

private class BearerTypeOAuth2RequestAuthenticator implements OAuth2RequestAuthenticator {

    @Override
    public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext,
        ClientHttpRequest request) {
        OAuth2AccessToken accessToken = clientContext.getAccessToken();
        if (accessToken == null) {
            throw new AccessTokenRequiredException(resource);
        }
        request.getHeaders().set("Authorization", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, accessToken.getValue()));
    }
}