Refactoring our JWT
Right now, the token we extract from the header of a request is just a string. In this section, we are going to encode and decode user credentials into a Json Web Token (JWT) so our user can login once, and then make multiple authenticated API calls to our backend with the token. Because the token has a unique ID associated with the user, we not only know that the user is authenticated, but what user is making the requests. To make these changes, we must carry out the following steps:
- Restructure our JWT for a unique ID
- Create a get key function for encoding
- Create a encode function to encode user credentials
- Create a decode function to extract user credentials
Before we carry out any of these steps however, we must add the following dependency to our glue
workspace:
# glue/Cargo.toml
jsonwebtoken = "9.3.0"
We then import the following:
// glue/src/token.rs
use crate::errors::{
NanoServiceError,
NanoServiceErrorStatus
};
use serde::{Serialize...