SQL Server
SQL Server
Get a JWS Unprotected Header
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.GetUnprotectedH, which copies the optional unprotected header of a signature into a JsonObject.
Background. The unprotected header is present only in JSON serialization forms that carry one. It is not covered by the signature.
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
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @jws int
EXEC @hr = sp_OACreate 'Chilkat.Jws', @jws OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Load the JWS compact serialization.
DECLARE @jwsCompact nvarchar(4000)
SELECT @jwsCompact = 'eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>'
EXEC sp_OAMethod @jws, 'LoadJws', @success OUT, @jwsCompact
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @jws, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jws
RETURN
END
-- Copy the optional unprotected header of signature 0 into a JsonObject. This applies to JWS in a
-- JSON serialization form that carries an unprotected header.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @jws, 'GetUnprotectedH', @success OUT, 0, @json
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @jws, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jws
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OASetProperty @json, 'EmitCompact', 0
EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jws
EXEC @hr = sp_OADestroy @json
END
GO