ezidam, openid: refactor check app in method, verifying and send POST as well
This commit is contained in:
parent
8ae0c59a25
commit
eb93cbd7ec
7 changed files with 76 additions and 22 deletions
|
|
@ -12,3 +12,4 @@ url = { workspace = true }
|
|||
id = { path = "../id" }
|
||||
database = { path = "../database" }
|
||||
hash = { path = "../hash" }
|
||||
openid = { path = "../openid" }
|
||||
|
|
@ -42,11 +42,11 @@ impl App {
|
|||
}
|
||||
|
||||
/// App needs to be not archived
|
||||
pub async fn get_one(
|
||||
pub(crate) async fn get_one(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
id: &str,
|
||||
redirect: &str,
|
||||
) -> Result<Option<Self>, Error> {
|
||||
) -> Result<Option<Self>, database::Error> {
|
||||
Ok(DatabaseApps::get_one(conn, id, redirect)
|
||||
.await?
|
||||
.map(Self::from))
|
||||
|
|
|
|||
42
crates/apps/src/get_valid.rs
Normal file
42
crates/apps/src/get_valid.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// error
|
||||
#[derive(thiserror::Error)]
|
||||
// the rest
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
#[error("Database: {0}")]
|
||||
Database(#[from] database::Error),
|
||||
|
||||
#[error("Bad response types")]
|
||||
ResponseTypes,
|
||||
|
||||
#[error("Invalid scopes")]
|
||||
Scopes,
|
||||
|
||||
#[error("Invalid application")]
|
||||
Application,
|
||||
}
|
||||
|
||||
use super::App;
|
||||
use database::sqlx::SqliteExecutor;
|
||||
|
||||
impl App {
|
||||
pub async fn get_valid_app(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
response_type: &str,
|
||||
scope: &str,
|
||||
client_id: &str,
|
||||
redirect_uri: &str,
|
||||
) -> Result<App, Error> {
|
||||
// Check for valid response types
|
||||
openid::parse_response_types(response_type).ok_or_else(|| Error::ResponseTypes)?;
|
||||
|
||||
// Check for supported scopes
|
||||
if !openid::SupportedScopes::check_supported_scopes(scope) {
|
||||
return Err(Error::Scopes);
|
||||
}
|
||||
|
||||
Self::get_one(conn, client_id, redirect_uri)
|
||||
.await?
|
||||
.ok_or_else(|| Error::Application)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
mod database;
|
||||
mod error;
|
||||
mod get_valid;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use id::AppID;
|
||||
|
||||
pub use crate::error::Error;
|
||||
pub use get_valid::Error as GetValidError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct App {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue