mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-05 14:35:20 -04:00
feat(bindings): Add logo_uri to OidcConfiguration
… and make most OidcConfiguration properties optional.
This commit is contained in:
@@ -103,16 +103,18 @@ impl From<OidcError> for AuthenticationError {
|
||||
#[derive(uniffi::Record)]
|
||||
pub struct OidcConfiguration {
|
||||
/// The name of the client that will be shown during OIDC authentication.
|
||||
pub client_name: String,
|
||||
pub client_name: Option<String>,
|
||||
/// The redirect URI that will be used when OIDC authentication is
|
||||
/// successful.
|
||||
pub redirect_uri: String,
|
||||
/// A URI that contains information about the client.
|
||||
pub client_uri: String,
|
||||
pub client_uri: Option<String>,
|
||||
/// A URI that contains the client's logo.
|
||||
pub logo_uri: Option<String>,
|
||||
/// A URI that contains the client's terms of service.
|
||||
pub tos_uri: String,
|
||||
pub tos_uri: Option<String>,
|
||||
/// A URI that contains the client's privacy policy.
|
||||
pub policy_uri: String,
|
||||
pub policy_uri: Option<String>,
|
||||
|
||||
/// Pre-configured registrations for use with issuers that don't support
|
||||
/// dynamic client registration.
|
||||
@@ -554,10 +556,12 @@ impl AuthenticationService {
|
||||
) -> Result<VerifiedClientMetadata, AuthenticationError> {
|
||||
let redirect_uri = Url::parse(&configuration.redirect_uri)
|
||||
.map_err(|_| AuthenticationError::OidcCallbackUrlInvalid)?;
|
||||
let client_name = Some(Localized::new(configuration.client_name.to_owned(), []));
|
||||
let client_uri = Url::parse(&configuration.client_uri).ok().map(|u| Localized::new(u, []));
|
||||
let policy_uri = Url::parse(&configuration.policy_uri).ok().map(|u| Localized::new(u, []));
|
||||
let tos_uri = Url::parse(&configuration.tos_uri).ok().map(|u| Localized::new(u, []));
|
||||
let client_name =
|
||||
configuration.client_name.as_ref().map(|n| Localized::new(n.to_owned(), []));
|
||||
let client_uri = configuration.client_uri.localized_url()?;
|
||||
let logo_uri = configuration.logo_uri.localized_url()?;
|
||||
let policy_uri = configuration.policy_uri.localized_url()?;
|
||||
let tos_uri = configuration.tos_uri.localized_url()?;
|
||||
|
||||
ClientMetadata {
|
||||
application_type: Some(ApplicationType::Native),
|
||||
@@ -569,6 +573,7 @@ impl AuthenticationService {
|
||||
client_name,
|
||||
contacts: None,
|
||||
client_uri,
|
||||
logo_uri,
|
||||
policy_uri,
|
||||
tos_uri,
|
||||
..Default::default()
|
||||
@@ -609,3 +614,22 @@ impl AuthenticationService {
|
||||
Ok(client)
|
||||
}
|
||||
}
|
||||
|
||||
trait OptionExt {
|
||||
/// Convenience method to convert a string to a URL and returns it as a
|
||||
/// Localized URL. No localization is actually performed.
|
||||
fn localized_url(&self) -> Result<Option<Localized<Url>>, AuthenticationError>;
|
||||
}
|
||||
|
||||
impl OptionExt for Option<String> {
|
||||
fn localized_url(&self) -> Result<Option<Localized<Url>>, AuthenticationError> {
|
||||
self.as_deref()
|
||||
.map(|uri| -> Result<Localized<Url>, AuthenticationError> {
|
||||
Ok(Localized::new(
|
||||
Url::parse(uri).map_err(|_| AuthenticationError::OidcMetadataInvalid)?,
|
||||
[],
|
||||
))
|
||||
})
|
||||
.transpose()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user