pub struct JwtAuthenticator { /* private fields */ }Expand description
Verifies an OIDC/JWT bearer against an injected JWKS and maps its claims to a
Principal.
Build it from the keys and the expected issuer/audience, then (optionally) point it at the claims that carry the tenant and permissions:
use jsonwebtoken::jwk::JwkSet;
use seiva_identity::JwtAuthenticator;
let auth = JwtAuthenticator::new(jwks, "https://id.example.com/", "seiva-api")
.with_tenant_claim("org_id");Implementations§
Source§impl JwtAuthenticator
impl JwtAuthenticator
Sourcepub fn new(
jwks: JwkSet,
issuer: impl Into<String>,
audience: impl Into<String>,
) -> JwtAuthenticator
pub fn new( jwks: JwkSet, issuer: impl Into<String>, audience: impl Into<String>, ) -> JwtAuthenticator
A verifier for tokens minted by issuer for audience, trusting the keys
in jwks. Algorithms are fixed to RS256 and ES256; exp and nbf are
validated.
Sourcepub fn from_jwks_json(
jwks_json: &str,
issuer: impl Into<String>,
audience: impl Into<String>,
) -> Result<JwtAuthenticator, Error>
pub fn from_jwks_json( jwks_json: &str, issuer: impl Into<String>, audience: impl Into<String>, ) -> Result<JwtAuthenticator, Error>
Builds a verifier from the JWKS as a JSON string (the body of a
jwks_uri, or a file a deployment ships), so a caller need not depend on
jsonwebtoken to parse the key set.
§Errors
Returns the serde_json::Error if jwks_json is not a valid JWKS.
Sourcepub fn with_tenant_claim(self, claim: impl Into<String>) -> JwtAuthenticator
pub fn with_tenant_claim(self, claim: impl Into<String>) -> JwtAuthenticator
Read the tenant from a different claim (default DEFAULT_TENANT_CLAIM).
Sourcepub fn with_permission_claim(self, claim: impl Into<String>) -> JwtAuthenticator
pub fn with_permission_claim(self, claim: impl Into<String>) -> JwtAuthenticator
Read the permissions from a different claim (default
DEFAULT_PERMISSION_CLAIM); a space-delimited scope is the fallback.