Axum+Leptos best practices suggestion for subdomain routing

I am planning to build a web backend system with subdomain routing. Subdomains are - "www.example.com", "a.example.com", "b.example.com" and "c.example.com". How to create separate functions (landing, pages render with leptos) for each subdomain and keep the auth across every subdomain?

There are multiple techniques to allow safe authorization across different domains, which include, but are not limited to

  • OAuth 2.0
  • CORS

none of which are specific to Rust. In order to facilitate us helping you, can you describe in more detail what kind of software you intend to write? From the given context I assume that you want to provide some kind of SSO service?

i want to build a jwt auth with my custom user model. but i want the auth system work across all subdomain, such as user logged in "a.example.com", will also be logged in "b.example.com", no need to log in again in "b.example.com". How do i achieve this?

What does your custom user model look like? In what way does it diverge from what standard IAM providers provide? Can you abstract your model into custom claims? If you can, I'd use OpenID Connect with an IAM server like keycloak or ory. Both support webhooks for custom claims AFAIK. You could then hook your custom user model server into the IAM provider and use the IAM server to verify tokens from your subdomains.

1 Like
pub enum IdType {
    Nid,
    Brn,
}

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct User {
    pub id: String,
    pub id_type: IdType,
    pub user_type: UserType,
    pub full_name: String,
    pub phone_number: Option<String>,
    pub blood_group: Option<String>,
    pub birth_date: Option<NaiveDate>,
    #[serde(skip)]
    pub password_hash: String,
    pub bmdc: Option<String>,
    pub created_at: Option<chrono::DateTime<chrono::Utc>>,
    pub updated_at: Option<chrono::DateTime<chrono::Utc>>,
}

This is my user model...how do i perform auth here without any third-party IAM? Can you guide me with some codes?