Skip to content

Commit

Permalink
feat: Add project_roles and metadata to all IntrospectedUser (#571)
Browse files Browse the repository at this point in the history
Adds `project_roles` and `metadata` fields to all three
`IntrospectedUser` structs
  • Loading branch information
FrTerstappen authored Sep 6, 2024
1 parent 4ebde7b commit d3d3997
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/actix/introspection/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use actix_web::error::{ErrorInternalServerError, ErrorUnauthorized};
use actix_web::{Error, FromRequest, HttpRequest};
use custom_error::custom_error;
use openidconnect::TokenIntrospectionResponse;
use std::collections::HashMap;

use crate::actix::introspection::config::IntrospectionConfig;
use crate::oidc::introspection::{introspect, IntrospectionError, ZitadelIntrospectionResponse};
Expand Down Expand Up @@ -37,6 +38,8 @@ pub struct IntrospectedUser {
pub email: Option<String>,
pub email_verified: Option<bool>,
pub locale: Option<String>,
pub project_roles: Option<HashMap<String, HashMap<String, String>>>,
pub metadata: Option<HashMap<String, String>>,
}

impl From<ZitadelIntrospectionResponse> for IntrospectedUser {
Expand All @@ -51,6 +54,8 @@ impl From<ZitadelIntrospectionResponse> for IntrospectedUser {
email: response.extra_fields().email.clone(),
email_verified: response.extra_fields().email_verified,
locale: response.extra_fields().locale.clone(),
project_roles: response.extra_fields().project_roles.clone(),
metadata: response.extra_fields().metadata.clone(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/axum/introspection/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub struct IntrospectedUser {
pub email_verified: Option<bool>,
pub locale: Option<String>,
pub project_roles: Option<HashMap<String, HashMap<String, String>>>,
pub metadata: Option<HashMap<String, String>>,
}

#[async_trait]
Expand Down Expand Up @@ -193,6 +194,7 @@ impl From<ZitadelIntrospectionResponse> for IntrospectedUser {
email_verified: response.extra_fields().email_verified,
locale: response.extra_fields().locale.clone(),
project_roles: response.extra_fields().project_roles.clone(),
metadata: response.extra_fields().metadata.clone(),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/rocket/introspection/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use openidconnect::TokenIntrospectionResponse;
use rocket::http::Status;
use rocket::request::{FromRequest, Outcome};
use rocket::{async_trait, Request};
use std::collections::HashMap;

use crate::oidc::introspection::{introspect, IntrospectionError, ZitadelIntrospectionResponse};
use crate::rocket::introspection::IntrospectionConfig;
Expand Down Expand Up @@ -35,6 +36,8 @@ pub struct IntrospectedUser {
pub email: Option<String>,
pub email_verified: Option<bool>,
pub locale: Option<String>,
pub project_roles: Option<HashMap<String, HashMap<String, String>>>,
pub metadata: Option<HashMap<String, String>>,
}

impl From<ZitadelIntrospectionResponse> for IntrospectedUser {
Expand All @@ -49,6 +52,8 @@ impl From<ZitadelIntrospectionResponse> for IntrospectedUser {
email: response.extra_fields().email.clone(),
email_verified: response.extra_fields().email_verified,
locale: response.extra_fields().locale.clone(),
project_roles: response.extra_fields().project_roles.clone(),
metadata: response.extra_fields().metadata.clone(),
}
}
}
Expand Down

0 comments on commit d3d3997

Please sign in to comment.