From 6e20a3c51756c2e84290da6ec53b89a5fc58c0fc Mon Sep 17 00:00:00 2001 From: Vika Date: Wed, 28 Sep 2022 03:55:48 +0300 Subject: Use tokens from the auth backend to authenticate for Micropub --- kittybox-rs/src/micropub/util.rs | 52 +++++++++++++++------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) (limited to 'kittybox-rs/src/micropub/util.rs') diff --git a/kittybox-rs/src/micropub/util.rs b/kittybox-rs/src/micropub/util.rs index 7c6a0b1..5097878 100644 --- a/kittybox-rs/src/micropub/util.rs +++ b/kittybox-rs/src/micropub/util.rs @@ -1,5 +1,5 @@ use crate::database::Storage; -use crate::tokenauth::User; +use kittybox_indieauth::TokenData; use chrono::prelude::*; use core::iter::Iterator; use newbase60::num_to_sxg; @@ -33,7 +33,7 @@ fn reset_dt(post: &mut serde_json::Value) -> DateTime { chrono::DateTime::from(curtime) } -pub fn normalize_mf2(mut body: serde_json::Value, user: &User) -> (String, serde_json::Value) { +pub fn normalize_mf2(mut body: serde_json::Value, user: &TokenData) -> (String, serde_json::Value) { // Normalize the MF2 object here. let me = &user.me; let folder = get_folder_from_type(body["type"][0].as_str().unwrap()); @@ -190,7 +190,7 @@ pub(crate) async fn create_feed( storage: &impl Storage, uid: &str, channel: &str, - user: &User, + user: &TokenData, ) -> crate::database::Result<()> { let path = url::Url::parse(channel).unwrap().path().to_string(); @@ -220,6 +220,16 @@ mod tests { use super::*; use serde_json::json; + fn token_data() -> TokenData { + TokenData { + me: "https://fireburn.ru/".parse().unwrap(), + client_id: "https://quill.p3k.io/".parse().unwrap(), + scope: kittybox_indieauth::Scopes::new(vec![kittybox_indieauth::Scope::Create]), + exp: Some(u64::MAX), + iat: Some(0) + } + } + #[test] fn test_form_to_mf2() { assert_eq!( @@ -248,11 +258,7 @@ mod tests { let (uid, normalized) = normalize_mf2( mf2.clone(), - &User::new( - "https://fireburn.ru/", - "https://quill.p3k.io/", - "create update media", - ), + &token_data(), ); assert_eq!( normalized["properties"]["uid"][0], mf2["properties"]["uid"][0], @@ -277,11 +283,7 @@ mod tests { let (_, normalized) = normalize_mf2( mf2.clone(), - &User::new( - "https://fireburn.ru/", - "https://quill.p3k.io/", - "create update media", - ), + &token_data(), ); assert_eq!( @@ -303,11 +305,7 @@ mod tests { let (_, normalized) = normalize_mf2( mf2.clone(), - &User::new( - "https://fireburn.ru/", - "https://quill.p3k.io/", - "create update media", - ), + &token_data(), ); assert_eq!( @@ -327,11 +325,7 @@ mod tests { let (uid, post) = normalize_mf2( mf2, - &User::new( - "https://fireburn.ru/", - "https://quill.p3k.io/", - "create update media", - ), + &token_data(), ); assert_eq!( post["properties"]["published"] @@ -396,11 +390,7 @@ mod tests { let (_, post) = normalize_mf2( mf2, - &User::new( - "https://fireburn.ru/", - "https://quill.p3k.io/", - "create update media", - ), + &token_data(), ); assert!( post["properties"]["url"] @@ -429,11 +419,7 @@ mod tests { let (uid, post) = normalize_mf2( mf2, - &User::new( - "https://fireburn.ru/", - "https://quill.p3k.io/", - "create update media", - ), + &token_data(), ); assert_eq!( post["properties"]["uid"][0], uid, -- cgit 1.4.1