mirror of
https://git.proxmox.com/git/proxmox-perl-rs
synced 2025-05-21 16:52:32 +00:00
move openid code from pve-rs to common
Change pve-rs functions to be wrapper functions for common. Signed-off-by: Markus Frank <m.frank@proxmox.com>
This commit is contained in:
parent
62ade0c4bb
commit
9ee9ad4154
@ -24,6 +24,7 @@ PERLMOD_PACKAGES := \
|
||||
Proxmox::RS::APT::Repositories \
|
||||
Proxmox::RS::CalendarEvent \
|
||||
Proxmox::RS::Notify \
|
||||
Proxmox::RS::OIDC \
|
||||
Proxmox::RS::SharedCache \
|
||||
Proxmox::RS::Subscription
|
||||
|
||||
|
@ -2,5 +2,6 @@ pub mod apt;
|
||||
mod calendar_event;
|
||||
pub mod logger;
|
||||
pub mod notify;
|
||||
pub mod oidc;
|
||||
pub mod shared_cache;
|
||||
mod subscription;
|
||||
|
63
common/src/oidc/mod.rs
Normal file
63
common/src/oidc/mod.rs
Normal file
@ -0,0 +1,63 @@
|
||||
#[perlmod::package(name = "Proxmox::RS::OIDC")]
|
||||
pub mod export {
|
||||
use std::sync::Mutex;
|
||||
|
||||
use anyhow::Error;
|
||||
|
||||
use perlmod::{to_value, Value};
|
||||
|
||||
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig, PrivateAuthState};
|
||||
|
||||
perlmod::declare_magic!(Box<OIDC> : &OIDC as "Proxmox::RS::OIDC");
|
||||
|
||||
/// An OpenIdAuthenticator client instance.
|
||||
pub struct OIDC {
|
||||
inner: Mutex<OpenIdAuthenticator>,
|
||||
}
|
||||
|
||||
/// Create a new OIDC client instance
|
||||
#[export(raw_return)]
|
||||
pub fn discover(
|
||||
#[raw] class: Value,
|
||||
config: OpenIdConfig,
|
||||
redirect_url: &str,
|
||||
) -> Result<Value, Error> {
|
||||
let oidc = OpenIdAuthenticator::discover(&config, redirect_url)?;
|
||||
Ok(perlmod::instantiate_magic!(
|
||||
&class,
|
||||
MAGIC => Box::new(OIDC {
|
||||
inner: Mutex::new(oidc),
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
#[export]
|
||||
pub fn authorize_url(
|
||||
#[try_from_ref] this: &OIDC,
|
||||
state_dir: &str,
|
||||
realm: &str,
|
||||
) -> Result<String, Error> {
|
||||
let oidc = this.inner.lock().unwrap();
|
||||
oidc.authorize_url(state_dir, realm)
|
||||
}
|
||||
|
||||
#[export]
|
||||
pub fn verify_public_auth_state(
|
||||
state_dir: &str,
|
||||
state: &str,
|
||||
) -> Result<(String, PrivateAuthState), Error> {
|
||||
OpenIdAuthenticator::verify_public_auth_state(state_dir, state)
|
||||
}
|
||||
|
||||
#[export(raw_return)]
|
||||
pub fn verify_authorization_code(
|
||||
#[try_from_ref] this: &OIDC,
|
||||
code: &str,
|
||||
private_auth_state: PrivateAuthState,
|
||||
) -> Result<Value, Error> {
|
||||
let oidc = this.inner.lock().unwrap();
|
||||
let claims = oidc.verify_authorization_code_simple(code, &private_auth_state)?;
|
||||
|
||||
Ok(to_value(&claims)?)
|
||||
}
|
||||
}
|
@ -42,3 +42,4 @@ proxmox-subscription = "0.5"
|
||||
proxmox-sys = "0.6"
|
||||
proxmox-tfa = { version = "5", features = ["api"] }
|
||||
proxmox-time = "2"
|
||||
proxmox-openid = "0.10.0"
|
||||
|
@ -27,6 +27,7 @@ Build-Depends: cargo:native <!nocheck>,
|
||||
librust-proxmox-http-error-0.1+default-dev,
|
||||
librust-proxmox-log-0.2+default-dev,
|
||||
librust-proxmox-notify-0.5+default-dev,
|
||||
librust-proxmox-openid-0.10+default-dev,
|
||||
librust-proxmox-shared-cache-0.1+default-dev,
|
||||
librust-proxmox-subscription-0.5+default-dev,
|
||||
librust-proxmox-sys-0.6+default-dev,
|
||||
|
@ -1,19 +1,13 @@
|
||||
#[perlmod::package(name = "PVE::RS::OpenId", lib = "pve_rs")]
|
||||
mod export {
|
||||
use std::sync::Mutex;
|
||||
|
||||
use anyhow::Error;
|
||||
|
||||
use perlmod::{to_value, Value};
|
||||
use perlmod::Value;
|
||||
|
||||
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig, PrivateAuthState};
|
||||
use proxmox_openid::{OpenIdConfig, PrivateAuthState};
|
||||
|
||||
perlmod::declare_magic!(Box<OpenId> : &OpenId as "PVE::RS::OpenId");
|
||||
|
||||
/// An OpenIdAuthenticator client instance.
|
||||
pub struct OpenId {
|
||||
inner: Mutex<OpenIdAuthenticator>,
|
||||
}
|
||||
use crate::common::oidc::export as common;
|
||||
use crate::common::oidc::export::OIDC as OpenId;
|
||||
|
||||
/// Create a new OpenId client instance
|
||||
#[export(raw_return)]
|
||||
@ -22,13 +16,7 @@ mod export {
|
||||
config: OpenIdConfig,
|
||||
redirect_url: &str,
|
||||
) -> Result<Value, Error> {
|
||||
let open_id = OpenIdAuthenticator::discover(&config, redirect_url)?;
|
||||
Ok(perlmod::instantiate_magic!(
|
||||
&class,
|
||||
MAGIC => Box::new(OpenId {
|
||||
inner: Mutex::new(open_id),
|
||||
})
|
||||
))
|
||||
common::discover(class, config, redirect_url)
|
||||
}
|
||||
|
||||
#[export]
|
||||
@ -37,8 +25,7 @@ mod export {
|
||||
state_dir: &str,
|
||||
realm: &str,
|
||||
) -> Result<String, Error> {
|
||||
let open_id = this.inner.lock().unwrap();
|
||||
open_id.authorize_url(state_dir, realm)
|
||||
common::authorize_url(this, state_dir, realm)
|
||||
}
|
||||
|
||||
#[export]
|
||||
@ -46,7 +33,7 @@ mod export {
|
||||
state_dir: &str,
|
||||
state: &str,
|
||||
) -> Result<(String, PrivateAuthState), Error> {
|
||||
OpenIdAuthenticator::verify_public_auth_state(state_dir, state)
|
||||
common::verify_public_auth_state(state_dir, state)
|
||||
}
|
||||
|
||||
#[export(raw_return)]
|
||||
@ -55,9 +42,6 @@ mod export {
|
||||
code: &str,
|
||||
private_auth_state: PrivateAuthState,
|
||||
) -> Result<Value, Error> {
|
||||
let open_id = this.inner.lock().unwrap();
|
||||
let claims = open_id.verify_authorization_code_simple(code, &private_auth_state)?;
|
||||
|
||||
Ok(to_value(&claims)?)
|
||||
common::verify_authorization_code(this, code, private_auth_state)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user