4EVERLAND Documents
HomeTwitterDiscordBlogs
  • Welcome to 4EVERLAND
  • Get started
    • Our Features
    • Quick Start Guide
      • Registration
      • Login options
        • MetaMask
        • OKX Wallet
        • Binance Web3 Wallet
        • Bitget Wallet
        • Phantom
        • Petra
        • Lilico
      • Usage Introduction
      • Dashboard stats
      • Account
        • Linking Your EVM Wallet to 4EVERLAND Account
        • Balance Alert
    • Billing and Pricing
      • What is LAND?
      • How to Obtain LAND?
      • Pricing Model
      • Q&As
    • Tokenomics
  • HOSITNG
    • What is Hosting?
      • IPFS Hosting
      • Arweave Hosting
        • Auto-Generation of Manifest
      • Internet Computer Hosting
      • Greenfield Hosting
    • Guides
      • Creating a Deployment
        • With Git
        • With IPFS Hash
        • With a Template
      • Site Deployment
      • Domain Management
        • DNS Setup Guide
        • ENS Setup Guide
        • SNS Setup Guide
          • The gateway: 4sol.xyz
        • SPACE ID Setup Guide
      • Project Setting
        • Git
      • Troubleshooting
      • Common Frameworks
    • Hosting Templates Centre
      • Templates Configuration File
    • Quick Addition
      • Implement Github 4EVER Pin
      • Github Deployment Button
    • Hosting API
      • Create Project API
      • Deploy Project API
      • Get Task Info API
      • IPNS Deployment Update API
    • Hosting CLI
  • Storage
    • Bucket
      • IPFS Bucket
        • Get Root CID - Snapshots
      • Arweave Bucket
        • Path Manifests
          • Instructions for Building Manifest
          • Auto-Generation of Manifest
        • Arweave Tags
        • Unleash Arweave
      • Guides
      • Bucket API - S3 Compatible
        • Coding Examples
          • AWS SDK - Go (Golang)
          • AWS SDK - Java
          • AWS SDK - JavaScript
          • AWS SDK - .NET
          • AWS SDK - PHP
          • AWS SDK - Python
          • AWS SDK - Ruby
        • S3 Tags Instructions
      • 4EVER Security Token Service API
      • Bucket Tools
      • Bucket Gateway Optimizer
    • 4EVER Pin
      • Guides
      • Pinning Services API
      • IPFS Migrator
    • Storage SDK
  • Gateways
    • IPFS Gateway
    • IC Gateway
    • Arweave Gateway
    • Dedicated Gateways
      • Gateway Access Controls
      • Video Streaming
      • IPFS Image Optimizer
    • IPNS Manager
      • IPNS Manager API
  • RPC
    • Guides
    • API Keys
    • JSON Web Token (JWT)
    • What's CUs/CUPS
    • WebSockets
    • Archive Node
    • Debug API
    • Chains RPC
      • BSC / opBNB
      • Ethereum
      • Optimism
      • Polygon
      • Taiko
  • AI
    • AI RPC
      • Quick Start
      • Models
      • API Keys
      • Requests & Responses
      • Parameters
    • 4EVER Chat
  • RaaS - Beta
    • What's Rollups?
    • 4EVER Rollup Stack
  • DePIN
    • 4EVER Network
    • Storage Nodes
  • More
    • Use Cases
      • Livepeer
      • Lens Protocol
      • Optopia.ai
      • Linear Finance
      • Snapshot
      • Tape
      • Taiko
      • Hey.xyz
      • SyncSwap
    • Community
    • Tutorials
    • Security
    • 4EVERLAND FAQ
Powered by GitBook
On this page
  • What is JSON Web Token?
  • How to use it?
  • Generate RSA-256 keys
  • Enable JWT in 4EVERLAND RPC
  • Generate the JWT
  • Header
  • Payload
  • Signature
  • JWT
  • Send request with JWT
  • What if the JWT is incorrect ?
  1. RPC

JSON Web Token (JWT)

Last updated 1 year ago

What is JSON Web Token?

JSON Web Token (JWT) is an open, industry standard method for representing claims securely between two parties. You can enable JWT in your API Key and send requests with JWT to ensure only authorized requests are available.

How to use it?

It's easy to enable JWT and send requests with JWT. You just need to follow the below instructions:

Generate RSA-256 keys

Generate your own RSA-256 public and private key with 2048 length. Below is the example using .

# generate rsa key
openssl genrsa -out jwtRSA256-private.pem 2048
openssl rsa -in jwtRSA256-private.pem -pubout -outform PEM -out jwtRSA256-public.pem

Enable JWT in 4EVERLAND RPC

  • Login > Dashboard > RPC > API Key > Setting

  • Enable the JTW and input the public key generated in previous step.

  • You will get the public key ID (uuid) after clicking "Add"

Copy ID (uuid) for JWT generation

Generate the JWT

Header

Field
Description
Example

alg

The signing algorithm being used

RS256

typ

The type of the token

JWT

You can use your terminal to encode the header.

# To encode a header
header=`echo -n '{"alg": "RS256","typ": "JWT","kid": "c6a5278e-ce1d-4f54-b7fa-f8d90f8b5756"}' | base64 | sed s/\+/-/ | sed -E s/=+$//`

Payload

Field
Required
Description
Example

uuid

TRUE

The ID generated in the previous step in the dashboard.

00000000-0000-0000-0000-000000000000

exp

FALSE

The expiry time. It should be no later than current time + 24 hours. Unix timestamp format.

1656907527

You can convert a human-readable timestamp to epoch by command below.

date -j -f "%Y-%m-%d %H:%M:%S" "2022-07-10 15:58:50" "+%s"

Make sure your expiration time is no longer than current time + 24 hours.You can encode your payload by command below.

#To encode a payload
payload=`echo -n '{"uuid": "00000000-0000-0000-0000-000000000000","exp": "1656907527"}' | base64 | sed s/\+/-/ | sed -E s/=+$//`

Signature

To create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that.

# To encode a signature
sig=`echo -n "$header.$payload" | openssl dgst -sha256 -binary -sign jwtRSA256-private.pem  | openssl enc -base64 | tr -d '\n=' | tr -- '+/' '-_'`

JWT

Your JWT is the combination of your encoded header.payload.signature.

# JWT = header.payload.signature
jwt=`echo $header.$payload.$sig`
echo $jwt

Verify your jwt by the debugger.

Send request with JWT

After generating the JWT, you would need to add the JWT as a part of your request header -H "Authorization: Bearer entry.

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $jwt" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' \
"https://bsc-mainnet.4everland.org/v1/<YOUR-API-KEY>"

What if the JWT is incorrect ?

If you have enabled the JWT but sending requests without JWT or with incorrect JWT, you will receive a http 401 error status code and also the response below.

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -40302,
        "message": "Json Web Token parsing failed."
    }
}

You should either disable the JWT setting or send requests with correct JWT.

Once you've enabled the JWT, it's required to add the JWT in all the requests header. Below is the example of generating JWT using You need HEADER, PAYLOAD, & SIGNATURE to generate a JWT.

https://jwt.io/
RFC 7519
OpenSSL