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
Implement Clone on ClientCredentials
This commit is contained in:
committed by
Quentin Gliech
parent
2171265dcd
commit
0c08e50846
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
//! Types and methods for client credentials.
|
//! Types and methods for client credentials.
|
||||||
|
|
||||||
use std::{collections::HashMap, fmt};
|
use std::{collections::HashMap, fmt, sync::Arc};
|
||||||
|
|
||||||
use base64ct::{Base64UrlUnpadded, Encoding};
|
use base64ct::{Base64UrlUnpadded, Encoding};
|
||||||
use chrono::{DateTime, Duration, Utc};
|
use chrono::{DateTime, Duration, Utc};
|
||||||
@ -56,13 +56,14 @@ pub type JwtSigningFn =
|
|||||||
dyn Fn(HashMap<String, Value>, JsonWebSignatureAlg) -> Result<String, BoxError> + Send + Sync;
|
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(Box<JwtSigningFn>),
|
Custom(Arc<JwtSigningFn>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JwtSigningMethod {
|
impl JwtSigningMethod {
|
||||||
@ -82,7 +83,7 @@ impl JwtSigningMethod {
|
|||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
{
|
{
|
||||||
Self::Custom(Box::new(signing_fn))
|
Self::Custom(Arc::new(signing_fn))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the [`Keystore`] from this [`JwtSigningMethod`].
|
/// Get the [`Keystore`] from this [`JwtSigningMethod`].
|
||||||
@ -99,7 +100,7 @@ impl JwtSigningMethod {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn jwt_custom(&self) -> Option<&JwtSigningFn> {
|
pub fn jwt_custom(&self) -> Option<&JwtSigningFn> {
|
||||||
match self {
|
match self {
|
||||||
JwtSigningMethod::Custom(s) => Some(s),
|
JwtSigningMethod::Custom(s) => Some(s.as_ref()),
|
||||||
JwtSigningMethod::Keystore(_) => None,
|
JwtSigningMethod::Keystore(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user