pub struct AuthInterceptor { /* private fields */ }Expand description
Adds authorization: Bearer <token> (and x-app-name) to every request.
The authorization value is marked sensitive, so tonic does not print it in debug output. One
interceptor serves one token. TbankClient builds it from the config, build it yourself only
when you wrap your own channel.
§Examples
use brokapi_tbank_protocol::AuthInterceptor;
use tonic::service::Interceptor;
let mut auth = AuthInterceptor::new("t.my-token", Some("me.my-robot"))?;
let request = auth.call(tonic::Request::new(())).expect("the interceptor never refuses");
assert_eq!(request.metadata().get("authorization").unwrap(), "Bearer t.my-token");
assert_eq!(request.metadata().get("x-app-name").unwrap(), "me.my-robot");
// A token a header cannot carry is a configuration error, not a panic.
assert!(AuthInterceptor::new("line\nbreak", None).is_err());Implementations§
Source§impl AuthInterceptor
impl AuthInterceptor
Sourcepub fn new(token: &str, app_name: Option<&str>) -> Result<Self, ProtocolError>
pub fn new(token: &str, app_name: Option<&str>) -> Result<Self, ProtocolError>
Prepares the headers for token and the optional app_name.
app_name becomes the x-app-name header (the T-Bank convention is <github nick>.<repo>).
§Errors
ProtocolError::Config when the token or the app name contains characters a header value
cannot carry (control characters such as a line break). The message does not repeat the token.
Trait Implementations§
Source§impl Clone for AuthInterceptor
impl Clone for AuthInterceptor
Source§fn clone(&self) -> AuthInterceptor
fn clone(&self) -> AuthInterceptor
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Freeze for AuthInterceptor
impl RefUnwindSafe for AuthInterceptor
impl Send for AuthInterceptor
impl Sync for AuthInterceptor
impl Unpin for AuthInterceptor
impl UnsafeUnpin for AuthInterceptor
impl UnwindSafe for AuthInterceptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].