|
3 | 3 |
|
4 | 4 | #[cfg(feature = "aws-auth")]
|
5 | 5 | pub(crate) mod aws;
|
6 |
| -pub(crate) mod oidc; |
| 6 | +/// Contains the functionality for [`OIDC`](https://openid.net/developers/how-connect-works/) authorization and authentication. |
| 7 | +pub mod oidc; |
7 | 8 | mod plain;
|
8 | 9 | mod sasl;
|
9 | 10 | mod scram;
|
@@ -227,8 +228,8 @@ impl AuthMechanism {
|
227 | 228 | .map_or(false, |s| s != "$external")
|
228 | 229 | {
|
229 | 230 | return Err(Error::invalid_argument(format!(
|
230 |
| - "source must be $external for {} authentication", |
231 |
| - MONGODB_OIDC_STR |
| 231 | + "source must be $external for {} authentication, found: {:?}", |
| 232 | + MONGODB_OIDC_STR, credential.source |
232 | 233 | )));
|
233 | 234 | }
|
234 | 235 | if credential.password.is_some() {
|
@@ -470,15 +471,32 @@ pub struct Credential {
|
470 | 471 | pub mechanism_properties: Option<Document>,
|
471 | 472 |
|
472 | 473 | /// The token callback for OIDC authentication.
|
473 |
| - // TODO RUST-1497: make this `pub` |
474 |
| - // Credential::builder().oidc_callback(oidc::Callback::human(...)).build() |
475 |
| - // the name of the field here does not well encompass what this field actually is since |
476 |
| - // it contains all the OIDC state information, not just the callback, but it conforms |
477 |
| - // to how a user would interact with it. |
| 474 | + /// ``` |
| 475 | + /// use mongodb::{error::Error, Client, options::{ClientOptions, oidc::{Callback, CallbackContext, IdpServerResponse}}}; |
| 476 | + /// use std::time::{Duration, Instant}; |
| 477 | + /// use futures::future::FutureExt; |
| 478 | + /// async fn do_human_flow(c: CallbackContext) -> Result<(String, Option<Instant>, Option<String>), Error> { |
| 479 | + /// // Do the human flow here see: https://auth0.com/docs/authenticate/login/oidc-conformant-authentication/oidc-adoption-auth-code-flow |
| 480 | + /// Ok(("some_access_token".to_string(), Some(Instant::now() + Duration::from_secs(60 * 60 * 12)), Some("some_refresh_token".to_string()))) |
| 481 | + /// } |
| 482 | + /// |
| 483 | + /// async fn setup_client() -> Result<Client, Error> { |
| 484 | + /// let mut opts = |
| 485 | + /// ClientOptions::parse("mongodb://localhost:27017,localhost:27018/admin?authSource=admin&authMechanism=MONGODB-OIDC").await?; |
| 486 | + /// opts.credential.as_mut().unwrap().oidc_callback = |
| 487 | + /// Callback::human(move |c: CallbackContext| { |
| 488 | + /// async move { |
| 489 | + /// let (access_token, expires, refresh_token) = do_human_flow(c).await?; |
| 490 | + /// Ok(IdpServerResponse::builder().access_token(access_token).expires(expires).refresh_token(refresh_token).build()) |
| 491 | + /// }.boxed() |
| 492 | + /// }); |
| 493 | + /// Client::with_options(opts) |
| 494 | + /// } |
| 495 | + /// ``` |
478 | 496 | #[serde(skip)]
|
479 | 497 | #[derivative(Debug = "ignore", PartialEq = "ignore")]
|
480 | 498 | #[builder(default)]
|
481 |
| - pub(crate) oidc_callback: oidc::State, |
| 499 | + pub oidc_callback: oidc::Callback, |
482 | 500 | }
|
483 | 501 |
|
484 | 502 | impl Credential {
|
|
0 commit comments