PureBasic
PureBasic
Get the JWS Payload as a String
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.GetPayload, which returns the payload of a loaded JWS as text, decoded using the given charset.
Background. In practice, validate the signature before trusting the payload. Getting the payload retrieves the signed content.
Chilkat PureBasic Downloads
IncludeFile "CkJws.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
; Return the JWS payload as text, decoded using the given charset.
payload.s = CkJws::ckGetPayload(jws,"utf-8")
If CkJws::ckLastMethodSuccess(jws) = 0
Debug CkJws::ckLastErrorText(jws)
CkJws::ckDispose(jws)
ProcedureReturn
EndIf
Debug payload
CkJws::ckDispose(jws)
ProcedureReturn
EndProcedure