headless_lms_server/controllers/main_frontend/oauth/
authorized_clients.rs1use crate::prelude::*;
2use actix_web::{HttpResponse, web};
3use models::oauth_user_client_scopes::{AuthorizedClientInfo, OAuthUserClientScopes};
4use sqlx::PgPool;
5use uuid::Uuid;
6
7#[instrument(skip(pool, auth_user))]
8pub async fn get_authorized_clients(
9 pool: web::Data<PgPool>,
10 auth_user: AuthUser,
11) -> ControllerResult<HttpResponse> {
12 let mut conn = pool.acquire().await?;
13 let token = skip_authorize();
14
15 let rows: Vec<AuthorizedClientInfo> =
16 OAuthUserClientScopes::list_authorized_clients_for_user(&mut conn, auth_user.id).await?;
17
18 token.authorized_ok(HttpResponse::Ok().json(rows))
19}
20
21#[instrument(skip(pool, auth_user))]
22pub async fn delete_authorized_client(
23 pool: web::Data<PgPool>,
24 auth_user: AuthUser,
25 path: web::Path<Uuid>, ) -> ControllerResult<HttpResponse> {
27 let client_id = path.into_inner();
28 let mut conn = pool.acquire().await?;
29 let token = skip_authorize();
30
31 OAuthUserClientScopes::revoke_user_client_everything(&mut conn, auth_user.id, client_id)
32 .await?;
33
34 token.authorized_ok(HttpResponse::NoContent().finish())
35}
36
37pub fn _add_routes(cfg: &mut web::ServiceConfig) {
38 cfg.route("/authorized-clients", web::get().to(get_authorized_clients))
39 .route(
40 "/authorized-clients/{client_id}",
41 web::delete().to(delete_authorized_client),
42 );
43}