Authenticating GroupDocs for Cloud REST APIs via signing request URLs

Hello,

I am trying to create url signatures for requests to the API. I am following this page: https://api.groupdocs.com/v2.0/spec/#!/signature.

On that page I have entered my client ID and private key and can make requests successfully. When I try to generate the signature myself in my own application I cannot match the signature shown on the reference webpage.

The method I use to sign the url is to create a HMAC using SHA1 and the private key as the secret, then append signature=[generatedValue] to the query parameters. Is this an incorrect way to create the signature?

Thank you,
Sebastian


This Topic is created by tilal.ahmad using the Email to Topic plugin.

@Sebastian_Coraccio

Thanks for your inquiry. Please note we have released Next Generation GroupDocs for Cloud APIs with more enhanced, efficient and improved programming structure. I am afraid we are not fixing any issues or making improvements in old obsolete versions, because of their complex API structure. So we will appreciate it if you please try latest version of GroupDocs for Cloud APIs.

Please check the documentation to sign the request url along with following resources for more details about Next Generation GroupDocs.Signature for Cloud APIs. Please note currently only .NET SDK is available, we are in process of publishing SDKs for other platforms as well. Please feel free to contact us for any further assistance.

@tilal.ahmad I’m sorry, my original question was unclear. I am not trying to use the Signature API. My main use case is storing files and then providing a file preview to users. The link you have provided to sign the request url is for the new Cloud API. I am trying to sign a request to this endpoint https://apps.groupdocs.com/document-viewer/embed/{guid}, which I do not believe is part of the Cloud API.

Has the embedded document-viewer been deprecated? If it has, what alternatives are available for the Cloud API?

@Sebastian_Coraccio

Thanks for your feedback.

Yes, old GroupDocs Cloud apps are also depreciated. We are not fixing issues and making any improvement in these old Apps. We have plan to create new Apps based on new GroupDocs Cloud APIs in the future, but I am afraid we can not share any time line at the moment.

You can also render documents to HTML5/Image representation using Next Generation GroupDocs.Viewer for Cloud API and use result in your document viewing application.

However, you may try following code to signing the URL for old GropuDocs API, parse_url and hash_hmac are common PHP functions.

Please note it is PHP code and you can migrate it, if you are using different platform.

public function signUrl($url){
  $urlParts = parse_url($url);
  $pathAndQuery = $urlParts['path'].(empty($urlParts['query']) ? "" : "?".$urlParts['query']);
  $signature = base64_encode(hash_hmac("sha1", encodeURI($pathAndQuery), $privateKey, true));
  if(substr($signature, -1) == '='){
   $signature = substr($signature, 0, - 1);
  }
  $url = $url . (empty($urlParts['query']) ? '?' : '&') . 'signature=' . APIClient::encodeURIComponent($signature);
  return $url;
 }
        
 public static function encodeURI($url) {
     $reserved = array(
         '%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', 
         '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'
     );
     $unescaped = array(
         '%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':',
         '%40'=>'@','%26'=>'&','%3D'=>'=',
         //'%2B'=>'+',
         '%24'=>'$', '%25'=>'%'
     );
     $score = array(
         '%23'=>'#'
     );
     return strtr(rawurlencode($url), array_merge($reserved,$unescaped,$score));

 }
 
 public static function encodeURIComponent($str) {
     $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
     return strtr(rawurlencode($str), $revert);
 }