How to Get Authorization Data

First, you need to know How to Get Authorization Data. This is one of the most important things responsible for logging the user into the Blockchain. Authorization capabilities will be required for integrating the MetaPro Wallet and also for executing certain API queries or displaying user-specific information.

Ethers package installation

In order to authorize, it is required to generate the signature. It can be achieved by using an ethers package.

npm install --save-dev ethers

Then validate if, in the package.json file, dependency is added

"dependencies": {
    "ethers": "^6.7.0"
  }

Generate signature

To generate the signature, please implement the following function

async function generateSignature() {
  const walletAddress = '${yourWalletAddress}'
  const hash = '${generatedHash}'
  const message = 'Please sign to let us verify\nthat you are the owner of this address\n'+walletAddress+'\n\nRequest ID '+hash;
  const signature = await wallet.signMessage(message);
  return signature;
}

Take note that the message should remain unchanged, only walletAddress and hash should vary. Take a hash from the response of the following endpoint:

[GET] {{baseURL}}/users-service/auth/signature/hash
Headers:        'Content-Type': 'application/json',
                'Accept': '*/*',
                'X-Account-Wallet': {{your wallet address}}

Authorize

Use our /users-service/auth/login endpoint to generate an access token

[POST] {{baseURL}}/users-service/auth/login
Body:           {"signature": signature,
                "wallet": walletAddress}

Headers:        'Content-Type': 'application/json',
                'Accept': '*/*',
                'X-Account-Wallet': {{your wallet address}}
                'X-Account-Login-Hash': {{generated hash}}

In response, you will receive an access token that can be used in the other endpoints as an Authorization header.

Last updated