You've already forked AstralRinth
forked from didirus/AstralRinth
OAuth 2.0 Authorization Server [MOD-559] (#733)
* WIP end-of-day push * Authorize endpoint, accept endpoints, DB stuff for oauth clients, their redirects, and client authorizations * OAuth Client create route * Get user clients * Client delete * Edit oauth client * Include redirects in edit client route * Database stuff for tokens * Reorg oauth stuff out of auth/flows and into its own module * Impl OAuth get access token endpoint * Accept oauth access tokens as auth and update through AuthQueue * User OAuth authorization management routes * Forgot to actually add the routes lol * Bit o cleanup * Happy path test for OAuth and minor fixes for things it found * Add dummy data oauth client (and detect/handle dummy data version changes) * More tests * Another test * More tests and reject endpoint * Test oauth client and authorization management routes * cargo sqlx prepare * dead code warning * Auto clippy fixes * Uri refactoring * minor name improvement * Don't compile-time check the test sqlx queries * Trying to fix db concurrency problem to get tests to pass * Try fix from test PR * Fixes for updated sqlx * Prevent restricted scopes from being requested or issued * Get OAuth client(s) * Remove joined oauth client info from authorization returns * Add default conversion to OAuthError::error so we can use ? * Rework routes * Consolidate scopes into SESSION_ACCESS * Cargo sqlx prepare * Parse to OAuthClientId automatically through serde and actix * Cargo clippy * Remove validation requiring 1 redirect URI on oauth client creation * Use serde(flatten) on OAuthClientCreationResult
This commit is contained in:
@@ -152,6 +152,38 @@ generate_ids!(
|
||||
ImageId
|
||||
);
|
||||
|
||||
generate_ids!(
|
||||
pub generate_oauth_client_authorization_id,
|
||||
OAuthClientAuthorizationId,
|
||||
8,
|
||||
"SELECT EXISTS(SELECT 1 FROM oauth_client_authorizations WHERE id=$1)",
|
||||
OAuthClientAuthorizationId
|
||||
);
|
||||
|
||||
generate_ids!(
|
||||
pub generate_oauth_client_id,
|
||||
OAuthClientId,
|
||||
8,
|
||||
"SELECT EXISTS(SELECT 1 FROM oauth_clients WHERE id=$1)",
|
||||
OAuthClientId
|
||||
);
|
||||
|
||||
generate_ids!(
|
||||
pub generate_oauth_redirect_id,
|
||||
OAuthRedirectUriId,
|
||||
8,
|
||||
"SELECT EXISTS(SELECT 1 FROM oauth_client_redirect_uris WHERE id=$1)",
|
||||
OAuthRedirectUriId
|
||||
);
|
||||
|
||||
generate_ids!(
|
||||
pub generate_oauth_access_token_id,
|
||||
OAuthAccessTokenId,
|
||||
8,
|
||||
"SELECT EXISTS(SELECT 1 FROM oauth_access_tokens WHERE id=$1)",
|
||||
OAuthAccessTokenId
|
||||
);
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Type, Hash, Serialize, Deserialize)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct UserId(pub i64);
|
||||
@@ -238,6 +270,22 @@ pub struct SessionId(pub i64);
|
||||
#[sqlx(transparent)]
|
||||
pub struct ImageId(pub i64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize, Eq, PartialEq, Hash)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct OAuthClientId(pub i64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize, Eq, PartialEq, Hash)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct OAuthClientAuthorizationId(pub i64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize, Eq, PartialEq, Hash)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct OAuthRedirectUriId(pub i64);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Type, Serialize, Deserialize, Eq, PartialEq, Hash)]
|
||||
#[sqlx(transparent)]
|
||||
pub struct OAuthAccessTokenId(pub i64);
|
||||
|
||||
use crate::models::ids;
|
||||
|
||||
impl From<ids::ProjectId> for ProjectId {
|
||||
@@ -360,3 +408,23 @@ impl From<PatId> for ids::PatId {
|
||||
ids::PatId(id.0 as u64)
|
||||
}
|
||||
}
|
||||
impl From<OAuthClientId> for ids::OAuthClientId {
|
||||
fn from(id: OAuthClientId) -> Self {
|
||||
ids::OAuthClientId(id.0 as u64)
|
||||
}
|
||||
}
|
||||
impl From<ids::OAuthClientId> for OAuthClientId {
|
||||
fn from(id: ids::OAuthClientId) -> Self {
|
||||
Self(id.0 as i64)
|
||||
}
|
||||
}
|
||||
impl From<OAuthRedirectUriId> for ids::OAuthRedirectUriId {
|
||||
fn from(id: OAuthRedirectUriId) -> Self {
|
||||
ids::OAuthRedirectUriId(id.0 as u64)
|
||||
}
|
||||
}
|
||||
impl From<OAuthClientAuthorizationId> for ids::OAuthClientAuthorizationId {
|
||||
fn from(id: OAuthClientAuthorizationId) -> Self {
|
||||
ids::OAuthClientAuthorizationId(id.0 as u64)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user