Add session::token() function for retrieving authentication token claims data

This commit is contained in:
Tobie Morgan Hitchcock 2022-09-17 02:44:39 +01:00
parent 0d4d2359d4
commit 2bc44af8cd
4 changed files with 9 additions and 0 deletions

View file

@ -134,6 +134,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Va
"session::origin" => args::check(ctx, name, args, Args::None, session::origin), "session::origin" => args::check(ctx, name, args, Args::None, session::origin),
"session::sc" => args::check(ctx, name, args, Args::None, session::sc), "session::sc" => args::check(ctx, name, args, Args::None, session::sc),
"session::sd" => args::check(ctx, name, args, Args::None, session::sd), "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::concat" => args::check(ctx, name, args, Args::Any, string::concat),
"string::endsWith" => args::check(ctx, name, args, Args::Two, string::ends_with), "string::endsWith" => args::check(ctx, name, args, Args::Two, string::ends_with),

View file

@ -7,6 +7,7 @@ use crate::sql::paths::NS;
use crate::sql::paths::OR; use crate::sql::paths::OR;
use crate::sql::paths::SC; use crate::sql::paths::SC;
use crate::sql::paths::SD; use crate::sql::paths::SD;
use crate::sql::paths::TK;
use crate::sql::value::Value; use crate::sql::value::Value;
pub fn db(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> { pub fn db(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
@ -36,3 +37,7 @@ pub fn sc(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
pub fn sd(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> { pub fn sd(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
ctx.value("session").unwrap_or(&Value::None).pick(SD.as_ref()).ok() ctx.value("session").unwrap_or(&Value::None).pick(SD.as_ref()).ok()
} }
pub fn token(ctx: &Context, _: Vec<Value>) -> Result<Value, Error> {
ctx.value("session").unwrap_or(&Value::None).pick(TK.as_ref()).ok()
}

View file

@ -394,6 +394,7 @@ fn function_session(i: &str) -> IResult<&str, &str> {
tag("session::origin"), tag("session::origin"),
tag("session::sc"), tag("session::sc"),
tag("session::sd"), tag("session::sd"),
tag("session::token"),
))(i) ))(i)
} }

View file

@ -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 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 IN: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("in")]);
pub static OUT: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("out")]); pub static OUT: Lazy<[Part; 1]> = Lazy::new(|| [Part::from("out")]);