ruma_identity_service_api/
lib.rs1#![doc(html_favicon_url = "https://ruma.dev/favicon.ico")]
2#![doc(html_logo_url = "https://ruma.dev/images/logo.png")]
3#![cfg(any(feature = "client", feature = "server"))]
11#![warn(missing_docs)]
12
13use ruma_common::api::auth_scheme::{
14 AuthScheme, ExtractTokenError, add_access_token_as_authorization_header,
15 extract_bearer_or_query_token,
16};
17
18pub mod association;
19pub mod authentication;
20pub mod discovery;
21pub mod invitation;
22pub mod keys;
23pub mod lookup;
24pub mod tos;
25
26ruma_common::priv_owned_str!();
27
28#[derive(Debug, Clone, Copy, Default)]
33#[allow(clippy::exhaustive_structs)]
34pub struct IdentityServiceToken;
35
36impl AuthScheme for IdentityServiceToken {
37 type Input<'a> = &'a str;
38 type AddAuthenticationError = http::header::InvalidHeaderValue;
39 type Output = String;
41 type ExtractAuthenticationError = ExtractTokenError;
42
43 fn add_authentication<T: AsRef<[u8]>>(
44 request: &mut http::Request<T>,
45 access_token: Self::Input<'_>,
46 ) -> Result<(), Self::AddAuthenticationError> {
47 add_access_token_as_authorization_header(request.headers_mut(), access_token)
48 }
49
50 fn extract_authentication<T>(
51 request: &http::Request<T>,
52 ) -> Result<Self::Output, Self::ExtractAuthenticationError> {
53 extract_bearer_or_query_token(request)?.ok_or(ExtractTokenError::MissingAccessToken)
54 }
55}