You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-31 09:24:31 +03:00
Revert "Implement Clone on ClientCredentials"
This reverts commit 1f3fe4fdbc
.
This commit is contained in:
committed by
Quentin Gliech
parent
d0c5eb3741
commit
2171265dcd
@ -52,17 +52,17 @@ pub const CLIENT_SUPPORTED_AUTH_METHODS: &[OAuthClientAuthenticationMethod] = &[
|
|||||||
|
|
||||||
/// A function that takes a map of claims and a signing algorithm and returns a
|
/// A function that takes a map of claims and a signing algorithm and returns a
|
||||||
/// signed JWT.
|
/// signed JWT.
|
||||||
pub type JwtSigningFn = fn(HashMap<String, Value>, JsonWebSignatureAlg) -> Result<String, BoxError>;
|
pub type JwtSigningFn =
|
||||||
|
dyn Fn(HashMap<String, Value>, JsonWebSignatureAlg) -> Result<String, BoxError> + Send + Sync;
|
||||||
|
|
||||||
/// The method used to sign JWTs with a private key.
|
/// The method used to sign JWTs with a private key.
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum JwtSigningMethod {
|
pub enum JwtSigningMethod {
|
||||||
/// Sign the JWTs with this library, by providing the signing keys.
|
/// Sign the JWTs with this library, by providing the signing keys.
|
||||||
#[cfg(feature = "keystore")]
|
#[cfg(feature = "keystore")]
|
||||||
Keystore(Keystore),
|
Keystore(Keystore),
|
||||||
|
|
||||||
/// Sign the JWTs in a callback.
|
/// Sign the JWTs in a callback.
|
||||||
Custom(JwtSigningFn),
|
Custom(Box<JwtSigningFn>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JwtSigningMethod {
|
impl JwtSigningMethod {
|
||||||
@ -75,8 +75,14 @@ impl JwtSigningMethod {
|
|||||||
|
|
||||||
/// Creates a new [`JwtSigningMethod`] from a [`JwtSigningFn`].
|
/// Creates a new [`JwtSigningMethod`] from a [`JwtSigningFn`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_custom_signing_method(signing_fn: JwtSigningFn) -> Self {
|
pub fn with_custom_signing_method<F>(signing_fn: F) -> Self
|
||||||
Self::Custom(signing_fn)
|
where
|
||||||
|
F: Fn(HashMap<String, Value>, JsonWebSignatureAlg) -> Result<String, BoxError>
|
||||||
|
+ Send
|
||||||
|
+ Sync
|
||||||
|
+ 'static,
|
||||||
|
{
|
||||||
|
Self::Custom(Box::new(signing_fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the [`Keystore`] from this [`JwtSigningMethod`].
|
/// Get the [`Keystore`] from this [`JwtSigningMethod`].
|
||||||
@ -101,7 +107,6 @@ impl JwtSigningMethod {
|
|||||||
|
|
||||||
/// The credentials obtained during registration, to authenticate a client on
|
/// The credentials obtained during registration, to authenticate a client on
|
||||||
/// endpoints that require it.
|
/// endpoints that require it.
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum ClientCredentials {
|
pub enum ClientCredentials {
|
||||||
/// No client authentication is used.
|
/// No client authentication is used.
|
||||||
///
|
///
|
||||||
|
@ -130,7 +130,7 @@ fn id_token(issuer: &str) -> (IdToken, PublicJsonWebKeySet) {
|
|||||||
fn client_credentials(
|
fn client_credentials(
|
||||||
auth_method: OAuthClientAuthenticationMethod,
|
auth_method: OAuthClientAuthenticationMethod,
|
||||||
issuer: &Url,
|
issuer: &Url,
|
||||||
custom_signing: Option<JwtSigningFn>,
|
custom_signing: Option<Box<JwtSigningFn>>,
|
||||||
) -> ClientCredentials {
|
) -> ClientCredentials {
|
||||||
match auth_method {
|
match auth_method {
|
||||||
OAuthClientAuthenticationMethod::None => ClientCredentials::None {
|
OAuthClientAuthenticationMethod::None => ClientCredentials::None {
|
||||||
|
@ -372,7 +372,7 @@ async fn pass_private_key_jwt_with_custom_signing() {
|
|||||||
let client_credentials = client_credentials(
|
let client_credentials = client_credentials(
|
||||||
OAuthClientAuthenticationMethod::PrivateKeyJwt,
|
OAuthClientAuthenticationMethod::PrivateKeyJwt,
|
||||||
&issuer,
|
&issuer,
|
||||||
Some(|_claims, _alg| Ok("fake.signed.jwt".to_owned())),
|
Some(Box::new(|_claims, _alg| Ok("fake.signed.jwt".to_owned()))),
|
||||||
);
|
);
|
||||||
let token_endpoint = issuer.join("token").unwrap();
|
let token_endpoint = issuer.join("token").unwrap();
|
||||||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(42);
|
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(42);
|
||||||
@ -441,7 +441,7 @@ async fn fail_private_key_jwt_with_custom_signing() {
|
|||||||
let client_credentials = client_credentials(
|
let client_credentials = client_credentials(
|
||||||
OAuthClientAuthenticationMethod::PrivateKeyJwt,
|
OAuthClientAuthenticationMethod::PrivateKeyJwt,
|
||||||
&issuer,
|
&issuer,
|
||||||
Some(|_claims, _alg| Err("Something went wrong".into())),
|
Some(Box::new(|_claims, _alg| Err("Something went wrong".into()))),
|
||||||
);
|
);
|
||||||
let token_endpoint = issuer.join("token").unwrap();
|
let token_endpoint = issuer.join("token").unwrap();
|
||||||
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(42);
|
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(42);
|
||||||
|
Reference in New Issue
Block a user