Quantcast
Channel: Spring Community Forums - Social
Viewing all articles
Browse latest Browse all 145

Possible problem with OAuth2Template?

$
0
0
Craig,

When I am trying to configure my OAuth2Template, I do the following:

Code:

                OAuth2Template oAuth2Template = new OAuth2Template(clientId, clientSecret, "someAuthenticateUrl", "someAccessTokenUrl");
                oAuth2Template.setUseParametersForClientAuthentication(true);

The problem is in the constructor of the OAuth2Template. Look at the following:
Code:

        public OAuth2Template(String clientId, String clientSecret, String authorizeUrl, String authenticateUrl, String accessTokenUrl) {
                Assert.notNull(clientId, "The clientId property cannot be null");
                Assert.notNull(clientSecret, "The clientSecret property cannot be null");
                Assert.notNull(authorizeUrl, "The authorizeUrl property cannot be null");
                Assert.notNull(accessTokenUrl, "The accessTokenUrl property cannot be null");
                this.clientId = clientId;
                this.clientSecret = clientSecret;
                String clientInfo = "?client_id=" + formEncode(clientId);
                this.authorizeUrl = authorizeUrl + clientInfo;
                if (authenticateUrl != null) {
                        this.authenticateUrl = authenticateUrl + clientInfo;
                } else {
                        this.authenticateUrl = null;
                }
                this.accessTokenUrl = accessTokenUrl;
                this.restTemplate = createRestTemplate();
                if (!useParametersForClientAuthentication) {
                        restTemplate.getInterceptors().add(new PreemptiveBasicAuthClientHttpRequestInterceptor(clientId, clientSecret));
                }
        }

As part of the constructor invocation, we are automatically adding a PreemptiveBasicAuthClientHttpRequestInterceptor before we get the chance to set the value of the useParametersForClientAuthentication variable to "true". As a result, this interceptor will always get added regardless of whether or not I call oAuth2Template.setUseParametersForClientAuthentica tion(true).

This has created some headaches when writing a new social API. Thoughts?

-Joshua

Viewing all articles
Browse latest Browse all 145

Trending Articles