this repo has no description
1use super::super::{AuthorizedClientData, OAuthError}; 2use super::helpers::{from_json, to_json}; 3use sqlx::PgPool; 4 5pub async fn upsert_authorized_client( 6 pool: &PgPool, 7 did: &str, 8 client_id: &str, 9 data: &AuthorizedClientData, 10) -> Result<(), OAuthError> { 11 let data_json = to_json(data)?; 12 sqlx::query!( 13 r#" 14 INSERT INTO oauth_authorized_client (did, client_id, created_at, updated_at, data) 15 VALUES ($1, $2, NOW(), NOW(), $3) 16 ON CONFLICT (did, client_id) DO UPDATE SET updated_at = NOW(), data = $3 17 "#, 18 did, 19 client_id, 20 data_json 21 ) 22 .execute(pool) 23 .await?; 24 Ok(()) 25} 26 27pub async fn get_authorized_client( 28 pool: &PgPool, 29 did: &str, 30 client_id: &str, 31) -> Result<Option<AuthorizedClientData>, OAuthError> { 32 let row = sqlx::query_scalar!( 33 r#" 34 SELECT data FROM oauth_authorized_client 35 WHERE did = $1 AND client_id = $2 36 "#, 37 did, 38 client_id 39 ) 40 .fetch_optional(pool) 41 .await?; 42 match row { 43 Some(v) => Ok(Some(from_json(v)?)), 44 None => Ok(None), 45 } 46}