Skip to main content

GnapService

Struct GnapService 

Source
pub struct GnapService { /* private fields */ }

Implementations§

Source§

impl GnapService

Source

pub fn new(config: GnapConfig) -> Self

Source

pub fn with_access_policy(self, policy: Arc<dyn GnapAccessPolicy>) -> Self

Set the policy that decides what access tokens carry. Without one, every request for an access token is denied.

Source

pub fn verify_jwk_signature( jwk: &GnapJwk, message: &[u8], signature: &[u8], ) -> Result<()>

Reconstruct the raw public key bytes from a JWK and verify a signature using ring. Supports ES256 (P-256) and RS256.

This is called by middleware or application code that extracts the HTTP message signature from the request before invoking the GNAP transaction endpoints.

Source

pub fn validate_client_key_with_proof( client: &Option<GnapClientInfo>, proof_message: Option<&[u8]>, proof_signature: Option<&[u8]>, ) -> Result<Option<String>>

Validate the client key binding on a request. Returns the key thumbprint if a key is present and valid.

When proof_message and proof_signature are provided, the actual cryptographic signature is verified against the client’s JWK. For proof methods other than “test”, the caller (typically HTTP middleware) must extract and supply the message and signature bytes from the request (e.g. the HTTP Signature input string and its signature value).

Source

pub async fn handle_transaction_with_proof( &self, dpop: &DpopManager, proof: &GnapProof<'_>, request: GnapTransactionRequest, ) -> Result<Value>

Handle a new GNAP transaction request (RFC 9635 section 2). The request must name a client key with the dpop proof method, and proof carries the request’s DPoP header, which must be signed by that key. A request that names no client key is refused, and no access token is issued unless the service has an access policy that grants something.

Source

pub async fn continue_transaction_with_proof( &self, dpop: &DpopManager, proof: &GnapProof<'_>, transaction_id: &str, continue_token: &str, interact_ref: Option<&str>, interact_hash: Option<&str>, ) -> Result<Value>

Continue a GNAP transaction (polling or post-interaction), RFC 9635 section 5.

The continuation request must carry a DPoP proof signed by the transaction’s client key. A transaction that uses a finish method continues only with the one-time interact_ref that Self::approve_transaction returned. The continuation token is rotated on every successful call, preventing replay of old continuation responses.

Source

pub async fn approve_transaction( &self, transaction_id: &str, subject_id: Option<&str>, ) -> Result<GnapInteractionCompletion>

Approve a pending transaction (called after user interaction). Optionally sets the subject identifier for subject-info responses.

For a transaction that uses a finish method this issues the one-time interaction reference and its hash (RFC 9635 section 4.2); deliver both to the client’s finish URI.

Source

pub async fn deny_transaction(&self, transaction_id: &str) -> Result<()>

Deny a pending transaction

Source

pub async fn revoke_token(&self, token_value: &str) -> Result<()>

Revoke an issued access token (draft §6.2 — DELETE on manage URI).

Source

pub async fn rotate_token(&self, old_token_value: &str) -> Result<Value>

Rotate an issued access token (draft §6.1 — POST on manage URI). Returns a new token with the same access rights and key binding.

Source

pub async fn introspect_token(&self, token_value: &str) -> Result<Option<Value>>

Introspect a token — check if it is valid and return its access rights.

Source

pub async fn validate_token_key_binding( &self, token_value: &str, presenting_jwk: &GnapJwk, ) -> Result<bool>

Validate that a key-bound token is being used with the correct key.

For tokens issued with a client key binding, verify that the presenting client’s JWK thumbprint matches the stored binding. Returns Ok(true) if the token is not key-bound (no restriction).

Source

pub async fn cleanup_expired_transactions(&self)

Remove expired transactions from the in-memory store.

Source

pub async fn cleanup_expired_tokens(&self)

Remove expired access tokens from the in-memory store.

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

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

Source§

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

Source§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

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

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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