Skip to content

Commit e7dd670

Browse files
committed
docs
1 parent 7f2f1a9 commit e7dd670

15 files changed

+405
-31
lines changed

src/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<C: CompactJson + Claims, P: Provider + Configurable> Client<P, C> {
316316
}
317317

318318
/// Get a userinfo json document for a given token at the provider's
319-
/// userinfo endpoint. Returns [Standard Claims](https://openid.net/specs/openid-connect-basic-1_0.html#StandardClaims) as [Userinfo] struct.
319+
/// userinfo endpoint. Returns [Standard Claims](https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims) as [Userinfo] struct.
320320
///
321321
/// # Errors
322322
///
@@ -334,7 +334,7 @@ impl<C: CompactJson + Claims, P: Provider + Configurable> Client<P, C> {
334334
}
335335

336336
/// Get a userinfo json document for a given token at the provider's
337-
/// userinfo endpoint. Returns [UserInfo Response](https://openid.net/specs/openid-connect-basic-1_0.html#UserInfoResponse)
337+
/// userinfo endpoint. Returns [UserInfo Response](https://openid.net/specs/openid-connect-core-1_0.html#UserInfoResponse)
338338
/// including non-standard claims. The sub (subject) Claim MUST always be
339339
/// returned in the UserInfo Response.
340340
///

src/configurable.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
use crate::Config;
22

3+
/// A trait for types that can be configured.
4+
///
5+
/// This trait defines a method `config` which returns a reference to a
6+
/// `Config`.
37
pub trait Configurable {
8+
/// Returns a reference to the configuration of this type.
9+
///
10+
/// # Examples
11+
///
12+
/// ```
13+
/// let config = MyType::default().config();
14+
/// ```
415
fn config(&self) -> &Config;
516
}

src/custom_claims.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::{Claims, StandardClaims};
3737
///
3838
/// See full example: [openid-example:custom_claims](https://github.com/kilork/openid-example/blob/master/examples/custom_claims.rs)
3939
pub trait CustomClaims: Serialize + DeserializeOwned {
40+
/// The standard claims.
4041
fn standard_claims(&self) -> &StandardClaims;
4142
}
4243

src/discovered.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use url::Url;
44

55
use crate::{error::Error, Config, Configurable, Provider};
66

7+
/// A discovered provider.
8+
///
9+
/// This struct is used to store configuration for a provider that was
10+
/// discovered using the discovery protocol.
711
#[derive(Debug, Clone)]
812
pub struct Discovered(Config);
913

src/display.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
/// The four values for the preferred display parameter in the Options. See spec
2-
/// for details.
1+
/// The four values for the preferred `display` parameter in the Options. See
2+
/// spec for details.
3+
///
4+
/// See: [OpenID Connect Core 1.0: Authentication Request](https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest)
35
#[derive(Debug, Clone, Copy)]
46
pub enum Display {
7+
/// The Authorization Server SHOULD display the authentication and consent
8+
/// UI consistent with a full User Agent page view. If the display parameter
9+
/// is not specified, this is the default display mode.
510
Page,
11+
/// The Authorization Server SHOULD display the authentication and consent
12+
/// UI consistent with a popup User Agent window. The popup User Agent
13+
/// window should be of an appropriate size for a login-focused dialog and
14+
/// should not obscure the entire window that it is popping up over.
615
Popup,
16+
/// The Authorization Server SHOULD display the authentication and consent
17+
/// UI consistent with a device that leverages a touch interface.
718
Touch,
19+
/// The Authorization Server SHOULD display the authentication and consent
20+
/// UI consistent with a "feature phone" type display.
821
Wap,
922
}
1023

src/error.rs

+110-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
OAuth 2.0 errors.
2+
Library errors for OAuth 2.0 and OpenID.
33
*/
44
use std::{error, fmt};
55

