JSON web tokens Flashcards

Learn about JSON web tokens

1
Q

What is a JSON web token?

A

A JSON web token (JWT) is a small, secure way to share information between two parties, typically between a server and a users browser in a safe verifiable way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three parts of a JSON web token?

A

The three parts of a JSON web token are the header, the payload and the signature.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is contained in the header?

A

The header typically consists of two parts, the type of the token and the signing algorithm being used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What types of signing algorithms can be used?

A

The types of signing algorithms that can be used with JWTs are:
- HMAC
- RSA

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does HMAC work?

A

In HMAC the same secret key is used to sign and verify the token.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does RSA work?

A

In RSA the private key signs the token and the public key verifies it, private keys stay secret and public keys can be safely shared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the payload contain?

A

The payload contains the claims, claims are statements about the entity and additional data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the three types of claims?

A

The three types of claims are:
- Registered claims
- Public claims
- Private claims

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are registered claims?

A

Registered claims are a set of predefined claims which are not mandatory but recommended, to provide a set of useful, inoperable claims.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are public claims?

A

Public claims can be defined at will by those using JWTs, but to avoid collisions, they should be defined in the IANA JSON web token registery.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are private claims?

A

Private claims are custom claims created to share information between parties that agree on using them and are neither registered nor public claims.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is the signature created?

A

The signature is created by taking the encoded header, the encoded payload, a secret, the algorithm specified in the header and signing that.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the signature used for?

A

The signature is used to verify that the message wasn’t changed along the way and in the case of tokens signed with a private key, it can also verify that the sender of the JWT is who it says it is.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How is a JWT obtained to access APIs or resources?

A
  1. The application or client requests authorisation to the authorisation server.
  2. When authorisation is granted, the authorisation server returns an access token to the application.
  3. The application uses the access token to access the protected resource.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is JWT validation?

A

JWT validation refers to checking the structure, format and content of a JWT.
- Structure: Ensuring the token has the standard 3 parts separated by a dot.
- Format: Verifying that each part is correctly encoded and that the payload contains expected claims.
- Content: Checks that the claims within the token are correct, eg token isn’t expired or used before its time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is JWT verification?

A

JWT verification involves confirming the authenticity and integrity of the token.
- Signature verification: The primary part of JWT verification. The signature part of the JWT is checked against the header and the payload using the algorithm specified in the header with a secret key or a public key
- Issuer verification: Checking if the iss claim matches the expected issuer.
- Audience check: Check the aud claim matches the expected audience.

17
Q

Why do you validate a JWT?

A

You validate a JWT to make sure that the token makes sense, adheres to the expected standards and contains the right data.

18
Q

Why do you verify a JWT?

A

You verify a JWT to make sure the token hasn’t been altered and comes from a trusted source.