Struct AuthenticationService

Source
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 ed25519_compact::KeyPair;
use jwt_compact::{alg::Ed25519};

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

let KeyPair {
    pk: public_key,
    sk: secret_key,
} = KeyPair::generate();

let authority = Authority::<User, _, _, _>::new()
    .refresh_authorizer(|| async move { Ok(()) })
    .token_signer(Some(
        TokenSigner::new()
            .signing_key(secret_key)
            .algorithm(Ed25519)
            .build()
            .unwrap()
    ))
    .verifying_key(public_key)
    .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 = Error> + 'static, Claims: Serialize + DeserializeOwned + 'static, Algo: Algorithm + Clone + 'static, Algo::SigningKey: Clone, Body: MessageBody, ReAuth: Handler<Args, Output = Result<(), Error>>, Args: FromRequest + 'static,

Source§

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

Responses produced by the service.
Source§

type Error = Error

Errors produced by the service.
Source§

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

The TransformService value created by this factory
Source§

type InitError = ()

Errors produced while building a transform service.
Source§

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> Freeze for AuthenticationService<Claims, Algo, ReAuth, Args>
where <Algo as Algorithm>::SigningKey: Sized,

§

impl<Claims, Algo, ReAuth, Args> RefUnwindSafe for AuthenticationService<Claims, Algo, ReAuth, Args>

§

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

§

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

§

impl<Claims, Algo, ReAuth, Args> Unpin for AuthenticationService<Claims, Algo, ReAuth, Args>
where <Algo as Algorithm>::SigningKey: Sized, Claims: Unpin,

§

impl<Claims, Algo, ReAuth, Args> UnwindSafe for AuthenticationService<Claims, Algo, ReAuth, Args>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

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 T
where U: From<T>,

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 for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,