Skip to content

Commit a5e0082

Browse files
committed
IA feedback
1 parent 349db38 commit a5e0082

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

source/fundamentals/enterprise-auth.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ the values of the ``expires`` and ``refresh_token`` fields.
213213
:dedent:
214214
:start-after: start-custom-callback-machine
215215
:end-before: end-custom-callback-machine
216-
:emphasize-lines: 3, 5-10
216+
:emphasize-lines: 3, 5-7
217217

218218
When the workforce identity authentication process involves human interaction,
219219
you must configure the client by setting the ``oidc_callback`` field of your
@@ -227,16 +227,18 @@ following process:
227227
potential ``refresh_token`` and timeout values, if configured, then returns
228228
them.
229229

230-
The following example defines a custom callback to handle workforce identity.
231-
The callback retrieves the IDPInfo for the provided username and negotiates with
232-
the IDP to obtain the necessary tokens:
230+
The following example defines a custom callback to handle workforce identity. To
231+
customize this example for your use case, replace ``<human flow>`` with your own
232+
custom flow. Refer to `Authorization Code Flow with OIDC
233+
<https://auth0.com/docs/authenticate/login/oidc-conformant-authentication/oidc-adoption-auth-code-flow>`__
234+
for more details.
233235

234236
.. literalinclude:: /includes/fundamentals/code-snippets/enterprise-auth.rs
235237
:language: rust
236238
:dedent:
237239
:start-after: start-custom-callback-user
238240
:end-before: end-custom-callback-user
239-
:emphasize-lines: 3-7, 12
241+
:emphasize-lines: 3
240242

241243
Additional Information
242244
----------------------

source/includes/fundamentals/code-snippets/enterprise-auth.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ async fn main() -> mongodb::error::Result<()> {
3030
.username("<username>".to_owned())
3131
.mechanism(AuthMechanism::MongoDbOidc)
3232
.mechanism_properties(
33-
doc! {"ENVIRONMENT": "azure", "TOKEN_RESOURCE": "<audience>"}
33+
doc! { "ENVIRONMENT": "azure", "TOKEN_RESOURCE": "<audience>" }
3434
)
35-
.build()
36-
.into();
35+
.build();
3736

3837
client_options.credential = Some(credential);
3938
let client = Client::with_options(client_options)?;
@@ -48,10 +47,9 @@ async fn main() -> mongodb::error::Result<()> {
4847
let credential = Credential::builder()
4948
.mechanism(AuthMechanism::MongoDbOidc)
5049
.mechanism_properties(
51-
doc! {"ENVIRONMENT": "gcp", "TOKEN_RESOURCE": "<audience>"}
50+
doc! { "ENVIRONMENT": "gcp", "TOKEN_RESOURCE": "<audience>" }
5251
)
53-
.build()
54-
.into();
52+
.build();
5553

5654
client_options.credential = Some(credential);
5755
let client = Client::with_options(client_options)?;
@@ -87,23 +85,25 @@ async fn main() -> mongodb::error::Result<()> {
8785
// end-custom-callback-machine
8886

8987
// start-custom-callback-user
90-
async fn cb(params: CallbackContext) -> mongodb::error::Result<IdpServerResponse> {
91-
let idp_info = params.idp_info.ok_or(Error::NoIDPInfo)?;
92-
let (access_token, expires, refresh_token) = negotiate_with_idp(ctx, idpInfo.Issuer).await?;
93-
Ok(IdpServerResponse::builder().access_token(access_token).expires(expires).refresh_token(refresh_token).build())
94-
}
95-
client_options.credential = Credential::builder()
96-
.mechanism(AuthMechanism::MongoDbOidc)
97-
.oidc_callback(oidc::Callback::human(move|c| {
98-
async move { cb(c).await }.boxed()
99-
}))
100-
.build()
101-
.into();
88+
let callback = Callback::human(move |context| {
89+
async move {
90+
"<human flow>"
91+
todo!()
92+
}
93+
.boxed()
94+
});
95+
let credential = Credential::builder()
96+
.mechanism(AuthMechanism::MongoDbOidc)
97+
.oidc_callback(callback)
98+
.build();
99+
client_options.credential = Some(credential);
100+
let client = Client::with_options(client_options)?;
101+
102102
let res = client
103103
.database("test")
104104
.collection::<Document>("test")
105105
.find_one(doc! {})
106-
.await;
106+
.await?;
107107
// end-custom-callback-user
108108

109109
Ok(())

0 commit comments

Comments
 (0)