Skip to main content

OperatorAuth

Struct OperatorAuth 

Source
pub struct OperatorAuth {
    operator_did: String,
    session_ttl: Duration,
    client: OAuthClient<Resolver, MemoryAuthStore>,
    sessions: Mutex<HashMap<String, Session>>,
    pending: Mutex<HashMap<String, (Option<String>, Instant)>>,
}
Expand description

The operator sign-in for one deployment.

Fields§

§operator_did: String§session_ttl: Duration§client: OAuthClient<Resolver, MemoryAuthStore>§sessions: Mutex<HashMap<String, Session>>§pending: Mutex<HashMap<String, (Option<String>, Instant)>>

Sign-ins started but not yet come back, keyed by the state this server chose. The value is where to send the browser afterwards — None for the dashboard’s own flow, and a loopback URL for a CLI waiting on one. See Self::start.

Implementations§

Source§

impl OperatorAuth

Source

pub fn new( operator_did: impl Into<String>, base_url: &str, session_ttl: Duration, ) -> Result<Arc<Self>, String>

Builds the sign-in for operator_did, publishing client metadata at base_url + CLIENT_METADATA_PATH.

base_url is this deployment’s own public origin, with no trailing slash — the authorization server fetches the metadata document from it and checks the redirect against it, so it has to be the address a browser actually reached.

Source

pub fn operator_did(&self) -> &str

The DID this deployment will accept a sign-in from, and nobody else.

Source

pub fn session_ttl(&self) -> Duration

How long a session this issues stays good for.

Source

pub fn client_metadata_document(&self) -> Result<Value, String>

The client metadata document, as the JSON served at CLIENT_METADATA_PATH.

Source

pub async fn start( &self, cli_redirect: Option<&str>, ) -> Result<String, SignInError>

Resolves this deployment’s operator and returns the URL to send the browser to.

The identity is the one --operator names and no other, so no caller picks the host this server resolves and pushes an authorization request to. What is checked at the far end is still the sub that comes back.

cli_redirect is where to send the browser once the sign-in lands, for a command-line caller waiting on a loopback address. It is refused unless it is loopback: this server would otherwise bounce a browser anywhere a link asked it to, carrying a freshly minted operator session.

Source

pub async fn finish( &self, params: CallbackParams, ) -> Result<SignedIn, SignInError>

Completes the redirect and, if it authenticated the operator, mints a session. Returns the session token and its CSRF token.

The OAuth session itself is dropped here: this server wanted the sub and has it.

Source

pub(crate) fn mint(&self) -> SignedIn

Issues a session for a caller already established as the operator.

pub(crate) and no wider: this is the one call that hands out an operator session without authenticating anybody, so the only callers are Self::finish, which has just checked the sub, and tests: the dashboard’s own, and Self::mint_for_tests’s.

Source

pub fn mint_for_tests(&self) -> SignedIn

A session as if the operator had just signed in, for a test standing a server up with no authorization server to sign in through.

Source

pub fn lookup(&self, token: &str) -> Option<String>

Whether token is a live session, and if so what CSRF token it expects. A read may stop here; see Self::authorize.

Source

pub fn authorize(&self, token: &str, presented_csrf: Option<&str>) -> bool

Whether token may perform a mutating operator action.

A cookie is sent by the browser on a request another origin caused, so a live session is necessary and not sufficient: a request that changes something must also echo the session’s own CSRF token, which only a page served from this origin can have read.

Source

pub fn sign_out(&self, token: &str)

Ends one session.

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

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
§

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, 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,