From 25ace1d8b2bb618b231e4de64adb7c7a06a80c97 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 23 Dec 2021 00:29:33 +0000 Subject: [PATCH] Add scripts --- scripts/get-token.sh | 7 +++++++ scripts/make-jwt.py | 20 ++++++++++++++++++++ scripts/refresh-token.sh | 7 +++++++ 3 files changed, 34 insertions(+) create mode 100755 scripts/get-token.sh create mode 100644 scripts/make-jwt.py create mode 100755 scripts/refresh-token.sh diff --git a/scripts/get-token.sh b/scripts/get-token.sh new file mode 100755 index 0000000..338d44a --- /dev/null +++ b/scripts/get-token.sh @@ -0,0 +1,7 @@ +curl https://sandbox-b2b.revolut.com/api/1.0/auth/token \ + -H "Content-Type: application/x-www-form-urlencoded"\ + --data "grant_type=authorization_code"\ + --data "code=oa_sand_[...]"\ + --data "client_id=XXXX_[...]"\ + --data "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer"\ + --data "client_assertion=long string [...]" diff --git a/scripts/make-jwt.py b/scripts/make-jwt.py new file mode 100644 index 0000000..fcc0af8 --- /dev/null +++ b/scripts/make-jwt.py @@ -0,0 +1,20 @@ +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.backends import default_backend +from json import load +import jwt + +PRIVATE_KEY = "pkcs8privatekey.pem" +PAYLOAD = "jwt" + +with open(PRIVATE_KEY, "rb") as f: + pem_bytes = f.read() + +with open(PAYLOAD, "rb") as f: + payload = load(f) + +print(pem_bytes) +print(payload) + +private_key = serialization.load_pem_private_key(pem_bytes, password=None, backend=default_backend()) +encoded = jwt.encode(payload, private_key, algorithm="RS256") +print(encoded) diff --git a/scripts/refresh-token.sh b/scripts/refresh-token.sh new file mode 100755 index 0000000..59a4f05 --- /dev/null +++ b/scripts/refresh-token.sh @@ -0,0 +1,7 @@ +curl https://sandbox-b2b.revolut.com/api/1.0/auth/token \ + -H "Content-Type: application/x-www-form-urlencoded"\ + --data "grant_type=refresh_token"\ + --data "refresh_token=oa_sand_[...]"\ + --data "client_id=XXXX_[...]"\ + --data "client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer"\ + --data "client_assertion=long string [...]"