Receiving bad request response when trying to register using ion method

469 Views Asked by At

I tried to follow the steps that are defined in the link "https://didproject.azurewebsites.net/docs/registration.html" as is with out any changes to create a sample and complete DID registration to understand the process.

I downloaded the sample and generated necessary public/private keys and completed till the step to generate the payload using the command node makejws which is successful.

After this when i am trying to use the curl command "curl" by replacing the entire text after -- data with the response of payload from the command node makejws . I am receiving an error as Bad request and not sure what is wrong in the command

Curl command that i used is as below

curl -v -H "Content-Type: application/json" --data "{'header':{'alg':'ES256K','kid':'#key-1','operation':'create','proofOfWork':'{}'},'payload':'eyJAY29udGV4dCI6Imh0dHBzOi8vdzNpZC5vcmcvZGlkL3YxIiwicHVibGljS2V5IjpbeyJpZCI6IiNrZXktMSIsInR5cGUiOiJTZWNwMjU2azFWZXJpZmljYXRpb25LZXkyMDE4IiwicHVibGljS2V5SndrIjp7Imt0eSI6IkVDIiwia2lkIjoiI2tleS0xIiwiY3J2IjoiUC0yNTZLIiwieCI6IjVvTEg2ZUVfdWZjZ2VlZ1U2NFo1ZFlEdUxjWWJSV3hsYk1xdFVnbmVRRWMiLCJ5IjoieXZEcXhwaXlCYlZsUlF1cXhHUm54U3hNbDJwSFFTem5Ub0U1dTZKMzBkSSIsInVzZSI6InZlcmlmeSIsImRlZmF1bHRFbmNyeXB0aW9uQWxnb3JpdGhtIjoibm9uZSIsImRlZmF1bHRTaWduQWxnb3JpdGhtIjoiRVMyNTZLIn19XSwic2VydmljZSI6W3siaWQiOiJJZGVudGl0eUh1YiIsInR5cGUiOiJJZGVudGl0eUh1YiIsInNlcnZpY2VFbmRwb2ludCI6eyJAY29udGV4dCI6InNjaGVtYS5pZGVudGl0eS5mb3VuZGF0aW9uL2h1YiIsIkB0eXBlIjoiVXNlclNlcnZpY2VFbmRwb2ludCIsImluc3RhbmNlIjpbImRpZDp0ZXN0Omh1Yi5pZCJdfX1dfQ','signature':'MEYCIQCb7qxCFyIcYumN-HbYqleTc5YldwRnNrhDzlB1DEubQQIhAMkAdsa-BxwV5EghhLljbr84MjkmUYI5narCTnapBcxs'}" -X POST https://beta.ion.microsoft.com/api/1.0/register

Excepted below response

"HTTP/1.1 200 OK
Content-Length: 395
Content-Type: application/json"

But receiving

HTTP/1.1 400 Bad Request
request-id: "test"
content-type: text/plain; charset=
1

There are 1 best solutions below

0
On BEST ANSWER

The curl command you are using is not sending JSON. JSON requires "double quotes" around keys and values.

Change all of your ' to ", and wrap it in ' like so:

--data '{"header":{"alg":"ES256K",...}' -X POST https://beta.ion.microsoft.com/api/1.0/register

When I did that, I received a HTTP/1.1 200 OK

(Also, the -X POST is not necessary - POST is already implied by other parts of the curl command.)

UPDATE 1 Based on your 6/30 comment, I have updated this answer with an unabbreviated form of what I mean, with the curl output showing that it works:

full curl command

