JWT
Authenticating using JWT
What is JWT (JSON Web Token)?
JSON Web Token (JWT) is an open standard RFC 7519 that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.
A JWT consist og three strings separate by dots; the header, the payload and the signature
JWT example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Part Name | Value |
---|---|
Header | eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 |
Payload | eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ |
Signature | SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c |
Descriptions
- Header
The header typically consists of two parts: the type of the token, which is JWT, and the signing algorithm being used, such as HMAC SHA256 or RSA.
- Payload
The second part of the token is the payload, which contains the claims. Claims are statements about an entity (typically, the user) and additional data. There are three types of claims: registered, public, and private claims.
Registered claims: These are a set of predefined claims which are not mandatory but recommended, to provide a set of useful, interoperable claims. Some of them are: iss (issuer), exp (expiration time), sub (subject), aud (audience), and others.
Public claims: These can be defined at will by those using JWTs. But to avoid collisions they should be defined in the IANA JSON Web Token Registry or be defined as a URI that contains a collision resistant namespace.
Private claims: These are the custom claims created to share information between parties that agree on using them and are neither registered or public claims.
- 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.
Obtain a JWT with Opengate
To obtain an token JWT with Opengate platform, you should do login with the resource /provision/users/login in the next link JWT.
The JWT (Json Web Token) can be sent using as a request header.
POST /north/v80/provision/organizations/{organizationId}
Host: [api.opengate.es]
Authorization: Bearer YOUR-JWT-HERE
It is sent using the Authorization
HTTP header. An example of POST
request may look like this:
curl --request POST \
--verbose \
--header "Authorization: Bearer YOUR-JWT-HERE" \
--header "Content-type: application/json" \
--data-binary @device.json \
http://[your_opengate_address]/north/v80/provision/organizations/{organizationId}