1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-28 11:02:02 +03:00

WIP: upstream OIDC provider support

This commit is contained in:
Quentin Gliech
2022-11-22 18:28:16 +01:00
parent 7f9be07e8d
commit bedcf44741
28 changed files with 1505 additions and 96 deletions

View File

@ -20,7 +20,6 @@
use std::{collections::BTreeSet, fmt, iter::FromIterator, str::FromStr};
use itertools::Itertools;
use mas_iana::oauth::OAuthAuthorizationEndpointResponseType;
use parse_display::{Display, FromStr};
use serde_with::{DeserializeFromStr, SerializeDisplay};
@ -127,14 +126,23 @@ impl FromStr for ResponseType {
impl fmt::Display for ResponseType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let res = Itertools::intersperse(self.iter().map(ToString::to_string), ' '.to_string())
.collect::<String>();
let mut iter = self.iter();
if res.is_empty() {
write!(f, "none")
// First item shouldn't have a leading space
if let Some(first) = iter.next() {
first.fmt(f)?;
} else {
f.write_str(&res)
// If the whole iterator is empty, write 'none' instead
write!(f, "none")?;
return Ok(());
}
// Write the other items with a leading space
for item in iter {
write!(f, " {item}")?;
}
Ok(())
}
}

View File

@ -20,7 +20,6 @@
use std::{borrow::Cow, collections::BTreeSet, iter::FromIterator, ops::Deref, str::FromStr};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use thiserror::Error;
@ -106,9 +105,9 @@ impl Deref for ScopeToken {
}
}
impl ToString for ScopeToken {
fn to_string(&self) -> String {
self.0.to_string()
impl std::fmt::Display for ScopeToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
@ -169,10 +168,17 @@ impl Scope {
}
}
impl ToString for Scope {
fn to_string(&self) -> String {
let it = self.0.iter().map(ScopeToken::to_string);
Itertools::intersperse(it, ' '.to_string()).collect()
impl std::fmt::Display for Scope {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
for (index, token) in self.0.iter().enumerate() {
if index == 0 {
write!(f, "{token}")?;
} else {
write!(f, " {token}")?;
}
}
Ok(())
}
}