1#![allow(clippy::extra_unused_lifetimes)]
2use std::fmt;
5
6use base64::Engine;
7
8#[aliri_braid::braid(serde)]
10pub struct ClientId;
11
12#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
14pub struct ClientSecret;
15
16impl fmt::Debug for ClientSecretRef {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 f.write_str("[redacted client secret]")
19 }
20}
21impl fmt::Display for ClientSecretRef {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 f.write_str("[redacted client secret]")
24 }
25}
26
27#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
29pub struct AccessToken;
30
31impl fmt::Debug for AccessTokenRef {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 f.write_str("[redacted access token]")
34 }
35}
36impl fmt::Display for AccessTokenRef {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 f.write_str("[redacted access token]")
39 }
40}
41
42#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
44pub struct RefreshToken;
45
46impl fmt::Debug for RefreshTokenRef {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.write_str("[redacted refresh token]")
49 }
50}
51impl fmt::Display for RefreshTokenRef {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 f.write_str("[redacted refresh token]")
54 }
55}
56
57#[aliri_braid::braid(display = "owned", debug = "owned", serde)]
59pub struct CsrfToken;
60
61impl fmt::Debug for CsrfTokenRef {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 f.write_str("[redacted csrf token]")
64 }
65}
66impl fmt::Display for CsrfTokenRef {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 f.write_str("[redacted csrf token]")
69 }
70}
71
72impl CsrfToken {
73 pub fn new_random() -> CsrfToken { Self::new_random_len(16) }
75
76 pub fn new_random_len(len: u32) -> CsrfToken {
78 use rand::Rng as _;
79 let random_bytes: Vec<u8> = (0..len).map(|_| rand::thread_rng().gen::<u8>()).collect();
80 CsrfToken::new(base64::engine::general_purpose::STANDARD.encode(random_bytes))
81 }
82}
83
84impl ClientSecretRef {
85 pub fn secret(&self) -> &str { self.as_str() }
89}
90
91impl AccessTokenRef {
92 pub fn secret(&self) -> &str { self.as_str() }
96}
97impl RefreshTokenRef {
98 pub fn secret(&self) -> &str { self.as_str() }
102}
103impl CsrfTokenRef {
104 pub fn secret(&self) -> &str { self.as_str() }
108}