Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions central/src/auth/authentik/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub async fn generate_provider_values(
let mapping = FlowPropertymapping::new(conf).await?;

let secret = (!oidc_client_config.is_public).then_some(secret);
let name = format!("Provider for {}", client_id); // not consistent at the moment
let mut json = json!({
"name": client_id,
"client_id": client_id,
Expand All @@ -39,7 +40,7 @@ pub async fn generate_provider_values(
.iter()
.map(|url| {
let (matching_mode, url) = if is_regex_uri(url) {
("regex".to_owned(), url.to_owned())
("regex".to_owned(), convert_to_regex_url(url))
} else {
("strict".to_owned(), url.to_owned())
};
Expand Down Expand Up @@ -215,6 +216,20 @@ pub async fn check_set_federation_id(
}

fn is_regex_uri(uri: &str) -> bool {
let regex_chars = ['^', '$', '*'];
let regex_chars = ['*'];
uri.chars().any(|c| regex_chars.contains(&c))
}

fn convert_to_regex_url(uri: &str) -> String {
let mut result_uri = String::from("^");
for ch in uri.chars() {
match ch {
'.' => result_uri.push_str(r"\."),
'*' => result_uri.push_str(".*"),
'?' => result_uri.push_str("."),
_ => result_uri.push(ch),
}
}
result_uri.push_str("$");
result_uri
}
6 changes: 4 additions & 2 deletions central/src/auth/authentik/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ async fn test_create_client() -> anyhow::Result<()> {
"http://foo/bar".into(),
"http://verbis/test".into(),
"http://dkfz/verbis/test".into(),
"^http://dkfz.verbis/*".into(),
"http://dkfz.verbis/*".into(),
"https://e000-nb000.inet.dkfz-heidelberg.de/opal/*".into(),
],
};
let (SecretResult::Created(pw) | SecretResult::AlreadyExisted(pw)) =
Expand All @@ -77,7 +78,8 @@ async fn test_create_client() -> anyhow::Result<()> {
"http://foo/bar".into(),
"http://verbis/test".into(),
"http://dkfz/verbis/test".into(),
"^http://dkfz.verbis/*".into(),
"http://dkfz.verbis/*".into(),
"https://e000-nb000.inet.dkfz-heidelberg.de/opal/*".into(),
],
};
let (SecretResult::Created(pw) | SecretResult::AlreadyExisted(pw)) =
Expand Down