From 8d182c68cc2ed973514276e1470f6d68ac1544e8 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 25 Aug 2024 17:20:46 +0300 Subject: SignIn: Provide scopes granted in the output TODO: make requested scopes parametrized --- src/components/signin.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/signin.rs b/src/components/signin.rs index c595bde..08e850a 100644 --- a/src/components/signin.rs +++ b/src/components/signin.rs @@ -12,6 +12,7 @@ pub struct Output { pub me: glib::Uri, pub micropub: glib::Uri, pub userinfo: Option, + pub scope: kittybox_indieauth::Scopes, pub access_token: String, pub refresh_token: Option, @@ -123,6 +124,14 @@ fn callback_handler(sender: AsyncComponentSender) -> impl Fn(&soup::Serv } impl SignIn { + fn scopes() -> kittybox_indieauth::Scopes { + kittybox_indieauth::Scopes::new(vec![ + kittybox_indieauth::Scope::Profile, + kittybox_indieauth::Scope::Create, + kittybox_indieauth::Scope::Media + ]) + } + fn bail_out(&mut self, widgets: &mut ::Widgets, sender: AsyncComponentSender, err: Error) { widgets.toasts.add_toast(adw::Toast::builder() .title(err.to_string()) @@ -401,11 +410,7 @@ impl AsyncComponent for SignIn { code_challenge: kittybox_indieauth::PKCEChallenge::new( &self.code_verifier, kittybox_indieauth::PKCEMethod::S256 ), - scope: Some(kittybox_indieauth::Scopes::new(vec![ - kittybox_indieauth::Scope::Profile, - kittybox_indieauth::Scope::Create, - kittybox_indieauth::Scope::Media - ])), + scope: Some(Self::scopes()), me: Some(url.to_str().parse().unwrap()) }; @@ -496,6 +501,7 @@ impl AsyncComponent for SignIn { }) => { let _ = sender.output(Output { me: glib::Uri::parse(me.as_str(), glib::UriFlags::NONE).unwrap(), + scope: scope.unwrap_or_else(Self::scopes), micropub: micropub_uri, userinfo: metadata.userinfo_endpoint .map(|u| glib::Uri::parse( -- cgit 1.4.1