@@ -91,6 +91,8 @@ impl From<&str> for OAuth2ErrorCode {
9191
}
9292
}
9393
}
94+
95+
/// Client side error.
9496
#[derive(Debug)]
9597
pub enum ClientError {
9698
/// IO error.
@@ -165,118 +167,213 @@ use thiserror::Error;
165167
#[cfg(feature = "uma2")]
166168
use crate::uma2::Uma2Error;
167169

170+
/// openid library error.
171+
///
172+
/// Wraps different sources of errors under one error type for library.
168173
#[derive(Debug, Error)]
169174
pub enum Error {
175+
/// [biscuit] errors.
170176
#[error(transparent)]
171177
Jose(#[from] Jose),
178+
/// [reqwest] errors.
172179
#[error(transparent)]
173180
Http(#[from] Http),
181+
/// [serde_json] errors.
174182
#[error(transparent)]
175183
Json(#[from] Json),
184+
/// Decode token error.
176185
#[error(transparent)]
177186
Decode(#[from] Decode),
187+
/// Validation error.
178188
#[error(transparent)]
179189
Validation(#[from] Validation),
190+
/// Errors related to userinfo endpoint.
180191
#[error(transparent)]
181192
Userinfo(#[from] Userinfo),
193+
/// Errors related to introspection endpoint.
182194
#[error(transparent)]
183195
Introspection(#[from] Introspection),
196+
/// Secure connection is required.
184197
#[error("Url must use TLS: '{0}'")]
185198
Insecure(::reqwest::Url),
199+
/// The scope must contain `openid`.
186200
#[error("Scope must contain Openid")]
187201
MissingOpenidScope,
202+
/// Path segments in url is cannot-be-a-base.
188203
#[error("Url: Path segments is cannot-be-a-base")]
189204
CannotBeABase,
205+
/// Client side error.
190206
#[error(transparent)]
191207
ClientError(#[from] ClientError),
192208
}
193209

210+
/// Decode token error.
194211
#[derive(Debug, Error)]
195212
pub enum Decode {
196-
#[error("Token Missing a Key Id when the key set has multiple keys")]
213+
/// Token missing a key id when the key set has multiple keys.
214+
#[error("Token missing a key id when the key set has multiple keys")]
197215
MissingKid,
216+
/// Token wants this key id not in the key set.
198217
#[error("Token wants this key id not in the key set: {0}")]
199218
MissingKey(String),
219+
/// JWK Set is empty.
200220
#[error("JWK Set is empty")]
201221
EmptySet,
222+
/// No support for EC keys yet.
202223
#[error("No support for EC keys yet")]
203224
UnsupportedEllipticCurve,
225+
/// No support for Octet key pair yet.
204226
#[error("No support for Octet key pair yet")]
205227
UnsupportedOctetKeyPair,
206228
}
207229

230+
/// Validation failure related to mismatch of values, missing values or expired
231+
/// values.
208232
#[derive(Debug, Error)]
209233
pub enum Validation {
234+
/// Mismatch in token attribute.
210235
#[error(transparent)]
211236
Mismatch(#[from] Mismatch),
237+
/// Missing required token attribute.
212238
#[error(transparent)]
213239
Missing(#[from] Missing),
240+
/// Token expired.
214241
#[error(transparent)]
215242
Expired(#[from] Expiry),
216243
}
217244

245+
/// Mismatch in token attribute.
218246
#[derive(Debug, Error)]
219247
pub enum Mismatch {
248+
/// Client ID and Token authorized party mismatch.
220249
#[error("Client ID and Token authorized party mismatch: '{expected}', '{actual}'")]
221-
AuthorizedParty { expected: String, actual: String },
250+
AuthorizedParty {
251+
/// Expected value.
252+
expected: String,
253+
/// Actual value.
254+
actual: String,
255+
},
256+
/// Configured issuer and token issuer mismatch.
222257
#[error("Configured issuer and token issuer mismatch: '{expected}', '{actual}'")]
223-
Issuer { expected: String, actual: String },
258+
Issuer {
259+
/// Expected value.
260+
expected: String,
261+
/// Actual value.
262+
actual: String,
263+
},
264+
/// Given nonce does not match token nonce.
224265
#[error("Given nonce does not match token nonce: '{expected}', '{actual}'")]
225-
Nonce { expected: String, actual: String },
266+
Nonce {
267+
/// Expected value.
268+
expected: String,
269+
/// Actual value.
270+
actual: String,
271+
},
226272
}
227273

228-
#[derive(Debug, Error)]
274+
/// Missing required token attribute.
275+
#[derive(Debug, Clone, Copy, Error)]
229276
pub enum Missing {
277+
/// Token missing Audience.
230278
#[error("Token missing Audience")]
231279
Audience,
280+
/// Token missing AZP.
232281
#[error("Token missing AZP")]
233282
AuthorizedParty,
283+
/// Token missing Auth Time.
234284
#[error("Token missing Auth Time")]
235285
AuthTime,
286+
/// Token missing Nonce.
236287
#[error("Token missing Nonce")]
237288
Nonce,
238289
}
239290

240-
#[derive(Debug, Error)]
291+
/// Token expiration variants.
292+
#[derive(Debug, Clone, Copy, Error)]
241293
pub enum Expiry {
294+
/// Token expired.
242295
#[error("Token expired at: {0}")]
243296
Expires(::chrono::DateTime<::chrono::Utc>),
297+
/// Token is too old.
244298
#[error("Token is too old: {0}")]
245299
MaxAge(::chrono::Duration),
300+
/// Token exp is not valid UNIX timestamp.
246301
#[error("Token exp is not valid UNIX timestamp: {0}")]
247302
NotUnix(i64),
248303
}
249304

305+
/// Errors related to userinfo endpoint.
250306
#[derive(Debug, Error)]
251307
pub enum Userinfo {
308+
/// Config has no userinfo url.
252309
#[error("Config has no userinfo url")]
253310
NoUrl,
311+
/// The UserInfo Endpoint MUST return a content-type header to indicate
312+
/// which format is being returned.
254313
#[error("The UserInfo Endpoint MUST return a content-type header to indicate which format is being returned")]
255314
MissingContentType,
315+
/// Not parsable content type header.
256316
#[error("Not parsable content type header: {content_type}")]
257-
ParseContentType { content_type: String },
317+
ParseContentType {
318+
/// Content type header value.
319+
content_type: String,
320+
},
321+
/// Wrong content type header.
322+
///
323+
/// The following are accepted content types: `application/json`,
324+
/// `application/jwt`.
258325
#[error("Wrong content type header: {content_type}. The following are accepted content types: application/json, application/jwt")]
259-
WrongContentType { content_type: String, body: Vec<u8> },
326+
WrongContentType {
327+
/// Content type header value.
328+
content_type: String,
329+
/// Request body for analyze.
330+
body: Vec<u8>,
331+
},
332+
/// Token and Userinfo Subjects mismatch.
260333
#[error("Token and Userinfo Subjects mismatch: '{expected}', '{actual}'")]
261-
MismatchSubject { expected: String, actual: String },
334+
MismatchSubject {
335+
/// Expected token subject value.
336+
expected: String,
337+
/// Actual token subject value.
338+
actual: String,
339+
},
340+
/// The sub (subject) Claim MUST always be returned in the UserInfo
341+
/// Response.
262342
#[error(transparent)]
263343
MissingSubject(#[from] StandardClaimsSubjectMissing),
264344
}
265345

266-
#[derive(Debug, Error)]
346+
/// The sub (subject) Claim MUST always be returned in the UserInfo Response.
347+
#[derive(Debug, Copy, Clone, Error)]
267348
#[error("The sub (subject) Claim MUST always be returned in the UserInfo Response")]
268349
pub struct StandardClaimsSubjectMissing;
269350

351+
/// Introspection error details.
270352
#[derive(Debug, Error)]
271353
pub enum Introspection {
354+
/// Config has no introspection url.
272355
#[error("Config has no introspection url")]
273356
NoUrl,
357+
/// The Introspection Endpoint MUST return a `content-type` header to
358+
/// indicate which format is being returned.
274359
#[error("The Introspection Endpoint MUST return a content-type header to indicate which format is being returned")]
275360
MissingContentType,
361+
/// Not parsable content type header.
276362
#[error("Not parsable content type header: {content_type}")]
277-
ParseContentType { content_type: String },
363+
ParseContentType {
364+
/// Content type header value.
365+
content_type: String,
366+
},
367+
/// Wrong content type header.
368+
///
369+
/// The following are accepted content types: `application/json`.
278370
#[error("Wrong content type header: {content_type}. The following are accepted content types: application/json")]
279-
WrongContentType { content_type: String, body: Vec<u8> },
371+
WrongContentType {
372+
/// Content type header value.
373+
content_type: String,
374+
/// Request body for analyze.
375+
body: Vec<u8>,
376+
},
280377
}
281378

282379
#[cfg(test)]

src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod standard_claims_subject;
3232
mod token;
3333
mod token_introspection;
3434
mod userinfo;
35+
/// Token validation methods.
3536
pub mod validation;
3637

3738
/// UMA2 OIDC/OAuth2 extension.
@@ -65,7 +66,20 @@ pub mod biscuit {
6566
pub use biscuit::*;
6667
}
6768

69+
/// Alias for [Jws]
6870
pub type IdToken<T> = Jws<T, Empty>;
71+
/// Alias for discovered [Client].
72+
///
73+
/// See also:
74+
///
75+
/// - [Discovered]
76+
/// - [StandardClaims]
6977
pub type DiscoveredClient = Client<Discovered, StandardClaims>;
78+
/// Alias for discovered UMA2 [Client]
79+
///
80+
/// See also:
81+
///
82+
/// - [uma2::DiscoveredUma2]
83+
/// - [StandardClaims]
7084
#[cfg(feature = "uma2")]
7185
pub type DiscoveredUma2Client = Client<uma2::DiscoveredUma2, StandardClaims>;

0 commit comments

Comments
 (0)