SQL Server
SQL Server
SharePoint User Authentication (Windows classic mode authentication)
Demonstrates how to achieve Windows classic mode authentication with SharePoint. This method uses NTLM to provide the Windows credentials. The example shows how to send a GET request that returns a JSON representation of all of a site’s lists.Chilkat SQL Server Downloads
-- 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 requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
-- For example, imagine our SharePoint endpoint is https://xyzoffice.mycompany.com/
-- The SHAREPOINT_NTLM_DOMAIN would be "mycompany.com"
-- The SHAREPOINT_HTTPS_DOMAIN would be "xyzoffice.mycompany.com"
-- Also, the SHAREPOINT_USERNAME would be just the name, not a full email address.
-- for example, "chilkat" instead of "chilkat@mycompany.com"
DECLARE @http int
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Provide the credentials:
EXEC sp_OASetProperty @http, 'Login', 'SHAREPOINT_USERNAME'
EXEC sp_OASetProperty @http, 'Password', 'SHAREPOINT_PASSWORD'
EXEC sp_OASetProperty @http, 'LoginDomain', 'SHAREPOINT_NTLM_DOMAIN'
-- Tell Chilkat to use NTLM authentication.
EXEC sp_OASetProperty @http, 'NtlmAuth', 1
-- Indicate that we want a JSON reply
EXEC sp_OASetProperty @http, 'Accept', 'application/json;odata=verbose'
DECLARE @sbJson int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbJson OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://SHAREPOINT_HTTPS_DOMAIN/_api/web/lists', @sbJson
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbJson
RETURN
END
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'LoadSb', @success OUT, @sbJson
EXEC sp_OASetProperty @json, 'EmitCompact', 0
-- This will emit the full JSON representation of all of a site's list.
EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbJson
EXEC @hr = sp_OADestroy @json
END
GO