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
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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue