예제 #1
0
 @Override
 public void signRequest(final Token accessToken, final AbstractRequest request) {
   request.addHeader(
       "Authorization",
       accessToken != null
           ? "Bearer " + accessToken.getToken()
           : "Client-ID " + getConfig().getApiKey());
 }
  @Override
  public void signRequest(Token accessToken, AbstractRequest request) {
    // sig = md5( request_params_composed_string+ md5(access_token + application_secret_key)  )
    try {
      final String tokenDigest = md5Hex(accessToken.getToken() + getConfig().getApiSecret());

      final String completeUrl = request.getCompleteUrl();
      final int queryIndex = completeUrl.indexOf('?');
      if (queryIndex != -1) {
        final String sigSource =
            URLDecoder.decode(
                    completeUrl.substring(queryIndex + 1).replace("&", ""), CharEncoding.UTF_8)
                + tokenDigest;
        request.addQuerystringParameter("sig", md5Hex(sigSource));
      }

      super.signRequest(accessToken, request);
    } catch (UnsupportedEncodingException unex) {
      throw new IllegalStateException(unex);
    }
  }