From 2bc44af8cdaf2e71b870916de61387ac617d4227 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Sat, 17 Sep 2022 02:44:39 +0100 Subject: [PATCH] Add session::token() function for retrieving authentication token claims data --- lib/src/fnc/mod.rs | 1 + lib/src/fnc/session.rs | 5 +++++ lib/src/sql/function.rs | 1 + lib/src/sql/paths.rs | 2 ++ 4 files changed, 9 insertions(+) diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index 24b0f412..1075eeaa 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -134,6 +134,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec) -> Result args::check(ctx, name, args, Args::None, session::origin), "session::sc" => args::check(ctx, name, args, Args::None, session::sc), "session::sd" => args::check(ctx, name, args, Args::None, session::sd), + "session::token" => args::check(ctx, name, args, Args::None, session::token), // "string::concat" => args::check(ctx, name, args, Args::Any, string::concat), "string::endsWith" => args::check(ctx, name, args, Args::Two, string::ends_with), diff --git a/lib/src/fnc/session.rs b/lib/src/fnc/session.rs index e00da6db..bf74e67b 100644 --- a/lib/src/fnc/session.rs +++ b/lib/src/fnc/session.rs @@ -7,6 +7,7 @@ use crate::sql::paths::NS; use crate::sql::paths::OR; use crate::sql::paths::SC; use crate::sql::paths::SD; +use crate::sql::paths::TK; use crate::sql::value::Value; pub fn db(ctx: &Context, _: Vec) -> Result { @@ -36,3 +37,7 @@ pub fn sc(ctx: &Context, _: Vec) -> Result { pub fn sd(ctx: &Context, _: Vec) -> Result { ctx.value("session").unwrap_or(&Value::None).pick(SD.as_ref()).ok() } + +pub fn token(ctx: &Context, _: Vec) -> Result { + ctx.value("session").unwrap_or(&Value::None).pick(TK.as_ref()).ok() +} diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 54f45502..8779ef8a 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -394,6 +394,7 @@ fn function_session(i: &str) -> IResult<&str, &str> { tag("session::origin"), tag("session::sc"), tag("session::sd"), + tag("session::token"), ))(i) } diff --git a/lib/src/sql/paths.rs b/lib/src/sql/paths.rs index cc12cb32..6c44b75e 100644 --- a/lib/src/sql/paths.rs +++ b/lib/src/sql/paths.rs @@ -15,6 +15,8 @@ pub static SD: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("sd")]); pub static OR: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("or")]); +pub static TK: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("tk")]); + pub static IN: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("in")]); pub static OUT: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("out")]);