openid: move helper from config to api2
it's not really needed in the config module, and this makes it easier to disable the proxmox-openid dependency linkage as a stop-gap measure. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
324c069848
commit
26a3450f19
|
@ -11,7 +11,8 @@ use proxmox::{list_subdirs_api_method};
|
||||||
use proxmox::{identity, sortable};
|
use proxmox::{identity, sortable};
|
||||||
use proxmox::tools::fs::open_file_locked;
|
use proxmox::tools::fs::open_file_locked;
|
||||||
|
|
||||||
use proxmox_openid::OpenIdAuthenticator;
|
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig};
|
||||||
|
|
||||||
|
|
||||||
use crate::server::ticket::ApiTicket;
|
use crate::server::ticket::ApiTicket;
|
||||||
use crate::tools::ticket::Ticket;
|
use crate::tools::ticket::Ticket;
|
||||||
|
@ -22,6 +23,16 @@ use crate::config::cached_user_info::CachedUserInfo;
|
||||||
use crate::api2::types::*;
|
use crate::api2::types::*;
|
||||||
use crate::auth_helpers::*;
|
use crate::auth_helpers::*;
|
||||||
|
|
||||||
|
fn openid_authenticator(realm_config: &OpenIdRealmConfig, redirect_url: &str) -> Result<OpenIdAuthenticator, Error> {
|
||||||
|
let config = OpenIdConfig {
|
||||||
|
issuer_url: realm_config.issuer_url.clone(),
|
||||||
|
client_id: realm_config.client_id.clone(),
|
||||||
|
client_key: realm_config.client_key.clone(),
|
||||||
|
};
|
||||||
|
OpenIdAuthenticator::discover(&config, redirect_url)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -77,7 +88,7 @@ pub fn openid_login(
|
||||||
let (domains, _digest) = crate::config::domains::config()?;
|
let (domains, _digest) = crate::config::domains::config()?;
|
||||||
let config: OpenIdRealmConfig = domains.lookup("openid", &realm)?;
|
let config: OpenIdRealmConfig = domains.lookup("openid", &realm)?;
|
||||||
|
|
||||||
let open_id = config.authenticator(&redirect_url)?;
|
let open_id = openid_authenticator(&config, &redirect_url)?;
|
||||||
|
|
||||||
let info = open_id.verify_authorization_code(&code, &private_auth_state)?;
|
let info = open_id.verify_authorization_code(&code, &private_auth_state)?;
|
||||||
|
|
||||||
|
@ -171,7 +182,7 @@ fn openid_auth_url(
|
||||||
let (domains, _digest) = crate::config::domains::config()?;
|
let (domains, _digest) = crate::config::domains::config()?;
|
||||||
let config: OpenIdRealmConfig = domains.lookup("openid", &realm)?;
|
let config: OpenIdRealmConfig = domains.lookup("openid", &realm)?;
|
||||||
|
|
||||||
let open_id = config.authenticator(&redirect_url)?;
|
let open_id = openid_authenticator(&config, &redirect_url)?;
|
||||||
|
|
||||||
let url = open_id.authorize_url(PROXMOX_BACKUP_RUN_DIR_M!(), &realm)?
|
let url = open_id.authorize_url(PROXMOX_BACKUP_RUN_DIR_M!(), &realm)?
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
|
@ -3,8 +3,6 @@ use lazy_static::lazy_static;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig};
|
|
||||||
|
|
||||||
use proxmox::api::{
|
use proxmox::api::{
|
||||||
api,
|
api,
|
||||||
schema::*,
|
schema::*,
|
||||||
|
@ -95,18 +93,6 @@ pub struct OpenIdRealmConfig {
|
||||||
pub username_claim: Option<OpenIdUserAttribute>,
|
pub username_claim: Option<OpenIdUserAttribute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenIdRealmConfig {
|
|
||||||
|
|
||||||
pub fn authenticator(&self, redirect_url: &str) -> Result<OpenIdAuthenticator, Error> {
|
|
||||||
let config = OpenIdConfig {
|
|
||||||
issuer_url: self.issuer_url.clone(),
|
|
||||||
client_id: self.client_id.clone(),
|
|
||||||
client_key: self.client_key.clone(),
|
|
||||||
};
|
|
||||||
OpenIdAuthenticator::discover(&config, redirect_url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init() -> SectionConfig {
|
fn init() -> SectionConfig {
|
||||||
let obj_schema = match OpenIdRealmConfig::API_SCHEMA {
|
let obj_schema = match OpenIdRealmConfig::API_SCHEMA {
|
||||||
Schema::Object(ref obj_schema) => obj_schema,
|
Schema::Object(ref obj_schema) => obj_schema,
|
||||||
|
|
Loading…
Reference in New Issue