61
Views
7
Comments
Solved
[CryptoAPI] How can I validate a JWS in OutSystems?
cryptoapi
Service icon
Forge asset by João Barata
Application Type
Service

I've created a REST API and I need to validate a JSON Web Signature that is sent from the provider against a public key. 

I've attempted to use a number of Forge items to verify the signature against the public key however I always encounter an error.


Public Key Example 

"-----BEGIN CERTIFICATE-----\nMIIIMTCCBhmgAwIBAgIUayqvBGb8dzDDj78mIDrQor08Jg0wDQYJKoZIhvcNAQEL\nBQAwTTELMAkGA1UEBhMCQk0xGTAXBgNVBAoTEFF1b1ZhZGlzIExpbWl0ZWQxIzAh\nBgNVBAMTGlF1b1ZhZGlzIEdsb2JhbCBTU0wgSUNBIEczMB4XDTIyMTAyNTE2MTIy\nN1oXDTIzMTAyNTE2MDcwMFowgZUxCzAJBgNVBAYTAkdCMRswGQYDVQQIDBJFZGlu\nYnVyZ2gsIENpdHkgb2YxEjAQBgNVBAcMCUVkaW5idXJnaDEhMB8GA1UECgwYTGxv\neWRzIEJhbmtpbmcgR3JvdXAgUExDMTIwMAYDVQQDDClkY2FwaS1ub3RpZmljYXRp\nb25zLXRzdC5sbG95ZHNiYW5raW5nLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP\nADCCAQoCggEBAMVq2JlSXd7E7YLFvCYJtDsg0j7MzHRiOA8jsXXz6TeT5H/hRPk5\no5+2vQWLndfKzhdvDWUwr+8gxGmZXA4R47zjqX6A3QHk+dqGpY2ZP63+VIvCXGSY\nmCFUtqjoYpDjX72CD6ISA7d+e7wFo2XHZYQj8L3/2UAWeATJNaLRO3O7+AcKbVdz\nrP70Wc8lTsqLSB3TCsRveQVMnOF7p7UWH5wac95Nt5+GmE69R253gYL+NsAJ17QB\npd1dGlxHwjx2vc2VGOzcaprm77FH/T9wC4DsBBImUa8w/h3j8xj63q4HmIiAwglR\npEX8x0WhO0AaZmo1d5bPK71u7JJZX7XkYhsCAwEAAaOCA74wggO6MAkGA1UdEwQC\nMAAwHwYDVR0jBBgwFoAUsxKJtalLNbwVAP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JQ3KnaAKqMuytOiPaZ2MQOOqXhezmg1SyrwNeYLQDZpVRZK9tTII6pyNnB4OlcGaz5Ikjpya4EbnS2wdv3NUAoty77nJsul6WUmIZZ31QKn0FpTw3MA6HFlcXlF/JfoCoVdaUG1qEu9XuhGYLzlw3VbbRpA5q8HS7zDqg4n8z7fVzMkPhOokiivtalYJFY3n74174zbPThA1g/aLBDxdw/Jig== 


2020-10-08 19-51-35
João Barata
Staff
Solution

@Craig Merrick 

Looking at the example you provided, it's not a valid JWS.

A JWS is comprised of 3 sections separated by a period "." :

  • header
  • payload
  • signature

Example:
eyJhbGciOiJIUzI1NiJ9.ew0KICAic3ViIjogIjEyMzQ1Njc4OTAiLA0KICAibmFtZSI6ICJBbmlzaCBOYXRoIiwNCiAgImlhdCI6IDE1MTYyMzkwMjINCn0.9tFLrurxXWKBDh317ly24fP03We-uzSZtPf7Yqy_oSw


Unfortunately, the current implementation of the CryptoAPI does not support JWS signature validation. As far as I'm aware the JWT component also only works with JWT, not JWS.

Regards,


2021-08-31 11-16-27
Craig Merrick

This is an excerpt from the API Services Tech Guide. 

This is what us rcvd in the header and the wording below indicates that this is just a Signature (and maybe not a full JWT?). - 

