tower_oauth2_resource_server/
validation.rs

1use std::fmt::Display;
2
3#[derive(Clone, Debug, Default)]
4pub struct ClaimsValidationSpec {
5    pub iss: Option<String>,
6    pub exp: bool,
7    pub nbf: bool,
8    pub aud: Option<Vec<String>>,
9}
10
11impl ClaimsValidationSpec {
12    pub fn new() -> Self {
13        Self::default()
14    }
15
16    pub fn recommended(issuer: &str, audiences: Vec<String>) -> Self {
17        Self::new().exp(true).nbf(true).iss(issuer).aud(audiences)
18    }
19
20    pub fn iss(mut self, issuer: &str) -> Self {
21        self.iss = Some(issuer.to_owned());
22        self
23    }
24
25    pub fn exp(mut self, validate: bool) -> Self {
26        self.exp = validate;
27        self
28    }
29
30    pub fn nbf(mut self, validate: bool) -> Self {
31        self.nbf = validate;
32        self
33    }
34
35    pub fn aud(mut self, audiences: Vec<String>) -> Self {
36        self.aud = Some(audiences);
37        self
38    }
39}
40
41impl Display for ClaimsValidationSpec {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        write!(f, "{:?}", self)
44    }
45}