pub struct AuthenticationService<Claims, Algo, ReAuth, Args>where
    Algo: Algorithm + Clone,
    Algo::SigningKey: Clone,{ /* private fields */ }
Expand description

A wrapper around the Authority which can be passed to the wrap function of a App/Scope or Resource.

Example

use actix_jwt_auth_middleware::{TokenSigner, Authority, AuthenticationService};
use actix_web::{web, App};
use serde::{Serialize, Deserialize};
use exonum_crypto::KeyPair;
use jwt_compact::{alg::Ed25519};

#[derive(Serialize, Deserialize, Clone)]
struct User {
    id: u32
}

let key_pair = KeyPair::random();

let authority = Authority::<User, _, _, _>::new()
    .refresh_authorizer(|| async move { Ok(()) })
    .token_signer(Some(
        TokenSigner::new()
            .signing_key(key_pair.secret_key().clone())
            .algorithm(Ed25519)
            .build()
            .unwrap()
    ))
    .verifying_key(key_pair.public_key().clone())
    .build()
    .unwrap();

let app = App::new()
    .service(
        web::scope("/auth-only")
            .wrap(
                AuthenticationService::new(authority.clone())
            )
     );

Implementations§

source§

impl<Claims, Algo, ReAuth, Args> AuthenticationService<Claims, Algo, ReAuth, Args>where Claims: DeserializeOwned, Algo: Algorithm + Clone, Algo::SigningKey: Clone,

source

pub fn new( authority: Authority<Claims, Algo, ReAuth, Args> ) -> AuthenticationService<Claims, Algo, ReAuth, Args>

returns a new AuthenticationService wrapping the Authority

Trait Implementations§

source§

impl<S, Body, Claims, Algo, ReAuth, Args> Transform<S, ServiceRequest> for AuthenticationService<Claims, Algo, ReAuth, Args>where S: Service<ServiceRequest, Response = ServiceResponse<Body>, Error = ActixWebError> + 'static, Claims: Serialize + DeserializeOwned + 'static, Algo: Algorithm + Clone + 'static, Algo::SigningKey: Clone, Body: MessageBody, ReAuth: Handler<Args, Output = Result<(), ActixWebError>>, Args: FromRequest + 'static,

§

type Response = <AuthenticationMiddleware<S, Claims, Algo, ReAuth, Args> as Service<ServiceRequest>>::Response

Responses produced by the service.
§

type Error = Error

Errors produced by the service.
§

type Transform = AuthenticationMiddleware<S, Claims, Algo, ReAuth, Args>

The TransformService value created by this factory
§

type InitError = ()

Errors produced while building a transform service.
§

type Future = Ready<Result<<AuthenticationService<Claims, Algo, ReAuth, Args> as Transform<S, ServiceRequest>>::Transform, <AuthenticationService<Claims, Algo, ReAuth, Args> as Transform<S, ServiceRequest>>::InitError>>

The future response value.
source§

fn new_transform(&self, service: S) -> Self::Future

Creates and returns a new Transform component, asynchronously

Auto Trait Implementations§

§

impl<Claims, Algo, ReAuth, Args> RefUnwindSafe for AuthenticationService<Claims, Algo, ReAuth, Args>where Algo: RefUnwindSafe, Args: RefUnwindSafe, Claims: RefUnwindSafe, ReAuth: RefUnwindSafe, <Algo as Algorithm>::SigningKey: RefUnwindSafe, <Algo as Algorithm>::VerifyingKey: RefUnwindSafe,

§

impl<Claims, Algo, ReAuth, Args> Send for AuthenticationService<Claims, Algo, ReAuth, Args>where Algo: Send + Sync, Args: Send + Sync, Claims: Send + Sync, ReAuth: Send + Sync, <Algo as Algorithm>::SigningKey: Send + Sync, <Algo as Algorithm>::VerifyingKey: Send + Sync,

§

impl<Claims, Algo, ReAuth, Args> Sync for AuthenticationService<Claims, Algo, ReAuth, Args>where Algo: Send + Sync, Args: Send + Sync, Claims: Send + Sync, ReAuth: Send + Sync, <Algo as Algorithm>::SigningKey: Send + Sync, <Algo as Algorithm>::VerifyingKey: Send + Sync,

§

impl<Claims, Algo, ReAuth, Args> Unpin for AuthenticationService<Claims, Algo, ReAuth, Args>where Claims: Unpin,

§

impl<Claims, Algo, ReAuth, Args> UnwindSafe for AuthenticationService<Claims, Algo, ReAuth, Args>where Algo: RefUnwindSafe, Args: RefUnwindSafe, Claims: UnwindSafe + RefUnwindSafe, ReAuth: RefUnwindSafe, <Algo as Algorithm>::SigningKey: RefUnwindSafe, <Algo as Algorithm>::VerifyingKey: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more