Sample code for 30+ languages & platforms
PureBasic

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

PureBasic
IncludeFile "CkJws.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    jws.i = CkJws::ckCreate()
    If jws.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Load the JWS compact serialization.
    jwsCompact.s = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
    success = CkJws::ckLoadJws(jws,jwsCompact)
    If success = 0
        Debug CkJws::ckLastErrorText(jws)
        CkJws::ckDispose(jws)
        ProcedureReturn
    EndIf

    ;  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.
    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkJws::ckGetUnprotectedH(jws,0,json)
    If success = 0
        Debug CkJws::ckLastErrorText(jws)
        CkJws::ckDispose(jws)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    CkJsonObject::setCkEmitCompact(json, 0)
    Debug CkJsonObject::ckEmit(json)


    CkJws::ckDispose(jws)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure