im
Clone
https://git.tahinli.com/Tahinli/im.git
0 watching0 forksRustAGPL-3.0542.8 KiBb9f0726Tahinli27 days ago34 commits
| 1 | //! The OpenID Connect provider of `im` (`docs/contracts.md` section 2): discovery, the signing keys, |
| 2 | //! the authorization endpoint, the token endpoint and userinfo. |
| 3 | //! |
| 4 | //! Who may sign in is decided by the browser session (`auth.rs`); every endpoint here asks the store |
| 5 | //! and never decides it alone. This module holds what the endpoints share: the token lifetimes, the |
| 6 | //! JSON and OAuth error answers, the query and form parsing, and the URL builder for redirects. |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | use Duration; |
| 21 | |
| 22 | use ; |
| 23 | use Value; |
| 24 | use Form; |
| 25 | use Response; |
| 26 | use ; |
| 27 | |
| 28 | use crateAppState; |
| 29 | |
| 30 | /// Lifetime of an authorization code (contracts section 2.3: 60 seconds, single use). |
| 31 | pub const CODE_TTL: Duration = from_secs; |
| 32 | |
| 33 | /// Lifetime of an access token (contracts section 2.3: 10 minutes). |
| 34 | pub const ACCESS_TTL: Duration = from_secs; |
| 35 | |
| 36 | /// Lifetime of an ID token. |
| 37 | pub const ID_TOKEN_TTL: Duration = from_secs; |
| 38 | |
| 39 | /// Lifetime of a refresh token, unless its session ends first. |
| 40 | pub const REFRESH_TTL: Duration = from_secs; |
| 41 | |
| 42 | /// The largest form body the token endpoint reads, in bytes (task: 16 KiB). |
| 43 | pub const TOKEN_BODY_LIMIT: usize = 16 * 1024; |
| 44 | |
| 45 | /// The audience of a user's access token: this provider's own userinfo endpoint, named by its family |
| 46 | /// key. A machine token's audience is the target service instead (contracts section 2.6). |
| 47 | pub const USERINFO_AUDIENCE: &str = "im"; |
| 48 | |
| 49 | /// Cache policy of the discovery document and the key set. Short, so a key change is seen soon. |
| 50 | pub const PUBLIC_CACHE: &str = "public, max-age=300"; |
| 51 | |
| 52 | /// The issuer: the public origin with no trailing slash (`config.base_url`, validated at boot). |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | /// A JSON answer with `status` and no caching. |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// An OAuth error at the token endpoint or another RFC 6749 endpoint (section 5.2). |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | /// `invalid_client`: 401 with a Basic challenge (RFC 6749 section 5.2). |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | /// `invalid_grant`: the code or token is not usable. One answer for every reason, so the reason is |
| 84 | /// not disclosed. |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | /// The name and value pairs of a query string or a form body, in order. Repeats are kept. |
| 90 | pub type Pairs = ; |
| 91 | |
| 92 | /// Parses a query string or a form body. `None` when it is not valid URL-encoded data. |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | /// How often a parameter occurs. |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | /// How often `name` occurs in `pairs`. |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | /// The value of `name` when it occurs exactly once. |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | /// Percent-encodes a query or form value: every byte except the RFC 3986 unreserved set. |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | /// Decodes `%XX` escapes. `None` for a bad escape or for bytes that are not UTF-8 once decoded. |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | /// Appends `params` to a redirect URI as a query, encoding every name and value. The registered URI |
| 161 | /// has no fragment (checked at registration), so the query goes at its end. |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 |