2021-11-18 10:19:44 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
use proxmox_schema::{api, ApiStringFormat, ArraySchema, Schema, StringSchema, Updater};
|
2021-11-18 10:19:44 +00:00
|
|
|
|
|
|
|
use super::{
|
2022-04-10 15:53:42 +00:00
|
|
|
PROXMOX_SAFE_ID_FORMAT, PROXMOX_SAFE_ID_REGEX, REALM_ID_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA,
|
2021-11-18 10:19:44 +00:00
|
|
|
};
|
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const OPENID_SCOPE_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX);
|
2021-11-18 10:19:44 +00:00
|
|
|
|
|
|
|
pub const OPENID_SCOPE_SCHEMA: Schema = StringSchema::new("OpenID Scope Name.")
|
|
|
|
.format(&OPENID_SCOPE_FORMAT)
|
|
|
|
.schema();
|
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const OPENID_SCOPE_ARRAY_SCHEMA: Schema =
|
|
|
|
ArraySchema::new("Array of OpenId Scopes.", &OPENID_SCOPE_SCHEMA).schema();
|
2021-11-18 10:19:44 +00:00
|
|
|
|
|
|
|
pub const OPENID_SCOPE_LIST_FORMAT: ApiStringFormat =
|
|
|
|
ApiStringFormat::PropertyString(&OPENID_SCOPE_ARRAY_SCHEMA);
|
|
|
|
|
2022-02-08 13:57:16 +00:00
|
|
|
pub const OPENID_DEFAILT_SCOPE_LIST: &str = "email profile";
|
2021-11-18 10:19:44 +00:00
|
|
|
pub const OPENID_SCOPE_LIST_SCHEMA: Schema = StringSchema::new("OpenID Scope List")
|
|
|
|
.format(&OPENID_SCOPE_LIST_FORMAT)
|
|
|
|
.default(OPENID_DEFAILT_SCOPE_LIST)
|
|
|
|
.schema();
|
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const OPENID_ACR_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&PROXMOX_SAFE_ID_REGEX);
|
2021-11-18 10:19:44 +00:00
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const OPENID_ACR_SCHEMA: Schema =
|
|
|
|
StringSchema::new("OpenID Authentication Context Class Reference.")
|
|
|
|
.format(&OPENID_SCOPE_FORMAT)
|
|
|
|
.schema();
|
2021-11-18 10:19:44 +00:00
|
|
|
|
2022-04-10 15:53:42 +00:00
|
|
|
pub const OPENID_ACR_ARRAY_SCHEMA: Schema =
|
|
|
|
ArraySchema::new("Array of OpenId ACRs.", &OPENID_ACR_SCHEMA).schema();
|
2021-11-18 10:19:44 +00:00
|
|
|
|
|
|
|
pub const OPENID_ACR_LIST_FORMAT: ApiStringFormat =
|
|
|
|
ApiStringFormat::PropertyString(&OPENID_ACR_ARRAY_SCHEMA);
|
|
|
|
|
|
|
|
pub const OPENID_ACR_LIST_SCHEMA: Schema = StringSchema::new("OpenID ACR List")
|
|
|
|
.format(&OPENID_ACR_LIST_FORMAT)
|
|
|
|
.schema();
|
|
|
|
|
|
|
|
pub const OPENID_USERNAME_CLAIM_SCHEMA: Schema = StringSchema::new(
|
|
|
|
"Use the value of this attribute/claim as unique user name. It \
|
|
|
|
is up to the identity provider to guarantee the uniqueness. The \
|
|
|
|
OpenID specification only guarantees that Subject ('sub') is \
|
|
|
|
unique. Also make sure that the user is not allowed to change that \
|
2022-04-10 15:53:42 +00:00
|
|
|
attribute by himself!",
|
|
|
|
)
|
|
|
|
.max_length(64)
|
|
|
|
.min_length(1)
|
|
|
|
.format(&PROXMOX_SAFE_ID_FORMAT)
|
|
|
|
.schema();
|
2021-11-18 10:19:44 +00:00
|
|
|
|
|
|
|
#[api(
|
|
|
|
properties: {
|
|
|
|
realm: {
|
|
|
|
schema: REALM_ID_SCHEMA,
|
|
|
|
},
|
|
|
|
"client-key": {
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"scopes": {
|
|
|
|
schema: OPENID_SCOPE_LIST_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
"acr-values": {
|
|
|
|
schema: OPENID_ACR_LIST_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
prompt: {
|
|
|
|
description: "OpenID Prompt",
|
|
|
|
type: String,
|
|
|
|
format: &PROXMOX_SAFE_ID_FORMAT,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
comment: {
|
|
|
|
optional: true,
|
|
|
|
schema: SINGLE_LINE_COMMENT_SCHEMA,
|
|
|
|
},
|
|
|
|
autocreate: {
|
|
|
|
optional: true,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
"username-claim": {
|
|
|
|
schema: OPENID_USERNAME_CLAIM_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)]
|
|
|
|
#[derive(Serialize, Deserialize, Updater)]
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(rename_all = "kebab-case")]
|
2021-11-18 10:19:44 +00:00
|
|
|
/// OpenID configuration properties.
|
|
|
|
pub struct OpenIdRealmConfig {
|
|
|
|
#[updater(skip)]
|
|
|
|
pub realm: String,
|
|
|
|
/// OpenID Issuer Url
|
|
|
|
pub issuer_url: String,
|
|
|
|
/// OpenID Client ID
|
|
|
|
pub client_id: String,
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub scopes: Option<String>,
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub acr_values: Option<String>,
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub prompt: Option<String>,
|
|
|
|
/// OpenID Client Key
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub client_key: Option<String>,
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub comment: Option<String>,
|
|
|
|
/// Automatically create users if they do not exist.
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub autocreate: Option<bool>,
|
|
|
|
#[updater(skip)]
|
2022-04-10 15:53:42 +00:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
2021-11-18 10:19:44 +00:00
|
|
|
pub username_claim: Option<String>,
|
|
|
|
}
|