chore: add #[non_exhaustive] to remaining public structs (#768)
* chore: add #[non_exhaustive] to remaining public structs * chore: add #[non_exhaustive] to remaining public types * chore: enable exhaustive_structs/enums clippy lints * test: add untagged ServerResult deserialization regression tests
This commit is contained in:
parent
ee1c63c53f
commit
6a3b32d3ab
1 changed files with 430 additions and 211 deletions
|
|
@ -60,6 +60,7 @@ const DEFAULT_EXCHANGE_URL: &str = "http://localhost";
|
|||
|
||||
/// Stored credentials for OAuth2 authorization
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct StoredCredentials {
|
||||
pub client_id: String,
|
||||
pub token_response: Option<OAuthTokenResponse>,
|
||||
|
|
@ -134,6 +135,7 @@ impl CredentialStore for InMemoryCredentialStore {
|
|||
|
||||
/// Stored authorization state for OAuth2 PKCE flow
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct StoredAuthorizationState {
|
||||
pub pkce_verifier: String,
|
||||
pub csrf_token: String,
|
||||
|
|
@ -172,6 +174,7 @@ impl std::fmt::Debug for StoredAuthorizationState {
|
|||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct VendorExtraTokenFields(pub HashMap<String, Value>);
|
||||
|
||||
impl ExtraTokenFields for VendorExtraTokenFields {}
|
||||
|
|
@ -257,6 +260,7 @@ impl StateStore for InMemoryStateStore {
|
|||
|
||||
/// HTTP client with OAuth 2.0 authorization
|
||||
#[derive(Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct AuthClient<C> {
|
||||
pub http_client: C,
|
||||
pub auth_manager: Arc<Mutex<AuthorizationManager>>,
|
||||
|
|
@ -350,6 +354,7 @@ pub enum AuthError {
|
|||
|
||||
/// oauth2 metadata
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct AuthorizationMetadata {
|
||||
pub authorization_endpoint: String,
|
||||
pub token_endpoint: String,
|
||||
|
|
@ -373,6 +378,7 @@ struct ResourceServerMetadata {
|
|||
|
||||
/// Parameters extracted from WWW-Authenticate header
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct WWWAuthenticateParams {
|
||||
pub resource_metadata_url: Option<Url>,
|
||||
pub scope: Option<String>,
|
||||
|
|
@ -394,6 +400,7 @@ impl WWWAuthenticateParams {
|
|||
|
||||
/// oauth2 client config
|
||||
#[derive(Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct OAuthClientConfig {
|
||||
pub client_id: String,
|
||||
pub client_secret: Option<String>,
|
||||
|
|
@ -401,6 +408,27 @@ pub struct OAuthClientConfig {
|
|||
pub redirect_uri: String,
|
||||
}
|
||||
|
||||
impl OAuthClientConfig {
|
||||
pub fn new(client_id: impl Into<String>, redirect_uri: impl Into<String>) -> Self {
|
||||
Self {
|
||||
client_id: client_id.into(),
|
||||
client_secret: None,
|
||||
scopes: Vec::new(),
|
||||
redirect_uri: redirect_uri.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_client_secret(mut self, secret: impl Into<String>) -> Self {
|
||||
self.client_secret = Some(secret.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_scopes(mut self, scopes: Vec<String>) -> Self {
|
||||
self.scopes = scopes;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
// add type aliases for oauth2 types
|
||||
type OAuthErrorResponse = oauth2::StandardErrorResponse<oauth2::basic::BasicErrorResponseType>;
|
||||
|
||||
|
|
@ -440,6 +468,7 @@ pub const EXTENSION_OAUTH_CLIENT_CREDENTIALS: &str =
|
|||
/// JWT signing algorithm for private_key_jwt authentication (SEP-1046)
|
||||
#[cfg(feature = "auth-client-credentials-jwt")]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[non_exhaustive]
|
||||
pub enum JwtSigningAlgorithm {
|
||||
RS256,
|
||||
RS384,
|
||||
|
|
@ -477,6 +506,7 @@ impl JwtSigningAlgorithm {
|
|||
/// - `ClientSecret`: credentials sent in the request body
|
||||
/// - `PrivateKeyJwt`: RFC 7523 signed JWT assertion (requires `auth-client-credentials-jwt` feature)
|
||||
#[derive(Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum ClientCredentialsConfig {
|
||||
/// Client secret authentication (credentials in request body)
|
||||
ClientSecret {
|
||||
|
|
@ -534,6 +564,7 @@ impl ClientCredentialsConfig {
|
|||
|
||||
/// Configuration for scope upgrade behavior
|
||||
#[derive(Debug, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub struct ScopeUpgradeConfig {
|
||||
/// Maximum number of scope upgrade attempts before giving up
|
||||
pub max_upgrade_attempts: u32,
|
||||
|
|
@ -579,6 +610,7 @@ pub(crate) struct ClientRegistrationRequest {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[non_exhaustive]
|
||||
pub struct ClientRegistrationResponse {
|
||||
pub client_id: String,
|
||||
pub client_secret: Option<String>,
|
||||
|
|
@ -589,6 +621,18 @@ pub struct ClientRegistrationResponse {
|
|||
pub additional_fields: HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
impl ClientRegistrationResponse {
|
||||
pub fn new(client_id: impl Into<String>, redirect_uris: Vec<String>) -> Self {
|
||||
Self {
|
||||
client_id: client_id.into(),
|
||||
client_secret: None,
|
||||
client_name: None,
|
||||
redirect_uris,
|
||||
additional_fields: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// SEP-991: URL-based Client IDs
|
||||
/// Validate that the client_id is a valid URL with https scheme and non-root pathname
|
||||
fn is_https_url(value: &str) -> bool {
|
||||
|
|
@ -2045,6 +2089,7 @@ impl AuthorizationManager {
|
|||
}
|
||||
|
||||
/// oauth2 authorization session, for guiding user to complete the authorization process
|
||||
#[non_exhaustive]
|
||||
pub struct AuthorizationSession {
|
||||
pub auth_manager: AuthorizationManager,
|
||||
pub auth_url: String,
|
||||
|
|
@ -2197,6 +2242,7 @@ impl AuthorizedHttpClient {
|
|||
/// OAuth state machine
|
||||
/// Use the OAuthState to manage the OAuth client is more recommend
|
||||
/// But also you can use the AuthorizationManager,AuthorizationSession,AuthorizedHttpClient directly
|
||||
#[non_exhaustive]
|
||||
pub enum OAuthState {
|
||||
/// the AuthorizationManager
|
||||
Unauthorized(AuthorizationManager),
|
||||
|
|
|
|||
Loading…
Reference in a new issue