Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJws
LOCAL cJwsCompact
LOCAL oJson

nSuccess := 0

oJws := CreateObject("Chilkat.Jws")

//  Load the JWS compact serialization.
cJwsCompact := "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
nSuccess := oJws:LoadJws(cJwsCompact)
IF (nSuccess == 0)
    ? oJws:LastErrorText
    oJws:destroy()
    RETURN
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.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJws:GetUnprotectedH(0, oJson)
IF (nSuccess == 0)
    ? oJws:LastErrorText
    oJws:destroy()
    oJson:destroy()
    RETURN
ENDIF

oJson:EmitCompact := 0
? oJson:Emit()

oJws:destroy()
oJson:destroy()