From 797870680324dc0a3949e19c4f4d6ae6883468d5 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Fri, 8 Apr 2022 18:53:57 +0200 Subject: [PATCH] Add openid-connecter discovery route --- README.md | 3 +-- src/controllers/mod.rs | 3 ++- src/controllers/openid_controller.rs | 19 +++++++++++++++++ src/data/app_config.rs | 8 +++++++ src/data/mod.rs | 3 ++- src/data/openid_config.rs | 32 ++++++++++++++++++++++++++++ src/main.rs | 3 +++ 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/controllers/openid_controller.rs create mode 100644 src/data/openid_config.rs diff --git a/README.md b/README.md index f854c72..aed2027 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # Basic OIDC Basic OpenID provider. Still under early development. -TODO : -- [ ] Bruteforce protection \ No newline at end of file +Official OpenID specifications: https://openid.net/developers/specs/ \ No newline at end of file diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index ce8cccd..03adad5 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -3,4 +3,5 @@ pub mod base_controller; pub mod login_controller; pub mod settings_controller; pub mod admin_controller; -pub mod admin_api; \ No newline at end of file +pub mod admin_api; +pub mod openid_controller; \ No newline at end of file diff --git a/src/controllers/openid_controller.rs b/src/controllers/openid_controller.rs new file mode 100644 index 0000000..396aa49 --- /dev/null +++ b/src/controllers/openid_controller.rs @@ -0,0 +1,19 @@ +use actix_web::{HttpResponse, Responder, web}; + +use crate::data::app_config::AppConfig; +use crate::data::openid_config::OpenIDConfig; + +pub async fn get_configuration(app_conf: web::Data) -> impl Responder { + HttpResponse::Ok().json(OpenIDConfig { + issuer: app_conf.full_url("/"), + authorization_endpoint: app_conf.full_url("openid/authorize"), + token_endpoint: app_conf.full_url("openid/token"), + userinfo_endpoint: app_conf.full_url("openid/userinfo"), + jwks_uri: app_conf.full_url("openid/jwks_uri"), + scopes_supported: vec!["openid", "profile", "email"], + response_types_supported: vec!["code", "id_token", "token id_token"], + subject_types_supported: vec!["public"], + id_token_signing_alg_values_supported: vec!["RS256"], + claims_supported: vec!["sub", "exp", "name", "given_name", "family_name", "email"] + }) +} \ No newline at end of file diff --git a/src/data/app_config.rs b/src/data/app_config.rs index 69a80c7..25eb66a 100644 --- a/src/data/app_config.rs +++ b/src/data/app_config.rs @@ -45,4 +45,12 @@ impl AppConfig { pub fn clients_file(&self) -> PathBuf { self.storage_path().join(CLIENTS_LIST_FILE) } + + pub fn full_url(&self, uri: &str) -> String { + if uri.starts_with("/") { + format!("{}{}", self.website_origin, uri) + } else { + format!("{}/{}", self.website_origin, uri) + } + } } diff --git a/src/data/mod.rs b/src/data/mod.rs index 099a69c..9d43bc5 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -4,4 +4,5 @@ pub mod session_identity; pub mod user; pub mod client; pub mod remote_ip; -pub mod current_user; \ No newline at end of file +pub mod current_user; +pub mod openid_config; \ No newline at end of file diff --git a/src/data/openid_config.rs b/src/data/openid_config.rs new file mode 100644 index 0000000..70486e9 --- /dev/null +++ b/src/data/openid_config.rs @@ -0,0 +1,32 @@ +#[derive(Debug, Clone, serde::Serialize)] +pub struct OpenIDConfig { + /// URL using the https scheme with no query or fragment component that the OP asserts as its Issuer Identifier. If Issuer discovery is supported (see Section 2), this value MUST be identical to the issuer value returned by WebFinger. This also MUST be identical to the iss Claim value in ID Tokens issued from this Issuer + pub issuer: String, + + /// REQUIRED. URL of the OP's OAuth 2.0 Authorization Endpoint `OpenID.Core` + pub authorization_endpoint: String, + + /// URL of the OP's OAuth 2.0 Token Endpoint `OpenID.Core`. This is REQUIRED unless only the Implicit Flow is used. + pub token_endpoint: String, + + /// RECOMMENDED. URL of the OP's UserInfo Endpoint `[`OpenID.Core`]`. This URL MUST use the https scheme and MAY contain port, path, and query parameter components + pub userinfo_endpoint: String, + + /// REQUIRED. URL of the OP's JSON Web Key Set `[`JWK`]` document. This contains the signing key(s) the RP uses to validate signatures from the OP. The JWK Set MAY also contain the Server's encryption key(s), which are used by RPs to encrypt requests to the Server. When both signing and encryption keys are made available, a use (Key Use) parameter value is REQUIRED for all keys in the referenced JWK Set to indicate each key's intended usage. Although some algorithms allow the same key to be used for both signatures and encryption, doing so is NOT RECOMMENDED, as it is less secure. The JWK x5c parameter MAY be used to provide X.509 representations of keys provided. When used, the bare key values MUST still be present and MUST match those in the certificate. + pub jwks_uri: String, + + /// RECOMMENDED. JSON array containing a list of the OAuth 2.0 `[`RFC6749`]` scope values that this server supports. The server MUST support the openid scope value. Servers MAY choose not to advertise some supported scope values even when this parameter is used, although those defined in `[`OpenID.Core`]` SHOULD be listed, if supported. + pub scopes_supported: Vec<&'static str>, + + /// REQUIRED. JSON array containing a list of the OAuth 2.0 response_type values that this OP supports. Dynamic OpenID Providers MUST support the code, id_token, and the token id_token Response Type values. + pub response_types_supported: Vec<&'static str>, + + /// REQUIRED. JSON array containing a list of the Subject Identifier types that this OP supports. Valid types include pairwise and public. + pub subject_types_supported: Vec<&'static str>, + + /// REQUIRED. JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT `[`JWT`. The algorithm RS256 MUST be included. The value none MAY be supported, but MUST NOT be used unless the Response Type used returns no ID Token from the Authorization Endpoint (such as when using the Authorization Code Flow). + pub id_token_signing_alg_values_supported: Vec<&'static str>, + + /// RECOMMENDED. JSON array containing a list of the Claim Names of the Claims that the OpenID Provider MAY be able to supply values for. Note that for privacy or other reasons, this might not be an exhaustive list. + pub claims_supported: Vec<&'static str>, +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ec25d5f..6140ea5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,9 @@ async fn main() -> std::io::Result<()> { // Admin API .route("/admin/api/find_username", web::post().to(admin_api::find_username)) .route("/admin/api/delete_user", web::post().to(admin_api::delete_user)) + + // OpenID specs + .route(".well-known/openid-configuration", web::get().to(openid_controller::get_configuration)) }) .bind(listen_address)? .run()