Skip to content

Add AuthkestraIntegration derive macro for simplified state integration#3

Open
onelrian wants to merge 2 commits intomarcjazz:mainfrom
onelrian:feature/simplify-state-integration
Open

Add AuthkestraIntegration derive macro for simplified state integration#3
onelrian wants to merge 2 commits intomarcjazz:mainfrom
onelrian:feature/simplify-state-integration

Conversation

@onelrian
Copy link

Summary

Introduces #[derive(AuthkestraIntegration)] macro to eliminate FromRef boilerplate when integrating Authkestra with custom Axum application state.

Problem

Integrating Authkestra with custom Axum AppState currently requires implementing 4 manual FromRef traits, creating approximately 30 lines of boilerplate code per integration.

Solution

Created authkestra-axum-macros crate providing a derive macro that automatically generates all required FromRef implementations.

Before

#[derive(Clone)]
struct AppState<S, T> {
    auth: Authkestra<S, T>,
    db_pool: Arc<PgPool>,
}

// 30+ lines of manual FromRef implementations
impl<S: Clone, T: Clone> FromRef<AppState<S, T>> for Authkestra<S, T> { ... }
impl<S, T> FromRef<AppState<S, T>> for Result<Arc<dyn SessionStore>, ...> { ... }
// ... 2 more implementations

After

use authkestra_axum::AuthkestraIntegration;

#[derive(Clone, AuthkestraIntegration)]
struct AppState<S, T> {
    #[authkestra]
    auth: Authkestra<S, T>,
    db_pool: Arc<PgPool>,
}

Changes

  • Created authkestra-axum-macros proc-macro crate
  • Implemented AuthkestraIntegration derive macro with compile-time validation
  • Added optional macros feature to authkestra-axum
  • Updated axum_credentials example demonstrating simplified integration
  • Added comprehensive documentation and migration guide

Impact

  • Reduces integration boilerplate by 90%
  • Backward compatible with existing AuthkestraState usage
  • Type-safe with compile-time validation
  • Optional feature flag, no forced dependency

Testing

  • All workspace tests pass
  • Examples compile and run correctly
  • Backward compatibility verified

Closes #2

@marcjazz marcjazz self-requested a review February 14, 2026 11:30
Copy link
Owner

@marcjazz marcjazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Rename the new crate from authkestra-axum-macros to authkestra-macros: This will help support other integrations macros in the features.
  • Add the renamed authkestra-macros with axum feature to the authkestra-axum cargo.toml. Make it available by default.
  • Rename AuthkestraIntegration to AuthkestraFromRef

Comment on lines 19 to 58
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is now irrelevant and should be deleted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AuthkestraState struct and its FromRef implementations serve a different purpose than the new AuthkestraFromRef macro:

  • AuthkestraState: Simple wrapper for users who only need Authkestra with no custom state fields
  • AuthkestraFromRef macro: For custom state structs with additional fields (e.g., db_pool, custom services)

They're complementary patterns, not replacements. Removing AuthkestraState would:

  • Break 3 existing examples (axum_oauth.rs, oidc_generic.rs, axum_spa_jwt.rs)
  • Force all users to use the macro even for simple cases
  • Be a breaking change

So , should I still delete it ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the macros crate to implement the AuthkestraState internal and existing example shall remain untouched.

@onelrian onelrian requested a review from marcjazz February 16, 2026 09:44
Comment on lines 19 to 58
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the macros crate to implement the AuthkestraState internal and existing example shall remain untouched.

@onelrian
Copy link
Author

onelrian commented Feb 17, 2026

Fixed the requested changes:

  • Refactored AuthkestraState to use the AuthkestraFromRef macro internally
  • Fixed all clippy warnings across the codebase (30+ uninlined_format_args warnings)

@onelrian onelrian force-pushed the feature/simplify-state-integration branch from c28ed75 to 67d25fa Compare February 17, 2026 14:59
@onelrian onelrian force-pushed the feature/simplify-state-integration branch from 67d25fa to 94dae9f Compare February 17, 2026 17:00
@onelrian onelrian requested a review from marcjazz February 17, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplify custom state integration by reducing FromRef boilerplate

2 participants