Sandeep Gupta

Sandeep Gupta

  • 1.5k
  • 147
  • 3.8k

How to Create Dynamic Signature,Nonce in OAuth 1.0 Auth

Sep 25 2019 11:53 AM
How to create dynamic Signature, Nonce, and Timestamp in Sql Server Stored Procedure?
 
When I access WebAPI type POST.
 
I have a problem, how can we access
  1. ALTER proc [dbo].[ImportPOFromERP]  
  2. as  
  3. -- Variable declaration  
  4. DECLARE @authHeader NVARCHAR(64);  
  5. DECLARE @contentType NVARCHAR(64);  
  6. DECLARE @postData NVARCHAR(2000);  
  7. DECLARE @responseText NVARCHAR(4000);  
  8. DECLARE @responseXML NVARCHAR(2000);  
  9. DECLARE @ret INT;  
  10. DECLARE @body NVARCHAR(max);  
  11. DECLARE @status NVARCHAR(32);  
  12. DECLARE @statusText NVARCHAR(32);  
  13. DECLARE @token INT;  
  14. DECLARE @url NVARCHAR(256);  
  15. -- Set Authentications  
  16. SET @contentType = 'text/plain';  
  17. SET @body='{"getPO":"true"}';  
  18. -- Set your desired url where you want to fire request  
  19. -- Open a connection  
  20. EXEC @ret = sp_OACreate 'MSXML2.ServerXMLHTTP', @token OUT;  
  21. IF @ret <> 0 RAISERROR('Unable to open HTTP connection.', 10, 1);  
  22. -- make a request  
  23. EXEC @ret = sp_OAMethod @token, 'open'NULL'POST''https://localhost/Example/api/GetData?script=872&deploy=1''false';  
  24. --set a custom header Authorization is the header key and VALUE is the value in the header  
  25. EXEC sp_OAMethod @token, 'SetRequestHeader'NULL'Authorization''OAuth realm="4453181_SB1",oauth_consumer_key="7072b99bacf89b48b7d72cad6b21548938caabcbfede58441ee52923a0d6b89",oauth_token="0c967370cc0f1a567686c175d8194a2db49815bd03811987f7ff4eceaadf288",oauth_signature_method="HMAC-SHA1",oauth_timestamp="",oauth_nonce="",oauth_version="1.0",oauth_signature=""';  
  26. EXEC @ret = sp_OAMethod @token, 'setRequestHeader'NULL'Content-type', @contentType;  
  27. EXEC @ret = sp_OAMethod @token, 'send',NULL, @body;  
  28. EXEC sp_OASetProperty @ret, 'AcceptCharset''';  
  29. --EXEC sp_OASetProperty @ret, 'UserAgent', ''  
  30. EXEC sp_OASetProperty @ret, 'AcceptLanguage''';  
  31. -- Suppress the Accept-Encoding header by disallowing  
  32. -- a gzip response:  
  33. EXEC sp_OASetProperty @ret, 'AllowGzip', 0;  
  34. EXEC @ret = sp_OAGetProperty @token, 'status', @status OUT;  
  35. EXEC @ret = sp_OAGetProperty @token, 'statusText', @statusText OUT;  
  36. EXEC @ret = sp_OAGetProperty @token, 'responseText', @responseText OUT;  
  37. -- Print responec  
  38. PRINT 'Status: ' + @status + ' (' + @statusText + ')';  
  39. PRINT 'Response text: ' + @responseText;  
  40. SELECT *  
  41. FROM OPENJSON(@responseText);  
  42. -- Close the connection.  
  43. EXEC @ret = sp_OADestroy @token;  
  44. IF @ret <> 0 RAISERROR('Unable to close HTTP connection.', 10, 1);