Add authentication from upstream providers #107

Merged
pierre merged 25 commits from feat-upstream-providers into master 2023-04-27 10:10:29 +00:00
2 changed files with 9 additions and 3 deletions
Showing only changes of commit 930cb8bf33 - Show all commits

View File

@ -95,6 +95,12 @@ impl AppConfig {
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)]

View File

@ -40,10 +40,10 @@ impl TotpKey {
pub fn url_for_user(&self, u: &User, conf: &AppConfig) -> String {
format!(
"otpauth://totp/{}:{}?secret={}&issuer={}&algorithm=SHA1&digits={}&period={}",
urlencoding::encode(conf.domain_name()),
urlencoding::encode(conf.domain_name_without_port()),
urlencoding::encode(&u.username),
self.encoded,
urlencoding::encode(conf.domain_name()),
urlencoding::encode(conf.domain_name_without_port()),
NUM_DIGITS,
PERIOD,
)
@ -53,7 +53,7 @@ impl TotpKey {
pub fn account_name(&self, u: &User, conf: &AppConfig) -> String {
format!(
"{}:{}",
urlencoding::encode(conf.domain_name()),
urlencoding::encode(conf.domain_name_without_port()),
urlencoding::encode(&u.username)
)
}