Sample code for 30+ languages & platforms
DataFlex

Get the JWS Payload into a StringBuilder

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetPayloadSb, which writes the payload of a loaded JWS as text into a StringBuilder, decoded using the given charset.

Background. In practice, validate the signature before trusting the payload.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoJws
    String sJwsCompact
    Variant vSbPayload
    Handle hoSbPayload
    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

    //  Get the JWS payload as text into a StringBuilder, decoded using the given charset.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPayload
    If (Not(IsComObjectCreated(hoSbPayload))) Begin
        Send CreateComObject of hoSbPayload
    End
    Get pvComObject of hoSbPayload to vSbPayload
    Get ComGetPayloadSb Of hoJws "utf-8" vSbPayload To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJws To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComGetAsString Of hoSbPayload To sTemp1
    Showln sTemp1


End_Procedure