Compare commits
2 commits
fdb868d10c
...
905c57000a
| Author | SHA1 | Date | |
|---|---|---|---|
| 905c57000a | |||
| 18b33c00a7 |
3 changed files with 8 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use axum::{extract::State, http::StatusCode, response::{Html, IntoResponse}, Extension, Form, Json};
|
use axum::{extract::State, http::StatusCode, response::{Html, IntoResponse}, Extension, Form, Json};
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use fully_pub::fully_pub;
|
use fully_pub::fully_pub;
|
||||||
use log::error;
|
use log::{debug, error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use kernel::{models::authorization::Authorization, repositories::users::get_user_by_id};
|
use kernel::{models::authorization::Authorization, repositories::users::get_user_by_id};
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
|
|
||||||
const AUTHORIZATION_CODE_TTL_SECONDS: i64 = 120;
|
const AUTHORIZATION_CODE_TTL_SECONDS: i64 = 120;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
#[fully_pub]
|
#[fully_pub]
|
||||||
struct AccessTokenRequestParams {
|
struct AccessTokenRequestParams {
|
||||||
grant_type: String,
|
grant_type: String,
|
||||||
|
|
@ -48,6 +48,7 @@ pub async fn get_access_token(
|
||||||
let authorization = match authorizations_res {
|
let authorization = match authorizations_res {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(sqlx::Error::RowNotFound) => {
|
Err(sqlx::Error::RowNotFound) => {
|
||||||
|
error!("Received invalid authorization_code.");
|
||||||
return (
|
return (
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
Json("Invalid authorization_code.")
|
Json("Invalid authorization_code.")
|
||||||
|
|
@ -68,12 +69,15 @@ pub async fn get_access_token(
|
||||||
Utc::now().signed_duration_since(ts) < Duration::seconds(AUTHORIZATION_CODE_TTL_SECONDS)
|
Utc::now().signed_duration_since(ts) < Duration::seconds(AUTHORIZATION_CODE_TTL_SECONDS)
|
||||||
});
|
});
|
||||||
if !is_code_valid {
|
if !is_code_valid {
|
||||||
|
debug!("Received expired authorization code");
|
||||||
return (
|
return (
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
Json("Authorization code has expired.")
|
Json("Authorization code has expired.")
|
||||||
).into_response();
|
).into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("Generating access_token and id_token.");
|
||||||
|
|
||||||
// 2.3. Fetch user resource owner
|
// 2.3. Fetch user resource owner
|
||||||
let user = get_user_by_id(&app_state.db, &authorization.user_id)
|
let user = get_user_by_id(&app_state.db, &authorization.user_id)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use jsonwebkey_convert_repaired::RSAPublicKey;
|
use jsonwebkey_convert_repaired::RSAPublicKey;
|
||||||
use jsonwebkey_convert_repaired::der::FromPem;
|
use jsonwebkey_convert_repaired::der::FromPem;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ struct WellKnownOpenIdConfiguration {
|
||||||
userinfo_endpoint: String,
|
userinfo_endpoint: String,
|
||||||
scopes_supported: Vec<String>,
|
scopes_supported: Vec<String>,
|
||||||
response_types_supported: Vec<String>,
|
response_types_supported: Vec<String>,
|
||||||
|
subject_types_supported: Vec<String>,
|
||||||
token_endpoint_auth_methods_supported: Vec<String>,
|
token_endpoint_auth_methods_supported: Vec<String>,
|
||||||
id_token_signing_alg_values_supported: Vec<String>,
|
id_token_signing_alg_values_supported: Vec<String>,
|
||||||
jwks_uri: String
|
jwks_uri: String
|
||||||
|
|
@ -33,6 +34,7 @@ pub async fn get_well_known_openid_configuration(
|
||||||
userinfo_endpoint: format!("{}/api/user", base_url),
|
userinfo_endpoint: format!("{}/api/user", base_url),
|
||||||
scopes_supported: AuthorizationScope::iter().map(|v| v.to_string()).collect(),
|
scopes_supported: AuthorizationScope::iter().map(|v| v.to_string()).collect(),
|
||||||
response_types_supported: vec!["code".into()],
|
response_types_supported: vec!["code".into()],
|
||||||
|
subject_types_supported: vec!["public".into(), "pairwise".into()],
|
||||||
token_endpoint_auth_methods_supported: vec!["client_secret_basic".into()],
|
token_endpoint_auth_methods_supported: vec!["client_secret_basic".into()],
|
||||||
id_token_signing_alg_values_supported: vec!["RS256".into()],
|
id_token_signing_alg_values_supported: vec!["RS256".into()],
|
||||||
jwks_uri: format!("{}/.well-known/jwks", base_url)
|
jwks_uri: format!("{}/.well-known/jwks", base_url)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue