Add openid-connecter discovery route

This commit is contained in:
Pierre HUBERT 2022-04-08 18:53:57 +02:00
parent c7d075f94e
commit 7978706803
7 changed files with 67 additions and 4 deletions

View File

@ -1,5 +1,4 @@
# Basic OIDC
Basic OpenID provider. Still under early development.
TODO :
- [ ] Bruteforce protection
Official OpenID specifications: https://openid.net/developers/specs/

View File

@ -3,4 +3,5 @@ pub mod base_controller;
pub mod login_controller;
pub mod settings_controller;
pub mod admin_controller;
pub mod admin_api;
pub mod admin_api;
pub mod openid_controller;

View File

@ -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<AppConfig>) -> 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"]
})
}

View File

@ -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)
}
}
}

View File

@ -4,4 +4,5 @@ pub mod session_identity;
pub mod user;
pub mod client;
pub mod remote_ip;
pub mod current_user;
pub mod current_user;
pub mod openid_config;

32
src/data/openid_config.rs Normal file
View File

@ -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>,
}

View File

@ -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()