//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `auth/authenticate`. Version: `0.2`.
#![allow(deprecated)]
/// Why this specification version is deprecated (SPEC "Superseded and
/// Withdrawn Versions"), or `None` while it is current.
pub const DEPRECATION: Option<&str> = Some("superseded by auth/authenticate/0.3");
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The subject presents a previously-issued challenge along with the framework `proof` that binds the document to their VID. The proof IS the authentication. 0.2 adds the optional `sessionKey` member, a did:key VID the consumer binds to the created session so later documents in that session can be signed with it instead of the subject's own key.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
#[deprecated(note = "superseded by auth/authenticate/0.3")]
pub struct Payload {
///The exact challenge value returned by a prior auth/challenge call. Consumers MUST reject mismatch, expired, or re-used challenges.
pub challenge: PayloadChallenge,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Optional capability tags the subject is requesting on the issued tokens. The consumer's authorization layer decides which are granted; the issued TokenBundle's `scope` MAY be a subset.
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub scope: ::std::vec::Vec<PayloadScopeItem>,
///The sessionId returned alongside the challenge. Consumers use it to look up the server-side challenge binding.
#[serde(rename = "sessionId")]
pub session_id: PayloadSessionId,
///A did:key VID the producer asks the consumer to bind to the session this authenticate document creates. The producer MUST hold the corresponding private key and SHOULD keep it non-extractable (for example, a WebCrypto non-extractable key). Once bound, the consumer MUST accept a framework `proof` made by this key, with `proofPurpose: authentication`, as the subject — for this session only, bounded by the session's `expiresAt` and `acr`, and never where a specification requires an `assertionMethod` attestation (SPEC.md §7.2 item 10; see Security & Privacy). The consumer MAY refuse a key type it does not support with `auth/authenticate:sessionKeyUnsupported`. It sits inside `payload`, so the subject's own `authentication` proof on this document covers it — a party cannot bind a session key without signing for it.
#[serde(
rename = "sessionKey",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub session_key: ::std::option::Option<PayloadSessionKey>,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///The exact challenge value returned by a prior auth/challenge call. Consumers MUST reject mismatch, expired, or re-used challenges.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadChallenge(::std::string::String);
impl ::std::ops::Deref for PayloadChallenge {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadChallenge> for ::std::string::String {
fn from(value: PayloadChallenge) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadChallenge {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 16usize {
return Err("shorter than 16 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadChallenge {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadChallenge {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadChallenge {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadChallenge {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`PayloadScopeItem`
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadScopeItem(::std::string::String);
impl ::std::ops::Deref for PayloadScopeItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadScopeItem> for ::std::string::String {
fn from(value: PayloadScopeItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadScopeItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadScopeItem {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadScopeItem {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadScopeItem {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadScopeItem {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The sessionId returned alongside the challenge. Consumers use it to look up the server-side challenge binding.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadSessionId(::std::string::String);
impl ::std::ops::Deref for PayloadSessionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadSessionId> for ::std::string::String {
fn from(value: PayloadSessionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadSessionId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadSessionId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadSessionId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadSessionId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadSessionId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///A did:key VID the producer asks the consumer to bind to the session this authenticate document creates. The producer MUST hold the corresponding private key and SHOULD keep it non-extractable (for example, a WebCrypto non-extractable key). Once bound, the consumer MUST accept a framework `proof` made by this key, with `proofPurpose: authentication`, as the subject — for this session only, bounded by the session's `expiresAt` and `acr`, and never where a specification requires an `assertionMethod` attestation (SPEC.md §7.2 item 10; see Security & Privacy). The consumer MAY refuse a key type it does not support with `auth/authenticate:sessionKeyUnsupported`. It sits inside `payload`, so the subject's own `authentication` proof on this document covers it — a party cannot bind a session key without signing for it.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadSessionKey(::std::string::String);
impl ::std::ops::Deref for PayloadSessionKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadSessionKey> for ::std::string::String {
fn from(value: PayloadSessionKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadSessionKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^did:key:z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadSessionKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadSessionKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadSessionKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadSessionKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Issued by the auth service after verifying the proof on the authenticate document. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/authenticate/0.2#response.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
#[deprecated(note = "superseded by auth/authenticate/0.3")]
pub struct Response {
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The session the consumer has just created or refreshed for this subject. Carries `sessionKey` when the request bound one.
pub session: Session,
///Access + optional refresh tokens. Consumers MAY omit a refresh token when their policy doesn't support refresh.
pub tokens: TokenBundle,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///A logical authentication context bound to a subject. Producers and consumers exchange Session-shaped data in challenge issuance, authentication responses, and introspection (whoami).
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Session {
///Authentication Context Class Reference per [OIDC Core §2]. Profiles define their own values; the recommended set is "aal1" (single-factor DID auth), "aal2" (a second possession-or-biometric factor confirmed), and "aal3" (hardware-bound second factor).
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub acr: ::std::option::Option<::std::string::String>,
///Authentication Methods References per [RFC 8176]. Typical values: "did" (challenge-response), "passkey" (WebAuthn), "vta" (verifiable-trust agent approval). Multi-factor sessions list every method used.
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub amr: ::std::vec::Vec<SessionAmrItem>,
///ISO-8601 timestamp when the session ceases to be valid. Producers SHOULD refresh before this time; consumers MUST reject after.
#[serde(rename = "expiresAt")]
pub expires_at: ::chrono::DateTime<::chrono::offset::Utc>,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Opaque, server-chosen session identifier. Stable for the lifetime of the session. Consumers MUST treat the value as opaque; no structure is implied.
pub id: SessionId,
///ISO-8601 timestamp when the session was created.
#[serde(rename = "issuedAt")]
pub issued_at: ::chrono::DateTime<::chrono::offset::Utc>,
///The did:key VID bound to this session by auth/authenticate/0.2, when the producer registered one. Present here so introspection (auth/whoami, auth/sessions/list) can show the binding a client already holds; it is descriptive, not an additional grant — the binding, its scope and its lifetime are governed entirely by the auth/authenticate/0.2 specification that established it. Absent when the session was established without a session key, or by a specification version that does not carry one.
#[serde(
rename = "sessionKey",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub session_key: ::std::option::Option<SessionSessionKey>,
///The authenticated party's VID (typically a DID URL).
pub subject: SessionSubject,
}
impl Session {
pub fn builder() -> builder::Session {
Default::default()
}
}
///`SessionAmrItem`
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SessionAmrItem(::std::string::String);
impl ::std::ops::Deref for SessionAmrItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SessionAmrItem> for ::std::string::String {
fn from(value: SessionAmrItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for SessionAmrItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for SessionAmrItem {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for SessionAmrItem {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for SessionAmrItem {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for SessionAmrItem {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Opaque, server-chosen session identifier. Stable for the lifetime of the session. Consumers MUST treat the value as opaque; no structure is implied.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SessionId(::std::string::String);
impl ::std::ops::Deref for SessionId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SessionId> for ::std::string::String {
fn from(value: SessionId) -> Self {
value.0
}
}
impl ::std::str::FromStr for SessionId {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for SessionId {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for SessionId {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for SessionId {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for SessionId {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The did:key VID bound to this session by auth/authenticate/0.2, when the producer registered one. Present here so introspection (auth/whoami, auth/sessions/list) can show the binding a client already holds; it is descriptive, not an additional grant — the binding, its scope and its lifetime are governed entirely by the auth/authenticate/0.2 specification that established it. Absent when the session was established without a session key, or by a specification version that does not carry one.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SessionSessionKey(::std::string::String);
impl ::std::ops::Deref for SessionSessionKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SessionSessionKey> for ::std::string::String {
fn from(value: SessionSessionKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for SessionSessionKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 512usize {
return Err("longer than 512 characters".into());
}
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^did:key:z[1-9A-HJ-NP-Za-km-z]+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for SessionSessionKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for SessionSessionKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for SessionSessionKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for SessionSessionKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The authenticated party's VID (typically a DID URL).
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct SessionSubject(::std::string::String);
impl ::std::ops::Deref for SessionSubject {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<SessionSubject> for ::std::string::String {
fn from(value: SessionSubject) -> Self {
value.0
}
}
impl ::std::str::FromStr for SessionSubject {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for SessionSubject {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for SessionSubject {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for SessionSubject {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for SessionSubject {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///An access token (typically short-lived JWT) paired with an optional refresh token (typically long-lived opaque string). The shapes follow OAuth 2.0 (RFC 6749 §5.1) conventions but are not coupled to any particular OAuth profile.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct TokenBundle {
///Bearer-style access token. Consumers presenting this token to downstream services prove the holder of the original session. Format is consumer-defined — JWT is common, but opaque strings are also valid.
#[serde(rename = "accessToken")]
pub access_token: TokenBundleAccessToken,
///Seconds from issuance until the access token expires.
#[serde(rename = "expiresIn")]
pub expires_in: ::std::num::NonZeroU64,
///Ecosystem-defined extension members per SPEC.md §4.5.1.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Seconds from issuance until the refresh token expires, when one was issued.
#[serde(
rename = "refreshExpiresIn",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub refresh_expires_in: ::std::option::Option<::std::num::NonZeroU64>,
///Long-lived token redeemable via auth/refresh for a new access token. MAY be absent when the issuer does not support refresh.
#[serde(
rename = "refreshToken",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub refresh_token: ::std::option::Option<TokenBundleRefreshToken>,
///Capability tags effective on this token. Format is consumer-defined; the framework imposes no syntax.
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub scope: ::std::vec::Vec<TokenBundleScopeItem>,
///Token presentation scheme. Almost always "Bearer"; reserved for future schemes.
#[serde(rename = "tokenType")]
pub token_type: TokenBundleTokenType,
}
impl TokenBundle {
pub fn builder() -> builder::TokenBundle {
Default::default()
}
}
///Bearer-style access token. Consumers presenting this token to downstream services prove the holder of the original session. Format is consumer-defined — JWT is common, but opaque strings are also valid.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct TokenBundleAccessToken(::std::string::String);
impl ::std::ops::Deref for TokenBundleAccessToken {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<TokenBundleAccessToken> for ::std::string::String {
fn from(value: TokenBundleAccessToken) -> Self {
value.0
}
}
impl ::std::str::FromStr for TokenBundleAccessToken {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for TokenBundleAccessToken {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for TokenBundleAccessToken {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for TokenBundleAccessToken {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for TokenBundleAccessToken {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Long-lived token redeemable via auth/refresh for a new access token. MAY be absent when the issuer does not support refresh.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct TokenBundleRefreshToken(::std::string::String);
impl ::std::ops::Deref for TokenBundleRefreshToken {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<TokenBundleRefreshToken> for ::std::string::String {
fn from(value: TokenBundleRefreshToken) -> Self {
value.0
}
}
impl ::std::str::FromStr for TokenBundleRefreshToken {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for TokenBundleRefreshToken {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for TokenBundleRefreshToken {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for TokenBundleRefreshToken {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for TokenBundleRefreshToken {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`TokenBundleScopeItem`
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct TokenBundleScopeItem(::std::string::String);
impl ::std::ops::Deref for TokenBundleScopeItem {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<TokenBundleScopeItem> for ::std::string::String {
fn from(value: TokenBundleScopeItem) -> Self {
value.0
}
}
impl ::std::str::FromStr for TokenBundleScopeItem {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for TokenBundleScopeItem {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for TokenBundleScopeItem {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for TokenBundleScopeItem {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for TokenBundleScopeItem {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Token presentation scheme. Almost always "Bearer"; reserved for future schemes.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct TokenBundleTokenType(::std::string::String);
impl ::std::ops::Deref for TokenBundleTokenType {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<TokenBundleTokenType> for ::std::string::String {
fn from(value: TokenBundleTokenType) -> Self {
value.0
}
}
impl ::std::str::FromStr for TokenBundleTokenType {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for TokenBundleTokenType {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for TokenBundleTokenType {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for TokenBundleTokenType {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for TokenBundleTokenType {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct Payload {
challenge: ::std::result::Result<super::PayloadChallenge, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
scope:
::std::result::Result<::std::vec::Vec<super::PayloadScopeItem>, ::std::string::String>,
session_id: ::std::result::Result<super::PayloadSessionId, ::std::string::String>,
session_key: ::std::result::Result<
::std::option::Option<super::PayloadSessionKey>,
::std::string::String,
>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
challenge: Err("no value supplied for challenge".to_string()),
ext: Ok(Default::default()),
scope: Ok(Default::default()),
session_id: Err("no value supplied for session_id".to_string()),
session_key: Ok(Default::default()),
}
}
}
impl Payload {
pub fn challenge<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadChallenge>,
T::Error: ::std::fmt::Display,
{
self.challenge = value
.try_into()
.map_err(|e| format!("error converting supplied value for challenge: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn scope<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::PayloadScopeItem>>,
T::Error: ::std::fmt::Display,
{
self.scope = value
.try_into()
.map_err(|e| format!("error converting supplied value for scope: {e}"));
self
}
pub fn session_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::PayloadSessionId>,
T::Error: ::std::fmt::Display,
{
self.session_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for session_id: {e}"));
self
}
pub fn session_key<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadSessionKey>>,
T::Error: ::std::fmt::Display,
{
self.session_key = value
.try_into()
.map_err(|e| format!("error converting supplied value for session_key: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
challenge: value.challenge?,
ext: value.ext?,
scope: value.scope?,
session_id: value.session_id?,
session_key: value.session_key?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
challenge: Ok(value.challenge),
ext: Ok(value.ext),
scope: Ok(value.scope),
session_id: Ok(value.session_id),
session_key: Ok(value.session_key),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
session: ::std::result::Result<super::Session, ::std::string::String>,
tokens: ::std::result::Result<super::TokenBundle, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
session: Err("no value supplied for session".to_string()),
tokens: Err("no value supplied for tokens".to_string()),
}
}
}
impl Response {
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn session<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Session>,
T::Error: ::std::fmt::Display,
{
self.session = value
.try_into()
.map_err(|e| format!("error converting supplied value for session: {e}"));
self
}
pub fn tokens<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TokenBundle>,
T::Error: ::std::fmt::Display,
{
self.tokens = value
.try_into()
.map_err(|e| format!("error converting supplied value for tokens: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
ext: value.ext?,
session: value.session?,
tokens: value.tokens?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
session: Ok(value.session),
tokens: Ok(value.tokens),
}
}
}
#[derive(Clone, Debug)]
pub struct Session {
acr: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
amr: ::std::result::Result<::std::vec::Vec<super::SessionAmrItem>, ::std::string::String>,
expires_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
id: ::std::result::Result<super::SessionId, ::std::string::String>,
issued_at:
::std::result::Result<::chrono::DateTime<::chrono::offset::Utc>, ::std::string::String>,
session_key: ::std::result::Result<
::std::option::Option<super::SessionSessionKey>,
::std::string::String,
>,
subject: ::std::result::Result<super::SessionSubject, ::std::string::String>,
}
impl ::std::default::Default for Session {
fn default() -> Self {
Self {
acr: Ok(Default::default()),
amr: Ok(Default::default()),
expires_at: Err("no value supplied for expires_at".to_string()),
ext: Ok(Default::default()),
id: Err("no value supplied for id".to_string()),
issued_at: Err("no value supplied for issued_at".to_string()),
session_key: Ok(Default::default()),
subject: Err("no value supplied for subject".to_string()),
}
}
}
impl Session {
pub fn acr<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.acr = value
.try_into()
.map_err(|e| format!("error converting supplied value for acr: {e}"));
self
}
pub fn amr<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::SessionAmrItem>>,
T::Error: ::std::fmt::Display,
{
self.amr = value
.try_into()
.map_err(|e| format!("error converting supplied value for amr: {e}"));
self
}
pub fn expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.expires_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for expires_at: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SessionId>,
T::Error: ::std::fmt::Display,
{
self.id = value
.try_into()
.map_err(|e| format!("error converting supplied value for id: {e}"));
self
}
pub fn issued_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
T::Error: ::std::fmt::Display,
{
self.issued_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for issued_at: {e}"));
self
}
pub fn session_key<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::SessionSessionKey>>,
T::Error: ::std::fmt::Display,
{
self.session_key = value
.try_into()
.map_err(|e| format!("error converting supplied value for session_key: {e}"));
self
}
pub fn subject<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::SessionSubject>,
T::Error: ::std::fmt::Display,
{
self.subject = value
.try_into()
.map_err(|e| format!("error converting supplied value for subject: {e}"));
self
}
}
impl ::std::convert::TryFrom<Session> for super::Session {
type Error = super::error::ConversionError;
fn try_from(value: Session) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
acr: value.acr?,
amr: value.amr?,
expires_at: value.expires_at?,
ext: value.ext?,
id: value.id?,
issued_at: value.issued_at?,
session_key: value.session_key?,
subject: value.subject?,
})
}
}
impl ::std::convert::From<super::Session> for Session {
fn from(value: super::Session) -> Self {
Self {
acr: Ok(value.acr),
amr: Ok(value.amr),
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
id: Ok(value.id),
issued_at: Ok(value.issued_at),
session_key: Ok(value.session_key),
subject: Ok(value.subject),
}
}
}
#[derive(Clone, Debug)]
pub struct TokenBundle {
access_token: ::std::result::Result<super::TokenBundleAccessToken, ::std::string::String>,
expires_in: ::std::result::Result<::std::num::NonZeroU64, ::std::string::String>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
refresh_expires_in: ::std::result::Result<
::std::option::Option<::std::num::NonZeroU64>,
::std::string::String,
>,
refresh_token: ::std::result::Result<
::std::option::Option<super::TokenBundleRefreshToken>,
::std::string::String,
>,
scope: ::std::result::Result<
::std::vec::Vec<super::TokenBundleScopeItem>,
::std::string::String,
>,
token_type: ::std::result::Result<super::TokenBundleTokenType, ::std::string::String>,
}
impl ::std::default::Default for TokenBundle {
fn default() -> Self {
Self {
access_token: Err("no value supplied for access_token".to_string()),
expires_in: Err("no value supplied for expires_in".to_string()),
ext: Ok(Default::default()),
refresh_expires_in: Ok(Default::default()),
refresh_token: Ok(Default::default()),
scope: Ok(Default::default()),
token_type: Err("no value supplied for token_type".to_string()),
}
}
}
impl TokenBundle {
pub fn access_token<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TokenBundleAccessToken>,
T::Error: ::std::fmt::Display,
{
self.access_token = value
.try_into()
.map_err(|e| format!("error converting supplied value for access_token: {e}"));
self
}
pub fn expires_in<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::num::NonZeroU64>,
T::Error: ::std::fmt::Display,
{
self.expires_in = value
.try_into()
.map_err(|e| format!("error converting supplied value for expires_in: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn refresh_expires_in<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::num::NonZeroU64>>,
T::Error: ::std::fmt::Display,
{
self.refresh_expires_in = value.try_into().map_err(|e| {
format!("error converting supplied value for refresh_expires_in: {e}")
});
self
}
pub fn refresh_token<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::TokenBundleRefreshToken>>,
T::Error: ::std::fmt::Display,
{
self.refresh_token = value
.try_into()
.map_err(|e| format!("error converting supplied value for refresh_token: {e}"));
self
}
pub fn scope<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::vec::Vec<super::TokenBundleScopeItem>>,
T::Error: ::std::fmt::Display,
{
self.scope = value
.try_into()
.map_err(|e| format!("error converting supplied value for scope: {e}"));
self
}
pub fn token_type<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::TokenBundleTokenType>,
T::Error: ::std::fmt::Display,
{
self.token_type = value
.try_into()
.map_err(|e| format!("error converting supplied value for token_type: {e}"));
self
}
}
impl ::std::convert::TryFrom<TokenBundle> for super::TokenBundle {
type Error = super::error::ConversionError;
fn try_from(
value: TokenBundle,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
access_token: value.access_token?,
expires_in: value.expires_in?,
ext: value.ext?,
refresh_expires_in: value.refresh_expires_in?,
refresh_token: value.refresh_token?,
scope: value.scope?,
token_type: value.token_type?,
})
}
}
impl ::std::convert::From<super::TokenBundle> for TokenBundle {
fn from(value: super::TokenBundle) -> Self {
Self {
access_token: Ok(value.access_token),
expires_in: Ok(value.expires_in),
ext: Ok(value.ext),
refresh_expires_in: Ok(value.refresh_expires_in),
refresh_token: Ok(value.refresh_token),
scope: Ok(value.scope),
token_type: Ok(value.token_type),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/auth/authenticate/0.2";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\"$defs\":{\"Ext\":{\"additionalProperties\":true,\"description\":\"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"description\":\"Issued by the auth service after verifying the proof on the authenticate document. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/authenticate/0.2#response.\",\"properties\":{\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"session\":{\"$ref\":\"#/$defs/Session\",\"description\":\"The session the consumer has just created or refreshed for this subject. Carries `sessionKey` when the request bound one.\"},\"tokens\":{\"$ref\":\"#/$defs/TokenBundle\",\"description\":\"Access + optional refresh tokens. Consumers MAY omit a refresh token when their policy doesn't support refresh.\"}},\"required\":[\"session\",\"tokens\"],\"title\":\"Auth Authenticate — response payload\",\"type\":\"object\"},\"Session\":{\"$anchor\":\"session\",\"additionalProperties\":false,\"description\":\"A logical authentication context bound to a subject. Producers and consumers exchange Session-shaped data in challenge issuance, authentication responses, and introspection (whoami).\",\"properties\":{\"acr\":{\"description\":\"Authentication Context Class Reference per [OIDC Core §2]. Profiles define their own values; the recommended set is \\\"aal1\\\" (single-factor DID auth), \\\"aal2\\\" (a second possession-or-biometric factor confirmed), and \\\"aal3\\\" (hardware-bound second factor).\",\"type\":\"string\"},\"amr\":{\"description\":\"Authentication Methods References per [RFC 8176]. Typical values: \\\"did\\\" (challenge-response), \\\"passkey\\\" (WebAuthn), \\\"vta\\\" (verifiable-trust agent approval). Multi-factor sessions list every method used.\",\"items\":{\"minLength\":1,\"type\":\"string\"},\"minItems\":1,\"type\":\"array\"},\"expiresAt\":{\"description\":\"ISO-8601 timestamp when the session ceases to be valid. Producers SHOULD refresh before this time; consumers MUST reject after.\",\"format\":\"date-time\",\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"id\":{\"description\":\"Opaque, server-chosen session identifier. Stable for the lifetime of the session. Consumers MUST treat the value as opaque; no structure is implied.\",\"minLength\":1,\"type\":\"string\"},\"issuedAt\":{\"description\":\"ISO-8601 timestamp when the session was created.\",\"format\":\"date-time\",\"type\":\"string\"},\"sessionKey\":{\"description\":\"The did:key VID bound to this session by auth/authenticate/0.2, when the producer registered one. Present here so introspection (auth/whoami, auth/sessions/list) can show the binding a client already holds; it is descriptive, not an additional grant — the binding, its scope and its lifetime are governed entirely by the auth/authenticate/0.2 specification that established it. Absent when the session was established without a session key, or by a specification version that does not carry one.\",\"maxLength\":512,\"pattern\":\"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\",\"type\":\"string\"},\"subject\":{\"description\":\"The authenticated party's VID (typically a DID URL).\",\"minLength\":1,\"type\":\"string\"}},\"required\":[\"id\",\"subject\",\"issuedAt\",\"expiresAt\"],\"title\":\"Session\",\"type\":\"object\"},\"TokenBundle\":{\"$anchor\":\"tokenBundle\",\"additionalProperties\":false,\"description\":\"An access token (typically short-lived JWT) paired with an optional refresh token (typically long-lived opaque string). The shapes follow OAuth 2.0 (RFC 6749 §5.1) conventions but are not coupled to any particular OAuth profile.\",\"properties\":{\"accessToken\":{\"description\":\"Bearer-style access token. Consumers presenting this token to downstream services prove the holder of the original session. Format is consumer-defined — JWT is common, but opaque strings are also valid.\",\"minLength\":1,\"type\":\"string\"},\"expiresIn\":{\"description\":\"Seconds from issuance until the access token expires.\",\"minimum\":1,\"type\":\"integer\"},\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"refreshExpiresIn\":{\"description\":\"Seconds from issuance until the refresh token expires, when one was issued.\",\"minimum\":1,\"type\":\"integer\"},\"refreshToken\":{\"description\":\"Long-lived token redeemable via auth/refresh for a new access token. MAY be absent when the issuer does not support refresh.\",\"minLength\":1,\"type\":\"string\"},\"scope\":{\"description\":\"Capability tags effective on this token. Format is consumer-defined; the framework imposes no syntax.\",\"items\":{\"minLength\":1,\"type\":\"string\"},\"type\":\"array\"},\"tokenType\":{\"description\":\"Token presentation scheme. Almost always \\\"Bearer\\\"; reserved for future schemes.\",\"minLength\":1,\"type\":\"string\"}},\"required\":[\"accessToken\",\"tokenType\",\"expiresIn\"],\"title\":\"TokenBundle\",\"type\":\"object\"}},\"$id\":\"https://trusttasks.org/spec/auth/authenticate/0.2\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"additionalProperties\":false,\"description\":\"The subject presents a previously-issued challenge along with the framework `proof` that binds the document to their VID. The proof IS the authentication. 0.2 adds the optional `sessionKey` member, a did:key VID the consumer binds to the created session so later documents in that session can be signed with it instead of the subject's own key.\",\"properties\":{\"challenge\":{\"description\":\"The exact challenge value returned by a prior auth/challenge call. Consumers MUST reject mismatch, expired, or re-used challenges.\",\"minLength\":16,\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"scope\":{\"description\":\"Optional capability tags the subject is requesting on the issued tokens. The consumer's authorization layer decides which are granted; the issued TokenBundle's `scope` MAY be a subset.\",\"items\":{\"minLength\":1,\"type\":\"string\"},\"type\":\"array\"},\"sessionId\":{\"description\":\"The sessionId returned alongside the challenge. Consumers use it to look up the server-side challenge binding.\",\"minLength\":1,\"type\":\"string\"},\"sessionKey\":{\"description\":\"A did:key VID the producer asks the consumer to bind to the session this authenticate document creates. The producer MUST hold the corresponding private key and SHOULD keep it non-extractable (for example, a WebCrypto non-extractable key). Once bound, the consumer MUST accept a framework `proof` made by this key, with `proofPurpose: authentication`, as the subject — for this session only, bounded by the session's `expiresAt` and `acr`, and never where a specification requires an `assertionMethod` attestation (SPEC.md §7.2 item 10; see Security & Privacy). The consumer MAY refuse a key type it does not support with `auth/authenticate:sessionKeyUnsupported`. It sits inside `payload`, so the subject's own `authentication` proof on this document covers it — a party cannot bind a session key without signing for it.\",\"maxLength\":512,\"pattern\":\"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\",\"type\":\"string\"}},\"required\":[\"challenge\",\"sessionId\"],\"title\":\"Auth — Authenticate\",\"type\":\"object\"}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/auth/authenticate/0.2#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\"$defs\":{\"Ext\":{\"additionalProperties\":true,\"description\":\"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"description\":\"Issued by the auth service after verifying the proof on the authenticate document. Carried in a Trust Task document whose type is https://trusttasks.org/spec/auth/authenticate/0.2#response.\",\"properties\":{\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"session\":{\"$ref\":\"#/$defs/Session\",\"description\":\"The session the consumer has just created or refreshed for this subject. Carries `sessionKey` when the request bound one.\"},\"tokens\":{\"$ref\":\"#/$defs/TokenBundle\",\"description\":\"Access + optional refresh tokens. Consumers MAY omit a refresh token when their policy doesn't support refresh.\"}},\"required\":[\"session\",\"tokens\"],\"title\":\"Auth Authenticate — response payload\",\"type\":\"object\"},\"Session\":{\"$anchor\":\"session\",\"additionalProperties\":false,\"description\":\"A logical authentication context bound to a subject. Producers and consumers exchange Session-shaped data in challenge issuance, authentication responses, and introspection (whoami).\",\"properties\":{\"acr\":{\"description\":\"Authentication Context Class Reference per [OIDC Core §2]. Profiles define their own values; the recommended set is \\\"aal1\\\" (single-factor DID auth), \\\"aal2\\\" (a second possession-or-biometric factor confirmed), and \\\"aal3\\\" (hardware-bound second factor).\",\"type\":\"string\"},\"amr\":{\"description\":\"Authentication Methods References per [RFC 8176]. Typical values: \\\"did\\\" (challenge-response), \\\"passkey\\\" (WebAuthn), \\\"vta\\\" (verifiable-trust agent approval). Multi-factor sessions list every method used.\",\"items\":{\"minLength\":1,\"type\":\"string\"},\"minItems\":1,\"type\":\"array\"},\"expiresAt\":{\"description\":\"ISO-8601 timestamp when the session ceases to be valid. Producers SHOULD refresh before this time; consumers MUST reject after.\",\"format\":\"date-time\",\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"id\":{\"description\":\"Opaque, server-chosen session identifier. Stable for the lifetime of the session. Consumers MUST treat the value as opaque; no structure is implied.\",\"minLength\":1,\"type\":\"string\"},\"issuedAt\":{\"description\":\"ISO-8601 timestamp when the session was created.\",\"format\":\"date-time\",\"type\":\"string\"},\"sessionKey\":{\"description\":\"The did:key VID bound to this session by auth/authenticate/0.2, when the producer registered one. Present here so introspection (auth/whoami, auth/sessions/list) can show the binding a client already holds; it is descriptive, not an additional grant — the binding, its scope and its lifetime are governed entirely by the auth/authenticate/0.2 specification that established it. Absent when the session was established without a session key, or by a specification version that does not carry one.\",\"maxLength\":512,\"pattern\":\"^did:key:z[1-9A-HJ-NP-Za-km-z]+$\",\"type\":\"string\"},\"subject\":{\"description\":\"The authenticated party's VID (typically a DID URL).\",\"minLength\":1,\"type\":\"string\"}},\"required\":[\"id\",\"subject\",\"issuedAt\",\"expiresAt\"],\"title\":\"Session\",\"type\":\"object\"},\"TokenBundle\":{\"$anchor\":\"tokenBundle\",\"additionalProperties\":false,\"description\":\"An access token (typically short-lived JWT) paired with an optional refresh token (typically long-lived opaque string). The shapes follow OAuth 2.0 (RFC 6749 §5.1) conventions but are not coupled to any particular OAuth profile.\",\"properties\":{\"accessToken\":{\"description\":\"Bearer-style access token. Consumers presenting this token to downstream services prove the holder of the original session. Format is consumer-defined — JWT is common, but opaque strings are also valid.\",\"minLength\":1,\"type\":\"string\"},\"expiresIn\":{\"description\":\"Seconds from issuance until the access token expires.\",\"minimum\":1,\"type\":\"integer\"},\"ext\":{\"$ref\":\"#/$defs/Ext\",\"description\":\"Ecosystem-defined extension members per SPEC.md §4.5.1.\"},\"refreshExpiresIn\":{\"description\":\"Seconds from issuance until the refresh token expires, when one was issued.\",\"minimum\":1,\"type\":\"integer\"},\"refreshToken\":{\"description\":\"Long-lived token redeemable via auth/refresh for a new access token. MAY be absent when the issuer does not support refresh.\",\"minLength\":1,\"type\":\"string\"},\"scope\":{\"description\":\"Capability tags effective on this token. Format is consumer-defined; the framework imposes no syntax.\",\"items\":{\"minLength\":1,\"type\":\"string\"},\"type\":\"array\"},\"tokenType\":{\"description\":\"Token presentation scheme. Almost always \\\"Bearer\\\"; reserved for future schemes.\",\"minLength\":1,\"type\":\"string\"}},\"required\":[\"accessToken\",\"tokenType\",\"expiresIn\"],\"title\":\"TokenBundle\",\"type\":\"object\"}},\"$ref\":\"#/$defs/Response\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The earlier `MAJOR.MINOR` of this slug that this version declares it
/// extends (front matter `extends`, SPEC §5.2 "Declared extension"), or
/// `None`. Only the direct declaration; walk a chain with
/// [`crate::extension::extends_for`].
pub const EXTENDS: Option<&str> = None;
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[
error_codes::CHALLENGE_NOT_FOUND,
error_codes::CHALLENGE_EXPIRED,
error_codes::CHALLENGE_MISMATCH,
error_codes::SUBJECT_MISMATCH,
error_codes::SCOPE_DENIED,
error_codes::SESSION_KEY_UNSUPPORTED,
];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `auth/authenticate:challengeNotFound`
///
/// The `sessionId` does not refer to any challenge the auth service issued, or the challenge was already consumed.
///
/// Declared `retryable: false`.
pub const CHALLENGE_NOT_FOUND: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/authenticate:challengeNotFound",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `auth/authenticate:challengeExpired`
///
/// The challenge's expiresAt is in the past.
///
/// Declared `retryable: true`.
pub const CHALLENGE_EXPIRED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/authenticate:challengeExpired",
retryable: true,
details_schema: ::core::option::Option::None,
};
/// `auth/authenticate:challengeMismatch`
///
/// The presented `challenge` value does not equal the one the auth service bound to `sessionId`.
///
/// Declared `retryable: false`.
pub const CHALLENGE_MISMATCH: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/authenticate:challengeMismatch",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `auth/authenticate:subjectMismatch`
///
/// The `issuer` of the authenticate document does not equal the `subject` the challenge was bound to.
///
/// Declared `retryable: false`.
pub const SUBJECT_MISMATCH: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/authenticate:subjectMismatch",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `auth/authenticate:scopeDenied`
///
/// One or more requested scopes were refused by the consumer's authorization policy. `details.refused` MAY enumerate the denied scopes.
///
/// Declared `retryable: false`.
/// Declares a `detailsSchema` for the error's `details` member.
pub const SCOPE_DENIED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/authenticate:scopeDenied",
retryable: false,
details_schema: ::core::option::Option::Some(
"{\"additionalProperties\":false,\"properties\":{\"refused\":{\"items\":{\"type\":\"string\"},\"type\":\"array\"}},\"type\":\"object\"}",
),
};
/// `auth/authenticate:sessionKeyUnsupported`
///
/// The consumer does not support the key type or DID method of the requested `sessionKey` (for example, a `did:key` encoding a curve the consumer's verifier does not implement) and refuses the request rather than silently authenticating without the binding. `details.requested` MAY echo the offending `sessionKey`.
///
/// Declared `retryable: false`.
/// Declares a `detailsSchema` for the error's `details` member.
pub const SESSION_KEY_UNSUPPORTED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "auth/authenticate:sessionKeyUnsupported",
retryable: false,
details_schema: ::core::option::Option::Some(
"{\"additionalProperties\":false,\"properties\":{\"requested\":{\"type\":\"string\"}},\"type\":\"object\"}",
),
};
}