Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions apps/auth-service/src/admin/service/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

use super::AdminService;
use crate::{
Applied, ClientDetails, ClientRegistry, ClientRegistryError, GracePeriod,
Applied, ClientRegistry, ClientRegistryError, GracePeriod,
admin::{AdminError, Operator, Reason},
};
use sourceorigin_common::{
ClientId,
admin::{ApprovedOrigin, Client},
admin::{ApprovedOrigin, Client, ClientDetail},
clients::{ClientField, ClientOwner, ClientRegistration, RelatedOrigin},
};
use sourceorigin_crypto::ClientSecret;
Expand All @@ -24,22 +24,22 @@ impl AdminService {
Ok(Self::views(self.database.oidc().list_clients().await?))
}

/// Describes one OIDC client as stored, with the lifetimes of its secrets.
pub(crate) async fn client_details(
/// Describes one OIDC client, deleted or not, with the lifetimes of its
/// secrets.
pub(crate) async fn client_detail(
&self,
operator: &Operator,
id: &ClientId,
) -> Result<ClientDetails, AdminError> {
) -> Result<ClientDetail, AdminError> {
operator.authorize_read(&self.database).await?;
let mut tx = self.database.begin().await?;
let client = tx
let detail = tx
.oidc()
.find_client(id.as_str())
.client_detail(id)
.await?
.ok_or(AdminError::ClientNotFound)?;
let secrets = tx.oidc().client_secrets(id).await?;
tx.commit().await?;
Ok(ClientDetails { client, secrets })
Ok(detail)
}

/// Runs `change` on the client registry in one transaction, attributed to
Expand Down
5 changes: 3 additions & 2 deletions apps/auth-service/src/admin/service/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use crate::{
use chrono::Utc;
use sourceorigin_common::{
AccountStatus, RecoveryId, UserId,
admin::Recovery,
events::{DomainEvent, EventContext, RecoveryRevocation, RevocationReason},
};
use sourceorigin_repository::{DatabaseTransaction, InsertRecovery, RecentRecovery};
use sourceorigin_repository::{DatabaseTransaction, InsertRecovery};
use url::Url;

impl AdminService {
Expand Down Expand Up @@ -157,7 +158,7 @@ impl AdminService {
&self,
operator: &Operator,
user_id: UserId,
) -> Result<Vec<RecentRecovery>, AdminError> {
) -> Result<Vec<Recovery>, AdminError> {
operator.authorize_read(&self.database).await?;
let mut tx = self.database.begin().await?;
let since = Utc::now() - PROBATION;
Expand Down
2 changes: 1 addition & 1 deletion apps/auth-service/src/admin/tests/reads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AdminOperation {
],
Self::ViewClient => vec![
service
.client_details(operator, &client.parse().expect("client ID"))
.client_detail(operator, &client.parse().expect("client ID"))
.await
.map(drop),
],
Expand Down
23 changes: 8 additions & 15 deletions apps/auth-service/src/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use super::{
CliError, Confirm, Console, Why,
output::{Cell, Joined, Single, Style, report},
};
use crate::{Applied, ClientDetails, GracePeriod, PUBLIC_BASE_URL, Reason};
use crate::{Applied, GracePeriod, PUBLIC_BASE_URL, Reason};
use clap::{Args, Subcommand};
use sourceorigin_common::{
ClientId, UserId,
admin::{ApprovedOrigin, Client},
admin::{ApprovedOrigin, Client, ClientDetail},
clients::{
AllowedScopes, BackchannelLogoutUri, ClientKind, ClientRegistration, ClientStatus,
DisplayName, PostLogoutUris, RedirectUri, RedirectUris, RelatedOrigin, ScopeName,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl ClientCommand {
}
Self::Apply(apply) => apply.run(console).await,
Self::List => out.emit(&service.list_clients(operator).await?[..]),
Self::Show { id } => out.emit(&service.client_details(operator, &id).await?),
Self::Show { id } => out.emit(&service.client_detail(operator, &id).await?),
Self::Update(update) => {
let (id, reason) = (update.id.clone(), update.why.reason.clone());
service
Expand Down Expand Up @@ -332,7 +332,7 @@ report!([Client], self, out, {
});

// A client's registration, then its secrets, never their values.
report!(ClientDetails, self, out, {
report!(ClientDetail, self, out, {
let client = &self.client;
out.title(format_args!("{} ({})", client.display_name, client.id))?;
let list = |items: &[String]| {
Expand All @@ -343,15 +343,8 @@ report!(ClientDetails, self, out, {
}
};
out.fields(&[
("Kind", Cell::new(client.kind)),
(
"Status",
ClientCommand::status(ClientStatus::of(
client.enabled,
client.suspended_at,
client.deleted_at,
)),
),
("Kind", Cell::new(self.kind)),
("Status", ClientCommand::status(client.status())),
("Owner", ClientCommand::owner(client.owner_id)),
("Redirect URIs", list(&client.redirect_uris)),
("Post-logout URIs", list(&client.post_logout_uris)),
Expand All @@ -366,8 +359,8 @@ report!(ClientDetails, self, out, {
"Back-channel logout",
client.backchannel_logout_uri.as_deref().into(),
),
("Created", client.created_at.into()),
("Updated", client.updated_at.into()),
("Created", self.created_at.into()),
("Updated", self.updated_at.into()),
("Last used", client.last_used_at.into()),
("Suspended", client.suspended_at.into()),
("Deleted", client.deleted_at.into()),
Expand Down
7 changes: 3 additions & 4 deletions apps/auth-service/src/cli/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use crate::{
use clap::Subcommand;
use sourceorigin_common::{
PasskeyId,
admin::{UserDetail, UserPage},
admin::{Recovery, RecoveryState, UserDetail, UserPage},
};
use sourceorigin_repository::{RecentRecovery, RecoveryState};

/// Accounts, in any status.
#[derive(Subcommand)]
Expand Down Expand Up @@ -263,7 +262,7 @@ impl UserCommand {
/// Shows the account's recent recoveries, if it has any, before another is
/// started or one is undone. On standard error, which leaves standard output
/// to the new link.
fn show_recent(console: &Console, recent: &[RecentRecovery]) -> Result<(), CliError> {
fn show_recent(console: &Console, recent: &[Recovery]) -> Result<(), CliError> {
if recent.is_empty() {
return Ok(());
}
Expand Down Expand Up @@ -307,7 +306,7 @@ impl UserCommand {

// An account's recent recoveries, newest first, with where each stands and the
// passkey it enrolled, shown before another is started or one is undone.
report!([RecentRecovery], self, out, {
report!([Recovery], self, out, {
out.table(
["RECOVERY", "STARTED", "STATE", "PASSKEY", "NAME", "ACTIVE"],
"",
Expand Down
16 changes: 1 addition & 15 deletions apps/auth-service/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
//! Nothing is cached: every request reads the registration it needs from the
//! database, so a change applies to the next request on every replica.

use serde::Serialize;
use sourceorigin_common::{
ClientId, UserId,
clients::{ClientField, ClientKind, ClientOwner, ClientRegistration, RelatedOrigin},
events::{DomainEvent, EventContext},
};
use sourceorigin_crypto::{ClientSecret, CryptoError};
use sourceorigin_repository::{
DatabaseError, DatabaseTransaction, StoredClientSecret, StoredOidcClient,
};
use sourceorigin_repository::{DatabaseError, DatabaseTransaction, StoredOidcClient};
use std::collections::BTreeSet;
use thiserror::Error;
use url::Url;
Expand Down Expand Up @@ -149,17 +146,6 @@ pub enum Applied {
Unchanged,
}

/// A client's registration and the lifetimes of its secrets, as `client show`
/// shows them.
#[derive(Serialize)]
pub struct ClientDetails {
/// The registration.
#[serde(flatten)]
pub client: StoredOidcClient,
/// Its secrets, oldest first; never their values.
pub secrets: Vec<StoredClientSecret>,
}

impl ClientRegistryError {
/// Reports `NotFound` as an unknown client `id`.
fn lookup(id: &ClientId) -> impl FnOnce(DatabaseError) -> Self {
Expand Down
10 changes: 6 additions & 4 deletions apps/auth-service/src/clients/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ use chrono::{DateTime, Utc};
use serde::Serialize;
use sourceorigin_common::{
ClientId,
admin::SecretLifetime,
clients::{
AllowedScopes, ClientField, ClientKind, ClientOwner, ClientRegistration, PostLogoutUris,
RedirectUri, RedirectUris, ScopeName,
},
protocol::oauth::Scope,
};
use sourceorigin_crypto::{ClientSecret, Secret};
use sourceorigin_repository::{DatabaseTransaction, StoredClientSecret, StoredOidcClient};
use sourceorigin_repository::{DatabaseTransaction, StoredOidcClient};
use std::error::Error;
use thiserror::Error;

Expand Down Expand Up @@ -398,12 +399,13 @@ impl AccountService {
pub(crate) async fn client_secrets(
&self,
owned: &OwnedClient,
) -> Result<Vec<StoredClientSecret>, AccountError> {
Ok(self
) -> Result<Vec<SecretLifetime>, AccountError> {
let secrets = self
.database
.oidc()
.client_secrets(&owned.client.id)
.await?)
.await?;
Ok(secrets.into_iter().map(Into::into).collect())
}

/// Runs `change` on the client registry in one transaction, attributed to
Expand Down
12 changes: 7 additions & 5 deletions apps/auth-service/src/deletion/export/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ use base64::Engine;
use chrono::{DateTime, Utc};
use serde::Serialize;
use serde_json::Value;
use sourceorigin_common::admin::{ApprovedOrigin, Consent, DashboardSession, KnownDevice};
use sourceorigin_common::admin::{
self, ApprovedOrigin, Consent, DashboardSession, KnownDevice, RecoveryState,
};
use sourceorigin_common::{
AccountStatus, ClientId, ErrorChain, Handle, PasskeyId, PictureId, RecoveryId, SessionId,
UserId, notifications::NotificationPreference,
};
use sourceorigin_repository::{
AnnouncementRecord, DatabaseError, DatabaseTransaction, EventFilter, IdentityRecord,
NotificationRecord, RecentRecovery, RecordedEvent, RecoveryState, SessionRecord, StoredGrant,
StoredHandle, StoredOidcClient, StoredPasskey, StoredPicture, StoredUser,
NotificationRecord, RecordedEvent, SessionRecord, StoredGrant, StoredHandle, StoredOidcClient,
StoredPasskey, StoredPicture, StoredUser,
};
use std::{collections::BTreeMap, time::Duration};
use tokio::sync::{
Expand Down Expand Up @@ -325,9 +327,9 @@ struct Recovery {
settles_at: Option<DateTime<Utc>>,
}

impl From<RecentRecovery> for Recovery {
impl From<admin::Recovery> for Recovery {
/// Keeps its dates, state and passkey.
fn from(recovery: RecentRecovery) -> Self {
fn from(recovery: admin::Recovery) -> Self {
let (state, settles_at) = match recovery.state {
RecoveryState::Open => ("open", None),
RecoveryState::Probation { settles_at } => ("probation", Some(settles_at)),
Expand Down
5 changes: 2 additions & 3 deletions apps/auth-service/src/deletion/export/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use chrono::TimeZone;
use serde_json::json;
use sourceorigin_common::{
AnnouncementId, AuthenticationMethod, EmailId, EventId, NotificationId, Provider, TokenId,
admin::DashboardSession,
admin::{DashboardSession, RecoveryPasskey},
clients::ClientKind,
events::{Browser, Platform, UserAgentFamily},
notifications::{EmailCategory, NotificationPreference},
};
use sourceorigin_repository::RecoveryPasskey;

/// Every section but the events serializes under its documented name and shape.
#[test]
Expand Down Expand Up @@ -152,7 +151,7 @@ fn serializes_every_section_in_its_documented_shape() {
approved_at: at,
}],
}],
recoveries: vec![Recovery::from(RecentRecovery {
recoveries: vec![Recovery::from(admin::Recovery {
id: recovery,
started_at: at,
expires_at: at,
Expand Down
3 changes: 1 addition & 2 deletions apps/auth-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ use audit::AuditApplication;
pub use audit::{AuditError, AuditKeys};
pub use cli::Cli;
pub use clients::{
Applied, ClientDetails, ClientRegistry, ClientRegistryError, MAX_DAILY_REGISTRATIONS,
MAX_OWNED_CLIENTS,
Applied, ClientRegistry, ClientRegistryError, MAX_DAILY_REGISTRATIONS, MAX_OWNED_CLIENTS,
};
pub use config::{
AuditConfig, AuthConfig, DashboardConfig, KeyEncryptionKeys, PUBLIC_BASE_URL, TokenDigestKeys,
Expand Down
3 changes: 2 additions & 1 deletion apps/auth-service/src/recovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ use chrono::{DateTime, Duration, Utc};
use serde::Serialize;
use sourceorigin_common::{
AccountStatus, Handle, PasskeyId, RecoveryId, UserId,
admin::RecoveryState,
config::Origin,
events::{DomainEvent, EventContext, RevocationReason},
protocol::api::Passkey,
};
use sourceorigin_crypto::Secret;
use sourceorigin_repository::{
DatabaseError, DatabaseTransaction, RecoveryState, SessionScope, StoredPasskey, StoredRecovery,
DatabaseError, DatabaseTransaction, SessionScope, StoredPasskey, StoredRecovery,
};
use url::Url;

Expand Down
Loading