feat: improve OAuth provider configuration

This commit is contained in:
fawney19
2026-05-04 00:18:05 +08:00
parent cb5b8ee1ee
commit fb642f7d62
9 changed files with 934 additions and 122 deletions

View File

@@ -47,6 +47,11 @@ impl IdentityOAuthService {
) -> Result<Arc<dyn IdentityOAuthProvider>, OAuthError> {
self.registry
.get(provider_type)
.or_else(|| {
is_custom_oidc_provider_type(provider_type)
.then(|| self.registry.get("custom_oidc"))
.flatten()
})
.ok_or_else(|| OAuthError::UnsupportedProvider(provider_type.to_string()))
}
@@ -80,6 +85,14 @@ impl IdentityOAuthService {
}
}
fn is_custom_oidc_provider_type(provider_type: &str) -> bool {
let normalized = provider_type.trim().to_ascii_lowercase();
normalized == "custom_oidc"
|| normalized.starts_with("custom_oidc_")
|| normalized.starts_with("custom_")
|| normalized.starts_with("oidc_")
}
pub fn start_identity_oauth(
provider: &dyn IdentityOAuthProvider,
config: &IdentityOAuthProviderConfig,
@@ -132,6 +145,7 @@ mod tests {
assert!(service.provider("linuxdo").is_ok());
assert!(service.provider("custom_oidc").is_ok());
assert!(service.provider("custom_oidc_work").is_ok());
assert!(service.provider("missing").is_err());
}
}