summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-25 17:20:46 +0300
committerVika <vika@fireburn.ru>2024-08-25 17:20:46 +0300
commit8d182c68cc2ed973514276e1470f6d68ac1544e8 (patch)
tree7c29d4ffe62c576c32da3cbf109e4bcc227a5931
parent266cf1e14f400292972534bb92802e5004d653ce (diff)
downloadbowl-8d182c68cc2ed973514276e1470f6d68ac1544e8.tar.zst
SignIn: Provide scopes granted in the output
TODO: make requested scopes parametrized
-rw-r--r--src/components/signin.rs16
1 files 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<glib::Uri>,
+    pub scope: kittybox_indieauth::Scopes,
 
     pub access_token: String,
     pub refresh_token: Option<String>,
@@ -123,6 +124,14 @@ fn callback_handler(sender: AsyncComponentSender<SignIn>) -> 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 <Self as AsyncComponent>::Widgets, sender: AsyncComponentSender<Self>, 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(