auth: Introduce User struct
The `UserClaims` structure is an implementation detail of how the JWT encoding process works. We do not need to expose all of the details of the JWT, such as issuer, audience, expiration, etc. to rest of the application. Route handlers should only be concerned with the information about the user, rather than the metadata about how the user was authenticated.
This commit is contained in:
@@ -78,7 +78,9 @@ async fn test_login() {
|
||||
assert_eq!(location, "/");
|
||||
let cookie = res.cookies().get("auth.token").unwrap();
|
||||
debug!("Cookie: {:?}", cookie);
|
||||
let claims = ctx.decode_jwt(cookie.value()).unwrap();
|
||||
debug!("Claims: {:?}", claims);
|
||||
assert!(!claims.sub.is_empty());
|
||||
|
||||
// Check to ensure the cookie contains a valid token
|
||||
let user = ctx.decode_jwt(cookie.value()).unwrap();
|
||||
debug!("User: {:?}", user);
|
||||
assert!(!user.id().is_empty());
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use rocket::local::blocking::Client;
|
||||
use rocket::serde::json::Value;
|
||||
use rocket::uri;
|
||||
|
||||
use seensite::auth::UserClaims;
|
||||
use seensite::auth::User;
|
||||
use seensite::page::*;
|
||||
use seensite::Context;
|
||||
|
||||
@@ -34,8 +34,8 @@ fn test_post_page() {
|
||||
super::setup();
|
||||
let client = Client::tracked(seensite::rocket()).unwrap();
|
||||
let ctx: &Context = client.rocket().state().unwrap();
|
||||
let claims = UserClaims::new("test1", 60);
|
||||
let token = ctx.make_jwt(&claims).unwrap();
|
||||
let user = User::new("test1");
|
||||
let token = ctx.make_jwt(&user, 60).unwrap();
|
||||
let data = Serializer::new(String::new())
|
||||
.append_pair("url", TEST_URL)
|
||||
.append_pair("data", TEST_HTML)
|
||||
|
||||
Reference in New Issue
Block a user