Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate JWT token in sap abap

former_member606596
Discoverer

Hello guys,

How to generate JWT Token using SAP ABAP code, and self sign it?. Can you help me out here

10 REPLIES 10

UweFetzer_se38
Active Contributor

If JWT stands for JSON Web Token, than there is no standard way to create a token via ABAP (as far as I know). but you are invited to write an Open Source solution for that 😉

0 Kudos

Hi,

I went through these documents, but none of them explains how to generate JWT tokens using abap.

former_member324164
Participant

Hi, i dont't know if this is still current but there is a simple way to generate JWTs in ABAP.

Have a look at this blog: https://blogs.sap.com/2019/11/10/connect-from-as-abap-to-google-cloud-platform-app-engine-resource-s...

nadimiqbal
Discoverer
0 Kudos

I have private key, need to sign with RS256 algorithm. Do not have P12 file. Not sure how to proceed further.

Hi Nadim, I'm facing the same situation, I don't have the P12 file, just the private and public key.
Please, did you find any solution for this?
Thanks in advance.

former_member6134
Participant
0 Kudos

hi Nikhil - I have similar requirement to decode the JWT. Is it solved?

mnietor
Discoverer
0 Kudos

Hi fellipe.mendes I'm facing the same situation.

¿Please, did you find any solution for this?

Thanks in advance.

0 Kudos

Hello Miguel.

We implemented a Java script in PI to sign the document.

Regards,

Fellipe

Finally found a way forward using OPENSSL commands to generate the JWS called from ABAP function SXPG_COMMAND_EXECUTE_LONG.

  lv_command = 'ZGENJWT01'. "SM49/SM69 OS command
  param1 = 'X'.  "ignored
  long_parm = {base64hdr.base64payload}.

* call OPENSSL to generate JWS

  CALL FUNCTION 'SXPG_COMMAND_EXECUTE_LONG'
    EXPORTING
      commandname                   = lv_command
      additional_parameters         = param1
      targetsystem                  = lv_host
      long_params                   = long_parm
    TABLES
      exec_protocol                 = result
    EXCEPTIONS
      no_permission                 = 1
      command_not_found             = 2
      parameters_too_long           = 3
      security_risk                 = 4
      wrong_check_call_interface    = 5
      program_start_error           = 6
      program_termination_error     = 7
      x_error                       = 8
      parameter_expected            = 9
      too_many_parameters           = 10
      illegal_command               = 11
      wrong_asynchronous_parameters = 12
      cant_enq_tbtco_entry          = 13
      jobcount_generation_error     = 14
      OTHERS                        = 15.

---

SM49 : Customer ZGENJWT01 SunOS /usr/sap/DEV/DVEBMGS00/GENJWT01.sh

---

GENJWT01.sh : -->

#!/bin/sh
PARAM1=$1
PARAM2=$2
printf '%s' "$PARAM2" | \
openssl dgst -sha256 -sign /usr/sap/DEV/DVEBMGS00/priv_key.pem -binary | \
openssl base64 | \
tr -- '+/=' '-_ ' | tr -d '\n'

( ensure script is executable with chmod +x GENJWT01.sh)

( user requires Auth object S_LOG_COM to execute from SAP front end)

( private key placed in .pem file on server)

( When load balancing is being used ensure LV_HOST = '{mainappserver}' )

https://superuser.com/questions/1419155/generating-jwt-rs256-signature-with-openssl