Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoJws
    String sJwsCompact
    Variant vJson
    Handle hoJson
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatJws)) To hoJws
    If (Not(IsComObjectCreated(hoJws))) Begin
        Send CreateComObject of hoJws
    End

    //  Load the JWS compact serialization.
    Move "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>" To sJwsCompact
    Get ComLoadJws Of hoJws sJwsCompact To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJws To sTemp1
        Showln sTemp1
        Procedure_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.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoJson to vJson
    Get ComGetUnprotectedH Of hoJws 0 vJson To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJws To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Set ComEmitCompact Of hoJson To False
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1


End_Procedure