curl -v -H "Content-Type: application/json" --data '{"header":{"alg":"ES256K","kid":"#key-1","operation":"create","proofOfWork":"{}"},"payload":"eyJAY29udGV4dCI6Imh0dHBzOi8vdzNpZC5vcmcvZGlkL3YxIiwicHVibGljS2V5IjpbeyJpZCI6IiNrZXktMSIsInR5cGUiOiJTZWNwMjU2azFWZXJpZmljYXRpb25LZXkyMDE4IiwicHVibGljS2V5SndrIjp7Imt0eSI6IkVDIiwia2lkIjoiI2tleS0xIiwiY3J2IjoiUC0yNTZLIiwieCI6IjVvTEg2ZUVfdWZjZ2VlZ1U2NFo1ZFlEdUxjWWJSV3hsYk1xdFVnbmVRRWMiLCJ5IjoieXZEcXhwaXlCYlZsUlF1cXhHUm54U3hNbDJwSFFTem5Ub0U1dTZKMzBkSSIsInVzZSI6InZlcmlmeSIsImRlZmF1bHRFbmNyeXB0aW9uQWxnb3JpdGhtIjoibm9uZSIsImRlZmF1bHRTaWduQWxnb3JpdGhtIjoiRVMyNTZLIn19XSwic2VydmljZSI6W3siaWQiOiJJZGVudGl0eUh1YiIsInR5cGUiOiJJZGVudGl0eUh1YiIsInNlcnZpY2VFbmRwb2ludCI6eyJAY29udGV4dCI6InNjaGVtYS5pZGVudGl0eS5mb3VuZGF0aW9uL2h1YiIsIkB0eXBlIjoiVXNlclNlcnZpY2VFbmRwb2ludCIsImluc3RhbmNlIjpbImRpZDp0ZXN0Omh1Yi5pZCJdfX1dfQ","signature":"MEYCIQCb7qxCFyIcYumN-HbYqleTc5YldwRnNrhDzlB1DEubQQIhAMkAdsa-BxwV5EghhLljbr84MjkmUYI5narCTnapBcxs"}' -X POST https://beta.ion.microsoft.com/api/1.0/register

curl transmission

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 52.183.24.15...
* TCP_NODELAY set
* Connected to beta.ion.microsoft.com (52.183.24.15) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=beta.ion.microsoft.com
*  start date: Apr 25 21:41:42 2019 GMT
*  expire date: Apr 25 21:41:42 2020 GMT
*  subjectAltName: host "beta.ion.microsoft.com" matched cert's "beta.ion.microsoft.com"
*  issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT TLS CA 2
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7f9e0e00c600)
> POST /api/1.0/register HTTP/2
> Host: beta.ion.microsoft.com
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 908
> 

curl response

* We are completely uploaded and fine
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
< request-id: 3545fb10-998e-4871-a28c-bc92e7d82648
< vary: Origin, Accept-Encoding
< x-dns-prefetch-control: off
< x-frame-options: SAMEORIGIN
< strict-transport-security: max-age=31536000; includeSubDomains
< x-download-options: noopen
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< content-type: application/json; charset=utf-8
< content-length: 828
< server-timing: total;dur=171.0000
< date: Mon, 01 Jul 2019 03:56:45 GMT
< x-envoy-upstream-service-time: 173
< server: envoy
< 
{
  "@context": "https://w3id.org/did/v1",
  "publicKey": [
    {
      "id": "#key-1",
      "type": "Secp256k1VerificationKey2018",
      "publicKeyJwk": {
        "kty": "EC",
        "kid": "#key-1",
        "crv": "P-256K",
        "x": "5oLH6eE_ufcgeegU64Z5dYDuLcYbRWxlbMqtUgneQEc",
        "y": "yvDqxpiyBbVlRQuqxGRnxSxMl2pHQSznToE5u6J30dI",
        "use": "verify",
        "defaultEncryptionAlgorithm": "none",
        "defaultSignAlgorithm": "ES256K"
      }
    }
  ],
  "service": [
    {
      "id": "IdentityHub",
      "type": "IdentityHub",
      "serviceEndpoint": {
        "@context": "schema.identity.foundation/hub",
        "@type": "UserServiceEndpoint",
        "instance": [
          "did:test:hub.id"
        ]
      }
    }
  ],
  "id": "did:ion:test:EiBXX4kWVIMsvP-evbWvr37Vy2UY32ALpNu9nssBhj_Pdg"
* Connection #0 to host beta.ion.microsoft.com left intact