-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
203 additions
and
1,414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use rauthy_client::{ | ||
oidc_config::{ClaimMapping, JwtClaim, JwtClaimTyp, RauthyConfig}, | ||
provider::OidcProvider, | ||
}; | ||
use std::collections::HashSet; | ||
use zino_core::{ | ||
application::{Application, Plugin}, | ||
extension::TomlTableExt, | ||
}; | ||
|
||
/// The Rauthy client. | ||
#[derive(Debug, Clone, Copy)] | ||
struct RauthyClient; | ||
|
||
impl RauthyClient { | ||
/// Initializes the Rauthy client and setups the OIDC provider. | ||
pub fn init() -> Plugin { | ||
let loader = Box::pin(async { | ||
let Some(config) = Agent::config().get_table("rauthy") else { | ||
tracing::warn!("`rauthy` config should be specified"); | ||
return; | ||
}; | ||
let Some(client_id) = config.get_str("client-id") else { | ||
tracing::warn!("`rauthy.client-id` should be specified"); | ||
return; | ||
}; | ||
let Some(redirect_uri) = config.get_str("redirect-uri") else { | ||
tracing::warn!("`rauthy.redirect-uri` should be specified"); | ||
return; | ||
}; | ||
let Some(issuer_uri) = config.get_str("issuer-uri") else { | ||
tracing::warn!("`rauthy.issuer-uri` should be specified"); | ||
return; | ||
}; | ||
let audiences = if let Some(audiences) = config.get_str_array("audiences") { | ||
HashSet::from_iter(audiences.into_iter().map(|s| s.to_owned())) | ||
} else { | ||
HashSet::from([client_id.to_owned()]) | ||
}; | ||
let group_claim = if let Some(groups) = config.get_str_array("groups") { | ||
let claims = groups | ||
.into_iter() | ||
.map(|group| JwtClaim { | ||
typ: JwtClaimTyp::Groups, | ||
value: group.to_owned(), | ||
}) | ||
.collect(); | ||
ClaimMapping::Or(claims) | ||
} else { | ||
ClaimMapping::Any | ||
}; | ||
let scopes = config | ||
.get_str_array("scopes") | ||
.unwrap_or_else(|| vec!["openid"]); | ||
let rauthy_config = RauthyConfig { | ||
admin_claim: ClaimMapping::Or(vec![JwtClaim { | ||
typ: JwtClaimTyp::Roles, | ||
value: "admin".to_owned(), | ||
}]), | ||
user_claim: group_claim, | ||
allowed_audiences: audiences, | ||
client_id: client_id.to_owned(), | ||
email_verified: config.get_bool("email-verified").unwrap_or_default(), | ||
iss: issuer_uri.to_owned(), | ||
scope: scopes.into_iter().map(|s| s.to_owned()).collect(), | ||
secret: config.get_str("secret").map(|s| s.to_owned()), | ||
}; | ||
if let Err(err) = rauthy_client::init().await { | ||
tracing::error!("fail to initialize the Rauthy client: {err}"); | ||
} | ||
if let Err(err) = OidcProvider::setup_from_config(rauthy_config, redirect_uri).await { | ||
tracing::error!("fail to setup the OIDC provider: {err}"); | ||
} | ||
Ok(()) | ||
}); | ||
let mut plugin = Plugin::new("rauthy-client"); | ||
plugin.set_loader(loader); | ||
plugin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.