Short version:
This unix command (from this tutorial https://techdocs.akamai.com/iot-token-access-control/docs/generate-jwt-rsa-keys):
$ echo -n '{ "alg": "RS256", "typ": "JWT" }' | base64 | sed s/\+/-/ | sed -E s/=+$//
Prints this:
eyAiYWxnIjogIlJTMjU2IiwgICAidHlwIjogIkpXVCIgfQ
I am trying to move this to a bash
script:
#!/bin/bash
HEADER='{ "alg": "RS256", "typ": "JWT" }' | base64 | sed s/\+/-/ | sed -E s/=+$//
echo -n $HEADER
But the output is an error:
sed: -e expression #1, char 8: unknown option to `s'
Is there something that needs to be done to make SSH scripts that work in the shell work in bash?
(I'm completely new to bash scripts)
Long version:
I need to build a bash script that creates a JWT and then calls a Rest API from a Linux server. I have never built a bash script before, but the basic format was going to be:
#!/bin/bash
HEADER= ... encoded header
SIXTYSECONDS=date -d '1 min' +%s #<-- this also works in echo, but not in bash -- supposed to be current time+60 seconds as epoch time
PAYLOAD= ... encoded payload with $SIXTYSECONDS as expiration time
SIGNATURE=... encoded signature from keycerts
JWT= $HEADER.$PAYLOAD.$SIGNATURE
... Will tackle the code to call the API once I have the JWT code down
I am following this tutorial (https://techdocs.akamai.com/iot-token-access-control/docs/generate-jwt-rsa-keys) but it doesn't help me programmatically concatenate the various JWT pieces. Also I'm not sure how to integrate the 60 second expiration.