Sample code for 30+ languages & platforms
SQL Server

Generate OAuth 1.0 Signature

Demonstrates how to generate an OAuth 1.0 signature.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    SELECT @success = 0

    DECLARE @oauth int
    EXEC @hr = sp_OACreate 'Chilkat.OAuth1', @oauth OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- Set input parameters:
    EXEC sp_OASetProperty @oauth, 'OauthVersion', '1.0'
    EXEC sp_OASetProperty @oauth, 'OauthMethod', 'GET'
    EXEC sp_OASetProperty @oauth, 'OauthUrl', 'http://echo.lab.madgex.com/echo.ashx'
    EXEC sp_OASetProperty @oauth, 'ConsumerKey', 'key'
    EXEC sp_OASetProperty @oauth, 'ConsumerSecret', 'secret'
    EXEC sp_OASetProperty @oauth, 'Token', 'accesskey'
    EXEC sp_OASetProperty @oauth, 'TokenSecret', 'accesssecret'
    EXEC sp_OASetProperty @oauth, 'Nonce', '01020304050607080102030405060708'
    EXEC sp_OASetProperty @oauth, 'Timestamp', '1441659763'
    -- Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
    EXEC sp_OASetProperty @oauth, 'SignatureMethod', 'HMAC-SHA256'

    EXEC sp_OAMethod @oauth, 'Generate', @success OUT
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @oauth, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @oauth
        RETURN
      END

    -- Examine the various outputs:

    EXEC sp_OAGetProperty @oauth, 'QueryString', @sTmp0 OUT
    PRINT @sTmp0
    EXEC sp_OAGetProperty @oauth, 'BaseString', @sTmp0 OUT
    PRINT @sTmp0
    EXEC sp_OAGetProperty @oauth, 'HmacKey', @sTmp0 OUT
    PRINT @sTmp0
    EXEC sp_OAGetProperty @oauth, 'Signature', @sTmp0 OUT
    PRINT @sTmp0
    EXEC sp_OAGetProperty @oauth, 'EncodedSignature', @sTmp0 OUT
    PRINT @sTmp0
    EXEC sp_OAGetProperty @oauth, 'AuthorizationHeader', @sTmp0 OUT
    PRINT @sTmp0
    EXEC sp_OAGetProperty @oauth, 'GeneratedUrl', @sTmp0 OUT
    PRINT @sTmp0

    EXEC @hr = sp_OADestroy @oauth


END
GO