@@ -192,6 +192,47 @@ protected OAuthRequest createAccessTokenPasswordGrantRequest(String username, St
192192 return request ;
193193 }
194194
195+ public final Future <OAuth2AccessToken > getAccessTokenClientCredentialsGrantAsync () {
196+ return getAccessTokenClientCredentialsGrant (null );
197+ }
198+
199+ public final OAuth2AccessToken getAccessTokenClientCredentialsGrant ()
200+ throws IOException , InterruptedException , ExecutionException {
201+ final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest ();
202+
203+ return sendAccessTokenRequestSync (request );
204+ }
205+
206+ /**
207+ * Start the request to retrieve the access token using client-credentials grant. The optionally provided callback
208+ * will be called with the Token when it is available.
209+ *
210+ * @param callback optional callback
211+ * @return Future
212+ */
213+ public final Future <OAuth2AccessToken > getAccessTokenClientCredentialsGrant (
214+ OAuthAsyncRequestCallback <OAuth2AccessToken > callback ) {
215+ final OAuthRequest request = createAccessTokenClientCredentialsGrantRequest ();
216+
217+ return sendAccessTokenRequestAsync (request , callback );
218+ }
219+
220+ protected OAuthRequest createAccessTokenClientCredentialsGrantRequest () {
221+ final OAuthRequest request = new OAuthRequest (api .getAccessTokenVerb (), api .getAccessTokenEndpoint ());
222+ final OAuthConfig config = getConfig ();
223+ request .addParameter (OAuthConstants .CLIENT_ID , config .getApiKey ());
224+ final String apiSecret = config .getApiSecret ();
225+ if (apiSecret != null ) {
226+ request .addParameter (OAuthConstants .CLIENT_SECRET , apiSecret );
227+ }
228+ final String scope = config .getScope ();
229+ if (scope != null ) {
230+ request .addParameter (OAuthConstants .SCOPE , scope );
231+ }
232+ request .addParameter (OAuthConstants .GRANT_TYPE , OAuthConstants .CLIENT_CREDENTIALS );
233+ return request ;
234+ }
235+
195236 /**
196237 * {@inheritDoc}
197238 */
0 commit comments