stytch/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use serde::{Deserialize, Serialize};

#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
    #[error("{0:?}")]
    Response(ErrorResponse),

    #[error(transparent)]
    InvalidHeaderValue(#[from] http::header::InvalidHeaderValue),

    #[error(transparent)]
    InvalidUrl(#[from] url::ParseError),

    #[error("Failed to fetch JWKS")]
    FetchJwks,

    #[error("{0:?}")]
    JwkNotFound(String),

    #[error("Unauthorized")]
    Unauthorized,

    #[error(transparent)]
    JWTError(#[from] crate::shared::jwt_helpers::JWTError),

    #[error(transparent)]
    Other(#[from] Box<dyn std::error::Error + Send + Sync>),
}

pub type Result<T> = std::result::Result<T, Error>;

pub struct Request<Body: Serialize + Send> {
    pub method: http::Method,
    pub path: String,
    pub body: Body,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ErrorResponse {
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
    pub request_id: String,

    #[serde(alias = "error_type", alias = "error")]
    pub error_type: String,
    #[serde(alias = "error_message", alias = "error_description")]
    pub error_message: String,
    #[serde(alias = "error_url", alias = "error_uri")]
    pub error_url: String,
}

pub mod b2b;
pub mod client;
pub mod consumer;
mod shared;