Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update axum to 0.7 #514

Closed
firstdorsal opened this issue Dec 17, 2023 · 2 comments · Fixed by #521
Closed

Update axum to 0.7 #514

firstdorsal opened this issue Dec 17, 2023 · 2 comments · Fixed by #521
Labels

Comments

@firstdorsal
Copy link

Hi, thank you for creating this crate!

Would it be possbile to update axum to 0.7?

I also wondered how one could pass other states to axum through app.with_state() like a mongodb client while using the User extractor.

@kjuulh
Copy link
Contributor

kjuulh commented Dec 29, 2023

Yep, I've got a fork with the update, so I will post it and we'll see when the maintainer can get it merged.

Also for the state, you can simply add it to a struct

    #[derive(Clone)]
    pub struct SharedApp(Arc<App>);

    impl Deref for SharedApp {
        type Target = Arc<App>;

        fn deref(&self) -> &Self::Target {
            &self.0
        }
    }

    pub struct App {
        pub is: IntrospectionState,
          // Add your own state here
    }
    
        impl App {
        pub fn to_shared(self) -> SharedApp {
            SharedApp(Arc::new(self))
        }
    }

    impl FromRef<SharedApp> for IntrospectionState {
        fn from_ref(input: &SharedApp) -> Self {
            input.is.clone()
        }
    }

// ... Se example 

   let is = IntrospectionStateBuilder::new("https://zitadel-libraries-l8boqa.zitadel.cloud")
        .with_basic_auth(
            // ... skipped for brevity
        )
        .build()
        .await
        .unwrap();
        
    let state = App {
        is
        // ... Add your other state
    }.to_shared()

    let app = Router::new()
        .route("/unauthed", get(unauthed))
        .route("/authed", get(authed))
        .with_state(state);

Something along those lines.

Btw this is the recommended pattern from upstream as well

buehler added a commit that referenced this issue Jan 23, 2024
buehler added a commit that referenced this issue Jan 23, 2024
* feat: update general dependencies and axum to v0.7

Closes #514.
Closes #519.
Closes #518.

* ignore marvin attack for now. there is no fix

* fix doctest
Copy link

🎉 This issue has been resolved in version 3.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants