.ietf.org/html/draft-ietf-oauth-v2-23#section-4.1.3">Access Token Request.
Use {@link Credential} to access protected resources from the resource server usingthe {@link TokenResponse} returned by {@link #execute()}. On error, it will instead throw {@link TokenResponseException}.
Sample usage:
static void requestAccessToken() throws IOException { try { TokenResponse response = new AuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), new GenericUrl("https://server.example.com/token"), "SplxlOBeZQQYbYS6WxSbIA") .setRedirectUri("https://client.example.com/rd") .setClientAuthentication( new BasicAuthentication("s6BhdRkqt3", "7Fjfp0ZBr1KtDRbnfVdmIw")).execute(); System.out.println("Access token: " + response.getAccessToken()); } catch (TokenResponseException e) { if (e.getDetails() != null) { System.err.println("Error: " + e.getDetails().getError()); if (e.getDetails().getErrorDescription() != null) { System.err.println(e.getDetails().getErrorDescription()); } if (e.getDetails().getErrorUri() != null) { System.err.println(e.getDetails().getErrorUri()); } } else { System.err.println(e.getMessage()); } } }
Some OAuth 2.0 providers don't support {@link BasicAuthentication} but instead support{@link ClientParametersAuthentication}. In the above sample code, simply replace the class name and it will work the same way.
Implementation is not thread-safe.
@since 1.7
@author Yaniv Inbar