'IM8oOo7/e83cWwD1S8nOG/RJYwisViQmVq/5eoq7pbdPULtw/hax2xuqS5vwWdc18TxQ1c0iIbdW8KWfrFWAERHHaYju+97SM8MCn3j1yEvGZaAruftkEEcLooAO9JQ3KnaAKqMuytOiPaZ2MQOOqXhezmg1SyrwNeYLQDZpVRZK9tTII6pyNnB4OlcGaz5Ikjpya4EbnS2wdv3NUAoty77nJsul6WUmIZZ31QKn0FpTw3MA6HFlcXlF/JfoCoVdaUG1qEu9XuhGYLzlw3VbbRpA5q8HS7zDqg4n8z7fVzMkPhOokiivtalYJFY3n74174zbPThA1g/aLBDxdw/Jig== '

Does anyone know how to validate just the signature if that's even what this is?


2025-01-15 08-35-04
Vignesh Sekar

Hi ,

Hope this component will work for you https://www.outsystems.com/forge/component-documentation/1853/jwt/0

I tried with your signature its working fine both encode and decode

https://joaoalmeida.outsystemscloud.com/JWT_Demo/GenerateToken_PEM.aspx?

Hope it will work

Thanks


2021-08-31 11-16-27
Craig Merrick

I’ve tried this component already. Would you mind sharing an example of how you set it up?


Would be a massive help

2025-01-15 08-35-04
Vignesh Sekar

Hi you can test with this URL ,

https://joaoalmeida.outsystemscloud.com/JWT_Demo/GenerateToken_PEM.aspx? 

you can add your custom claims it will generate PDF based on your signature it will encode it .

If its work you can download the sample app , can verify how its works



2021-08-31 11-16-27
Craig Merrick

I’m not really sure what this is supposed to be showing me. Sorry, I’m new to JWT’s and API’s.


The third party only appears to be sending the signature and that is what needs to be compared to the public key for verification.


The components I have been using tend to have input parameters for ‘Signature’ and ‘Public Key’ and I’ve just aligned these fields with the data that I’m rcving from the third party sending us the request as shown in my first screen shot. 

2020-10-08 19-51-35
João Barata
Staff
Solution

@Craig Merrick 

Looking at the example you provided, it's not a valid JWS.

A JWS is comprised of 3 sections separated by a period "." :

  • header
  • payload
  • signature

Example:
eyJhbGciOiJIUzI1NiJ9.ew0KICAic3ViIjogIjEyMzQ1Njc4OTAiLA0KICAibmFtZSI6ICJBbmlzaCBOYXRoIiwNCiAgImlhdCI6IDE1MTYyMzkwMjINCn0.9tFLrurxXWKBDh317ly24fP03We-uzSZtPf7Yqy_oSw


Unfortunately, the current implementation of the CryptoAPI does not support JWS signature validation. As far as I'm aware the JWT component also only works with JWT, not JWS.

Regards,


2021-08-31 11-16-27
Craig Merrick

This is an excerpt from the API Services Tech Guide. 

This is what us rcvd in the header and the wording below indicates that this is just a Signature (and maybe not a full JWT?). - 

'IM8oOo7/e83cWwD1S8nOG/RJYwisViQmVq/5eoq7pbdPULtw/hax2xuqS5vwWdc18TxQ1c0iIbdW8KWfrFWAERHHaYju+97SM8MCn3j1yEvGZaAruftkEEcLooAO9JQ3KnaAKqMuytOiPaZ2MQOOqXhezmg1SyrwNeYLQDZpVRZK9tTII6pyNnB4OlcGaz5Ikjpya4EbnS2wdv3NUAoty77nJsul6WUmIZZ31QKn0FpTw3MA6HFlcXlF/JfoCoVdaUG1qEu9XuhGYLzlw3VbbRpA5q8HS7zDqg4n8z7fVzMkPhOokiivtalYJFY3n74174zbPThA1g/aLBDxdw/Jig== '

Does anyone know how to validate just the signature if that's even what this is?


2021-10-09 07-57-44
Stefan Weber
 
MVP

Hi,

i have written an article here https://medium.com/itnext/protect-outsystems-rest-apis-using-openid-connect-87a2ac7575c1 that includes a description and a link to a sample application on how to validate and decode a Json Web Token using the JWT component mentioned above. Also this uses public keys from a Key server you can modify the sample to use a local public e.g. stored in site property.

Hope that helps,

Stefan

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.