haste_server/auth_n/oidc/schemas/
mod.rs

1pub mod token_body {
2    typify::import_types!(schema = "./src/auth_n/oidc/schemas/oauth2_token_body.schema.json");
3}
4
5pub mod token_instrospection {
6    typify::import_types!(
7        schema = "./src/auth_n/oidc/schemas/oauth2_token_introspection.schema.json"
8    );
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14
15    #[test]
16    fn test_token_body() {
17        let body = serde_json::from_str::<token_body::OAuth2TokenBody>(
18            r#"
19            {
20               "grant_type": "refresh_token",
21               "refresh_token": "hello",
22               "scope" : "read write",
23               "client_id": "test_client",
24               "client_secret": "test_secret"
25            }
26            "#,
27        );
28
29        assert!(body.is_ok());
30
31        let missing_client_id = serde_json::from_str::<token_body::OAuth2TokenBody>(
32            r#"
33            {
34               "grant_type": "refresh_token",
35               "refresh_token": "hello",
36               "scope" : "read write",
37               "client_secret": "test_secret"
38            }
39            "#,
40        );
41
42        assert!(!missing_client_id.is_ok());
43
44        let body = serde_json::from_str::<token_body::OAuth2TokenBody>(
45            r#"
46            {
47                "grant_type": "authorization_code",
48                "code": "code",
49                "redirect_uri": "redirect_uri",
50                "code_verifier": "code_verifier",
51                "client_id": "client_id"
52            }
53            "#,
54        );
55
56        assert!(body.is_ok());
57
58        let missing_grant_type = serde_json::from_str::<token_body::OAuth2TokenBody>(
59            r#"
60            {
61                "code": "code",
62                "redirect_uri": "redirect_uri",
63                "code_verifier": "code_verifier",
64                "client_id": "client_id"
65            }
66            "#,
67        );
68
69        assert!(!missing_grant_type.is_ok());
70    }
71}