Add authentication from upstream providers (#107)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Let BasicOIDC delegate authentication to upstream providers (Google, GitHub, GitLab, Keycloak...) Reviewed-on: #107
This commit is contained in:
@@ -2,7 +2,9 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::constants::{APP_NAME, CLIENTS_LIST_FILE, USERS_LIST_FILE};
|
||||
use crate::constants::{
|
||||
APP_NAME, CLIENTS_LIST_FILE, OIDC_PROVIDER_CB_URI, PROVIDERS_LIST_FILE, USERS_LIST_FILE,
|
||||
};
|
||||
|
||||
/// Basic OIDC provider
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
@@ -72,6 +74,10 @@ impl AppConfig {
|
||||
self.storage_path().join(CLIENTS_LIST_FILE)
|
||||
}
|
||||
|
||||
pub fn providers_file(&self) -> PathBuf {
|
||||
self.storage_path().join(PROVIDERS_LIST_FILE)
|
||||
}
|
||||
|
||||
pub fn full_url(&self, uri: &str) -> String {
|
||||
if uri.starts_with('/') {
|
||||
format!("{}{}", self.website_origin, uri)
|
||||
@@ -80,9 +86,21 @@ impl AppConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the URL where a upstream OpenID provider should redirect
|
||||
/// the user after an authentication
|
||||
pub fn oidc_provider_redirect_url(&self) -> String {
|
||||
AppConfig::get().full_url(OIDC_PROVIDER_CB_URI)
|
||||
}
|
||||
|
||||
pub fn domain_name(&self) -> &str {
|
||||
self.website_origin.split('/').nth(2).unwrap_or(APP_NAME)
|
||||
}
|
||||
|
||||
/// Get the domain without the port
|
||||
pub fn domain_name_without_port(&self) -> &str {
|
||||
let domain = self.domain_name();
|
||||
domain.split_once(':').map(|i| i.0).unwrap_or(domain)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user