0
0
IOT Protocolsdevops~10 mins

Token-based authentication (JWT) in IOT Protocols - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Token-based authentication (JWT)
Client sends login request
Server verifies credentials
Server creates JWT
Server sends JWT to client
Client stores JWT
Client sends JWT with requests
Server verifies JWT
Allow
This flow shows how a client logs in, receives a JWT token, and uses it for future requests that the server verifies.
Execution Sample
IOT Protocols
POST /login
Server: verify user
Server: create JWT token
Client: store token
Client: send token in header
Server: verify token
Server: allow or deny access
This sequence shows the main steps of JWT token creation and usage for authentication.
Process Table
StepActionInputOutputServer StateClient State
1Client sends login requestusername/passwordRequest receivedWaiting for verificationSent login request
2Server verifies credentialsusername/passwordCredentials validCredentials verifiedWaiting for token
3Server creates JWT tokenUser infoJWT token generatedJWT token readyWaiting for token
4Server sends JWT to clientJWT tokenToken sentToken sentReceived JWT token
5Client stores JWTJWT tokenToken storedToken sentToken stored
6Client sends request with JWTJWT token in headerRequest receivedVerifying tokenSent request with token
7Server verifies JWTJWT tokenToken validToken verifiedWaiting for response
8Server allows accessValid tokenAccess grantedRequest processedAccess granted
9Client receives responseAccess grantedResponse receivedIdleReceived response
10Client sends request with expired JWTExpired JWT tokenRequest receivedVerifying tokenSent request with expired token
11Server verifies JWTExpired JWT tokenToken invalidToken rejectedWaiting for response
12Server rejects accessInvalid tokenAccess deniedRequest deniedAccess denied
13Client receives rejectionAccess deniedResponse receivedIdleReceived rejection
💡 Execution stops after client receives access granted or access denied response.
Status Tracker
VariableStartAfter Step 4After Step 5After Step 6After Step 11Final
JWT TokenNoneGeneratedStored by clientSent with requestExpired/InvalidNone or expired
Server StateIdleToken readyToken sentVerifying tokenToken rejectedIdle
Client StateIdleWaiting for tokenToken storedSent request with tokenSent request with expired tokenIdle
Key Moments - 3 Insights
Why does the server reject a request even if the client sends a token?
Because the token might be expired or invalid as shown in steps 10-12 in the execution_table where the server verifies and rejects the token.
Does the client send username and password every time after login?
No, after login the client sends only the JWT token with requests as shown in steps 6 and 10, not the username/password.
What happens if the credentials are invalid at login?
The server rejects the login immediately as shown in the concept_flow branch 'No' after credential verification.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the server state after step 7?
AToken rejected
BToken verified
CIdle
DWaiting for verification
💡 Hint
Check the 'Server State' column at step 7 in the execution_table.
At which step does the client store the JWT token?
AStep 5
BStep 4
CStep 3
DStep 6
💡 Hint
Look for the action 'Client stores JWT' in the execution_table.
If the token expires, what will the server do according to the execution_table?
AAllow access
BIgnore the token
CReject access
DRequest new login
💡 Hint
See steps 11 and 12 where the server verifies and rejects an expired token.
Concept Snapshot
Token-based authentication uses JWT tokens to prove identity.
Client logs in with credentials once.
Server creates and sends JWT token.
Client stores and sends JWT with requests.
Server verifies JWT to allow or deny access.
Expired or invalid tokens cause rejection.
Full Transcript
Token-based authentication with JWT works by the client first sending login credentials to the server. The server checks these credentials and if valid, creates a JWT token. This token is sent back to the client, which stores it. For future requests, the client sends the JWT token instead of credentials. The server verifies the token on each request. If the token is valid, access is granted. If the token is expired or invalid, the server rejects the request. This process avoids sending username and password repeatedly and secures communication by using signed tokens.