feat: Initial implementation of OIDC

This commit is contained in:
Ginger committed 2026-07-02 16:34:38 -04:00
1 parent 69163b5391
commit c0cb4afd8a
32 files changed
+1300 -63

No files matched your search

+15 -1
View File
@@ -1,5 +1,5 @@
use clap::Parser;
use conduwuit::Result;
use conduwuit::{Err, Result};
use crate::{
appservice::{self, AppserviceCommand},
@@ -8,6 +8,7 @@ use crate::{
debug::{self, DebugCommand},
federation::{self, FederationCommand},
media::{self, MediaCommand},
oidc::{self, OidcCommand},
query::{self, QueryCommand},
room::{self, RoomCommand},
server::{self, ServerCommand},
@@ -30,6 +31,9 @@ pub enum AdminCommand {
/// Commands for managing registration tokens
Token(TokenCommand),
#[command(subcommand)]
Oidc(OidcCommand),
#[command(subcommand)]
/// Commands for managing rooms
Rooms(RoomCommand),
@@ -80,6 +84,16 @@ pub(super) async fn process(command: AdminCommand, context: &Context<'_>) -> Res
context.bail_restricted()?;
token::process(command, context).await
},
| Oidc(command) => {
// OIDC commands are all restricted
context.bail_restricted()?;
if !context.services.oidc.enabled() {
return Err!("OIDC is not configured");
}
oidc::process(command, context).await
},
| Rooms(command) => room::process(command, context).await,
| Federation(command) => federation::process(command, context).await,
| Server(command) => server::process(command, context).await,
+1
View File
@@ -16,6 +16,7 @@ pub(crate) mod check;
pub(crate) mod debug;
pub(crate) mod federation;
pub(crate) mod media;
pub(crate) mod oidc;
pub(crate) mod query;
pub(crate) mod room;
pub(crate) mod server;
+17
View File
@@ -0,0 +1,17 @@
use conduwuit::Result;
use crate::utils::parse_active_local_user_id;
impl crate::Context<'_> {
pub(super) async fn oidc_link(&self, user_id: String, subject: String) -> Result {
let user_id = parse_active_local_user_id(self.services, &user_id).await?;
self.services.oidc.link_user(&user_id, &subject).await;
self.write_str("Account linked successfully").await?;
Ok(())
}
pub(super) async fn oidc_unlink(&self, _user_id: String) -> Result { todo!() }
}
+21
View File
@@ -0,0 +1,21 @@
mod commands;
use clap::Subcommand;
use conduwuit::Result;
use conduwuit_macros::admin_command_dispatch;
#[admin_command_dispatch]
#[derive(Debug, Subcommand)]
pub enum OidcCommand {
/// Link a user ID to the given subject claim.
#[clap(name = "link")]
OidcLink {
user_id: String,
subject: String,
},
#[clap(name = "unlink")]
OidcUnlink {
user_id: String,
},
}
+1 -1
View File
@@ -44,7 +44,7 @@ impl crate::Context<'_> {
.services
.config
.oauth
.compatibility_mode
.compatibility_mode()
.oauth_available()
{
self.write_str(&format!(
+1 -1
View File
@@ -59,7 +59,7 @@ impl crate::Context<'_> {
self.services
.users
.create_local_account(&user_id, HashedPassword::new(password)?, None)
.create_local_account(&user_id, Some(HashedPassword::new(password)?), None)
.await?;
self.write_str(&format!("Created user {user_id} with password `{password}`"))