Add shared OAuth flows

This commit is contained in:
fawney19
2026-04-28 15:46:21 +08:00
parent 712b484bc8
commit 70f747d406
56 changed files with 5927 additions and 977 deletions

View File

@@ -0,0 +1,38 @@
use thiserror::Error;
#[derive(Debug, Error)]
pub enum OAuthError {
#[error("unsupported oauth provider: {0}")]
UnsupportedProvider(String),
#[error("invalid oauth request: {0}")]
InvalidRequest(String),
#[error("oauth state is invalid or expired")]
InvalidState,
#[error("oauth provider returned HTTP {status_code}: {body_excerpt}")]
HttpStatus {
status_code: u16,
body_excerpt: String,
},
#[error("oauth provider returned invalid response: {0}")]
InvalidResponse(String),
#[error("oauth transport failed: {0}")]
Transport(String),
#[error("oauth storage failed: {0}")]
Storage(String),
#[error("oauth encryption failed")]
EncryptionUnavailable,
}
impl OAuthError {
pub fn invalid_request(detail: impl Into<String>) -> Self {
Self::InvalidRequest(detail.into())
}
pub fn invalid_response(detail: impl Into<String>) -> Self {
Self::InvalidResponse(detail.into())
}
pub fn transport(detail: impl Into<String>) -> Self {
Self::Transport(detail.into())
}
}