Add GetByAuthorization trait
This trait provides a seam to fetch arbitrary values based on an
Authorization.
@@ -22,6 +22,8 @@ pub mod github;
use std::str::FromStr;
+use crate::error::InternalError;
+
pub use error::{AuthorizationParseError, IdentityProviderError};
/// A service that fetches identities from a backing provider
@@ -48,6 +50,12 @@ impl Clone for Box<dyn IdentityProvider> {
}
}
+/// A trait that fetches a value based on an Authorization.
+pub trait GetByAuthorization<T> {
+ /// Return a value based on the given authorization value.
+ fn get(&self, authorization: &Authorization) -> Result<Option<T>, InternalError>;
+}
+
/// The authorization that is passed to an `IdentityProvider`
pub enum Authorization {
Bearer(BearerToken),
