Sample code for 30+ languages & platforms
SQL Server

Clear REST Authentication Settings

See more REST Examples

Demonstrates Rest.ClearAuth, which removes any authentication providers and credentials previously configured through the SetAuth* methods.

Background. Clearing authentication is useful when reusing a Rest object for a request that must be sent without credentials, or before switching to a different authentication method.

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
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

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

    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'example.com', 443, @bTls, @bAutoReconnect
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    --  Normally you would not hard-code secrets in source.  You should instead obtain them from an
    --  interactive prompt, environment variable, or a secrets vault.
    DECLARE @username nvarchar(4000)
    SELECT @username = 'myUsername'
    DECLARE @password nvarchar(4000)
    SELECT @password = 'myPassword'
    EXEC sp_OAMethod @rest, 'SetAuthBasic', @success OUT, @username, @password
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    --  ClearAuth removes any authentication providers and credentials previously configured through the
    --  SetAuth* methods, for example before reusing the object for an unauthenticated request.
    EXEC sp_OAMethod @rest, 'ClearAuth', @success OUT


    PRINT 'Authentication cleared.'

    EXEC @hr = sp_OADestroy @rest


END
GO