diff --git a/bindings/matrix-sdk-ffi/src/authentication_service.rs b/bindings/matrix-sdk-ffi/src/authentication_service.rs index d91425db3..e56e89d03 100644 --- a/bindings/matrix-sdk-ffi/src/authentication_service.rs +++ b/bindings/matrix-sdk-ffi/src/authentication_service.rs @@ -103,16 +103,18 @@ impl From 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, /// 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, + /// A URI that contains the client's logo. + pub logo_uri: Option, /// A URI that contains the client's terms of service. - pub tos_uri: String, + pub tos_uri: Option, /// A URI that contains the client's privacy policy. - pub policy_uri: String, + pub policy_uri: Option, /// Pre-configured registrations for use with issuers that don't support /// dynamic client registration. @@ -554,10 +556,12 @@ impl AuthenticationService { ) -> Result { 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>, AuthenticationError>; +} + +impl OptionExt for Option { + fn localized_url(&self) -> Result>, AuthenticationError> { + self.as_deref() + .map(|uri| -> Result, AuthenticationError> { + Ok(Localized::new( + Url::parse(uri).map_err(|_| AuthenticationError::OidcMetadataInvalid)?, + [], + )) + }) + .transpose() + } +}