feat(openid): add well-known openid config page
This commit is contained in:
parent
66b7a256cf
commit
a7f6c28e0d
7 changed files with 52 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
[instance]
|
[instance]
|
||||||
|
base_uri = "http://localhost:8085"
|
||||||
name = "Example org"
|
name = "Example org"
|
||||||
logo_uri = "https://example.org/logo.png"
|
logo_uri = "https://example.org/logo.png"
|
||||||
|
|
||||||
|
@ -9,7 +10,8 @@ description = "A super application where you can do everything you want."
|
||||||
client_id = "a1785786-8be1-443c-9a6f-35feed703609"
|
client_id = "a1785786-8be1-443c-9a6f-35feed703609"
|
||||||
client_secret = "49c6c16a-0a8a-4981-a60d-5cb96582cc1a"
|
client_secret = "49c6c16a-0a8a-4981-a60d-5cb96582cc1a"
|
||||||
allowed_redirect_uris = [
|
allowed_redirect_uris = [
|
||||||
"http://localhost:9090/authorize"
|
"http://localhost:9090/authorize",
|
||||||
|
"http://localhost:9876/callback"
|
||||||
]
|
]
|
||||||
|
|
||||||
[[roles]]
|
[[roles]]
|
||||||
|
|
10
http_integration_tests/oauth2c.sh
Executable file
10
http_integration_tests/oauth2c.sh
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
oauth2c http://localhost:8085 \
|
||||||
|
--client-id "a1785786-8be1-443c-9a6f-35feed703609" \
|
||||||
|
--client-secret "49c6c16a-0a8a-4981-a60d-5cb96582cc1a" \
|
||||||
|
--response-types code \
|
||||||
|
--response-mode query \
|
||||||
|
--grant-type authorization_code \
|
||||||
|
--auth-method client_secret_basic \
|
||||||
|
--scopes "read_user_basic"
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod oauth2;
|
pub mod oauth2;
|
||||||
pub mod read_user;
|
pub mod read_user;
|
||||||
|
pub mod openid;
|
||||||
|
|
1
src/controllers/api/openid/mod.rs
Normal file
1
src/controllers/api/openid/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod well_known;
|
32
src/controllers/api/openid/well_known.rs
Normal file
32
src/controllers/api/openid/well_known.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
use axum::{extract::State, response::IntoResponse, Json};
|
||||||
|
use fully_pub::fully_pub;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
use crate::server::AppState;
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[fully_pub]
|
||||||
|
struct WellKnownOpenIdConfiguration {
|
||||||
|
issuer: String,
|
||||||
|
authorization_endpoint: String,
|
||||||
|
token_endpoint: String,
|
||||||
|
userinfo_endpoint: String,
|
||||||
|
scopes_supported: Vec<String>,
|
||||||
|
response_types_supported: Vec<String>,
|
||||||
|
token_endpoint_auth_methods_supported: Vec<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_well_known_openid_configuration(
|
||||||
|
State(app_state): State<AppState>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let base_url = app_state.config.instance.base_uri;
|
||||||
|
Json(WellKnownOpenIdConfiguration {
|
||||||
|
issuer: base_url.clone(),
|
||||||
|
authorization_endpoint: format!("{}/authorize", base_url),
|
||||||
|
token_endpoint: format!("{}/api/token", base_url),
|
||||||
|
userinfo_endpoint: format!("{}/api/user", base_url),
|
||||||
|
scopes_supported: vec!["read_user_basic".into()],
|
||||||
|
response_types_supported: vec!["code".into()],
|
||||||
|
token_endpoint_auth_methods_supported: vec!["client_secret_basic".into()],
|
||||||
|
})
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ const fn _default_true() -> bool { true }
|
||||||
#[fully_pub]
|
#[fully_pub]
|
||||||
/// Instance branding/customization config
|
/// Instance branding/customization config
|
||||||
struct InstanceConfig {
|
struct InstanceConfig {
|
||||||
|
base_uri: String,
|
||||||
name: String,
|
name: String,
|
||||||
logo_uri: Option<String>
|
logo_uri: Option<String>
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,11 +40,15 @@ pub fn build_router(server_config: &ServerConfig, app_state: AppState) -> Router
|
||||||
.route("/api/user", get(api::read_user::read_user_basic))
|
.route("/api/user", get(api::read_user::read_user_basic))
|
||||||
.layer(middleware::from_fn_with_state(app_state.clone(), app_auth::enforce_jwt_auth_middleware));
|
.layer(middleware::from_fn_with_state(app_state.clone(), app_auth::enforce_jwt_auth_middleware));
|
||||||
|
|
||||||
|
let well_known_routes = Router::new()
|
||||||
|
.route("/.well-known/openid-configuration", get(api::openid::well_known::get_well_known_openid_configuration));
|
||||||
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.merge(public_routes)
|
.merge(public_routes)
|
||||||
.merge(user_routes)
|
.merge(user_routes)
|
||||||
.merge(app_routes)
|
.merge(app_routes)
|
||||||
.merge(app_user_routes)
|
.merge(app_user_routes)
|
||||||
|
.merge(well_known_routes)
|
||||||
.layer(middleware::from_fn_with_state(app_state.clone(), renderer_middleware))
|
.layer(middleware::from_fn_with_state(app_state.clone(), renderer_middleware))
|
||||||
.nest_service(
|
.nest_service(
|
||||||
"/assets",
|
"/assets",
|
||||||
|
|
Loading…
Reference in a new issue