I'm running a client with the following request and I was wondering if someone had an idea why this fails with error 400 please ?
code *************
header = {
"alg": "ES256",
"jwk": {
"crv": "P-256",
"kty": "EC",
"x": base64.urlsafe_b64encode(public_key.public_numbers().x.to_bytes(length=32, byteorder="big")).decode().rstrip("="),
"y": base64.urlsafe_b64encode(public_key.public_numbers().y.to_bytes(length=32, byteorder="big")).decode().rstrip("="),
},
"nonce": res_head.headers.get('Replay-Nonce'),
"url": res_get.json()["newAccount"]
}
payload = {
"termsOfServiceAgreed": "true",
"contact": [
"mailto:test@gmail.com"
]
}
protected_header = base64_helper(json.dumps(header,indent=4))
encoded_payload = base64_helper(json.dumps(payload,indent=4))
msg = f"{protected_header}.{encoded_payload}".encode('ascii')
signature = base64.urlsafe_b64encode(private_key.sign(msg,ec.ECDSA(hashes.SHA256()))).decode("ascii").rstrip("=").replace("-","+").replace("_","/")
final_payload = {
"protected": protected_header,
"payload": encoded_payload,
"signature": signature
}
url = res_get.json()["newAccount"]
headers = {'Content-type': 'application/jose+json'} #'Accept': 'text/plain'
res_post = requests.post(url,verify=False, data=final_payload, headers=headers)
def base64_helper(data):
if(isinstance(data,dict)):
data = json.dumps(data,indent=4)
return base64.urlsafe_b64encode(data.encode('UTF-8')).decode('ascii').rstrip("=")
result**************
{
"alg": "ES256",
"jwk": {
"crv": "P-256",
"kty": "EC",
"x": "5rFwxh1FppncQC1sHBK2jR1DZ2-ZXxFA1x5778zvhfU",
"y": "fGN0R0uCb6k9c3oCyqrkwVe7biYlWlT9ELPvHFyVSCM"
},
"nonce": "2ekqnNv4lxhO_EiwbZEVLA",
"url": "https://127.0.0.1:14000/sign-me-up"
}
{
"termsOfServiceAgreed": "true",
"contact": [
"mailto:test@gmail.com"
]
}
{
"protected": "ewogICAgImFsZyI6ICJFUzI1NiIsCiAgICAiandrIjogewogICAgICAgICJjcnYiOiAiUC0yNTYiLAogICAgICAgICJrdHkiOiAiRUMiLAogICAgICAgICJ4IjogIjVyRnd4aDFGcHBuY1FDMXNIQksyalIxRFoyLVpYeEZBMXg1Nzc4enZoZlUiLAogICAgICAgICJ5IjogImZHTjBSMHVDYjZrOWMzb0N5cXJrd1ZlN2JpWWxXbFQ5RUxQdkhGeVZTQ00iCiAgICB9LAogICAgIm5vbmNlIjogIjJla3FuTnY0bHhoT19FaXdiWkVWTEEiLAogICAgInVybCI6ICJodHRwczovLzEyNy4wLjAuMToxNDAwMC9zaWduLW1lLXVwIgp9",
"payload": "ewogICAgInRlcm1zT2ZTZXJ2aWNlQWdyZWVkIjogInRydWUiLAogICAgImNvbnRhY3QiOiBbCiAgICAgICAgIm1haWx0bzpyb3kuc2hvaGFtOTVAZ21haWwuY29tIgogICAgXQp9",
"signature": "MEUCIQDTW+67a+5Cw4GRhLamDzdTIWsEZfMcK97JBt/H+PgI7gIgYaarNYCZqpSn3NRF3edl1lpsLKZ+/bVg60voQOomg0c"
}
b'-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5rFwxh1FppncQC1sHBK2jR1DZ2+Z\nXxFA1x5778zvhfV8Y3RHS4JvqT1zegLKquTBV7tuJiVaVP0Qs+8cXJVIIw==\n-----END PUBLIC KEY-----\n'