Struct AuthClient

Source
pub struct AuthClient { /* private fields */ }
Expand description

C3A Authentication & Authorization Client.

Implementations§

Source§

impl AuthClient

Source

pub async fn new( app_name: impl ToString, app_keypair: SignKeypair, authnz_base_url: impl ToString, ) -> MResult<Self>

Create C3A client.

This method ensures that C3A server is alive by health check.

Changes default cookie names.

Source

pub fn change_challenge_header_names(&mut self, new_names: [&'static str; 3])

Changes default challenge header names.

Source

pub async fn get_config(&mut self) -> MResult<AppAuthConfiguration>

Checks if the application exists in C3A server and returns application config.

Source

pub async fn app_register( &self, invite: Invite, config: AppAuthConfiguration, ) -> MResult<()>

Registers the application with given invite code and config.

Source

pub async fn update_config( &mut self, actual_config: &AppAuthConfiguration, ) -> MResult<()>

Edits appliaction config.

Source

pub async fn force_register_user( &self, user_id: Id, flows: Vec<Vec<AdminAuthenticationStep>>, tags: &[impl Into<AccessTag> + Clone], ) -> MResult<()>

Registers an account without authentication flow approvals.

Source§

impl AuthClient

Source

pub async fn prepare_sign_up( &self, login: Id, ) -> MResult<(PreregistrationRequirementsResponse, String)>

Prepares a user registration and returns requirements and registration state.

For successful registration you should provide given registration state in perform_sign_up method.

Source

pub async fn perform_sign_up( &self, login: Id, state: String, authentication_flows: AuthenticationFlows, cli_pkey: Option<Vec<u8>>, cba_challenge_sign: Option<CBAChallengeSign>, ) -> MResult<TokenBundle>

Performs a user registration with given registration state and returns token triple for authorization.

Source

pub async fn prepare_login(&self, login: Id) -> MResult<PrefetchLoginResponse>

Prepares a user authentication and returns login requirements.

Source

pub async fn perform_login( &self, login: Id, authentication_flow: AuthenticationFlow, cli_pkey: Option<Vec<u8>>, cba_challenge_sign: Option<CBAChallengeSign>, ) -> MResult<TokenBundle>

Performs a user authentication and returns token triple for authorization.

Source

pub async fn check_user_exists(&self, user_id: Id) -> MResult<()>

Checks if the user exists.

Source

pub async fn get_user_tags(&self, user_id: Id) -> MResult<Vec<AccessTag>>

Gets user tags.

Source

pub async fn edit_user_tags( &self, user_id: Id, add_tags: &[AccessTag], remove_tags: &[AccessTag], ) -> MResult<()>

Edits user tags.

Source

pub async fn delete_user(&self, user_id: Id) -> MResult<()>

Deletes the user.

Source

pub async fn authorize( &self, tokens: TokenBundle, cba_challenge_state: Option<String>, cba_challenge_sign: Option<CBAChallengeSign>, tags: &[impl Into<AccessTag> + Clone], ) -> MResult<(UserAuthorizeResponse, Option<String>)>

Authorizes a user by given token triple for given tags.

Source

pub async fn request_cba_update( &self, tokens: TokenBundle, cba_challenge_state: Option<String>, cba_challenge_sign: Option<CBAChallengeSign>, ) -> MResult<(CBAUpdateResponse, Option<String>)>

Requests an update for client-based authorization token.

This method is intended to be run twice:

  1. You should get cba_challenge in CBAUpdateResponse and the signed lmpaat_cba_challenge to store at client side.
  2. You should set lmpaat_cba_challenge and provide cba_challenge_sign from the client.

For successful update client should sign the challenge with the same private key which public part is stored at triple.

Source

pub async fn perform_logout(&self, bundle: TokenBundle) -> MResult<()>

Logs a user out by his tokens.

Source§

impl AuthClient

Source

pub fn lifetimes(&self) -> TokenLifetimes

Returns token lifetimes.

Source

pub async fn check_signed_in( &self, req: &mut Request, res: &mut Response, ) -> MResult<ApplicationAuthorizeResponse>

Just checks if a user is authenticated.

Source

pub async fn check_authorized_to( &self, req: &mut Request, res: &mut Response, tags: &[impl Into<AccessTag> + Clone], ) -> MResult<ApplicationAuthorizeResponse>

Checks if a user is authorized to given action tags.

Source

pub async fn update_client_token( &self, req: &mut Request, res: &mut Response, ) -> MResult<OK>

Forces to update client token.

Source

pub async fn logout(&self, req: &mut Request, res: &mut Response) -> MResult<()>

Requests a logout.

After this, refresh token is no longer available, and access token stays alive up to 15 minutes.

Source

pub fn deploy_triple_to_cookies( &self, bundle: &TokenBundle, res: &mut Response, ) -> MResult<()>

This method sets up token triple to cookies.

Trait Implementations§

Source§

impl Clone for AuthClient

Source§

fn clone(&self) -> AuthClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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,