sb.append("Basic ");
try {
String data = consumer.getKey() + ":" + consumer.getSecret();
sb.append(Base64Utility.encode(data.getBytes("UTF-8")));
} catch (Exception ex) {
throw new ClientException(ex);
}
accessTokenService.header("Authorization", sb.toString());
} else {
form.set(OAuthConstants.CLIENT_ID, consumer.getKey());
form.set(OAuthConstants.CLIENT_SECRET, consumer.getSecret());
}
} else {
// in this case the AccessToken service is expected to find a mapping between
// the authenticated credentials and the client registration id
}
Response response = accessTokenService.form(form);
Map<String, String> map = null;
try {
map = new OAuthJSONProvider().readJSONResponse((InputStream)response.getEntity());
} catch (IOException ex) {
throw new ClientException(ex);
}
if (200 == response.getStatus()) {
ClientAccessToken token = fromMapToClientToken(map);
if (token == null) {
throw new OAuthServiceException(OAuthConstants.SERVER_ERROR);