From ce369403adc22bf9720433fb30054703eac8e6f6 Mon Sep 17 00:00:00 2001 From: mrw1593 Date: Mon, 5 Jun 2023 21:08:07 -0400 Subject: Update existing endpoints to have client scopes --- src/models/client.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/models/client.rs') diff --git a/src/models/client.rs b/src/models/client.rs index 44079de..90c5902 100644 --- a/src/models/client.rs +++ b/src/models/client.rs @@ -4,7 +4,6 @@ use actix_web::{http::StatusCode, ResponseError}; use exun::{Expect, RawUnexpected}; use raise::yeet; use serde::{Deserialize, Serialize}; -use sqlx::FromRow; use thiserror::Error; use url::Url; use uuid::Uuid; @@ -34,17 +33,11 @@ pub struct Client { ty: ClientType, alias: Box, secret: Option, + allowed_scopes: Box<[Box]>, + default_scopes: Option]>>, redirect_uris: Box<[Url]>, } -#[derive(Debug, Clone, Serialize, FromRow)] -#[serde(rename_all = "camelCase")] -pub struct ClientResponse { - pub id: Uuid, - pub alias: String, - pub client_type: ClientType, -} - impl PartialEq for Client { fn eq(&self, other: &Self) -> bool { self.id == other.id @@ -85,6 +78,8 @@ impl Client { alias: &str, ty: ClientType, secret: Option<&str>, + allowed_scopes: Box<[Box]>, + default_scopes: Option]>>, redirect_uris: &[Url], ) -> Result> { let secret = if let Some(secret) = secret { @@ -102,6 +97,8 @@ impl Client { alias: Box::from(alias), ty: ClientType::Public, secret, + allowed_scopes, + default_scopes, redirect_uris: redirect_uris.into_iter().cloned().collect(), }) } @@ -134,6 +131,14 @@ impl Client { self.secret.as_ref().map(|s| s.version()) } + pub fn allowed_scopes(&self) -> String { + self.allowed_scopes.join(" ") + } + + pub fn default_scopes(&self) -> Option { + self.default_scopes.clone().map(|s| s.join(" ")) + } + pub fn check_secret(&self, secret: &str) -> Option> { self.secret.as_ref().map(|s| s.check_password(secret)) } -- cgit v1.2.3