Skip to content

Commit 19d0460

Browse files
authored
RUST-1870: OIDC Spec Cleanup (#1118)
* RUST-1870: OIDC Spec Cleanup * RUST-1870: cargo fmt
1 parent 2057ddc commit 19d0460

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/client/auth.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ impl AuthMechanism {
203203
MONGODB_OIDC_STR, ENVIRONMENT_PROP_STR
204204
)));
205205
}
206+
let has_token_resource = credential
207+
.mechanism_properties
208+
.as_ref()
209+
.unwrap_or(default_document)
210+
.contains_key(TOKEN_RESOURCE_PROP_STR);
206211
match environment {
207212
Ok(AZURE_ENVIRONMENT_VALUE_STR) | Ok(GCP_ENVIRONMENT_VALUE_STR) => {
208-
if !credential
209-
.mechanism_properties
210-
.as_ref()
211-
.unwrap_or(default_document)
212-
.contains_key(TOKEN_RESOURCE_PROP_STR)
213-
{
213+
if !has_token_resource {
214214
return Err(Error::invalid_argument(format!(
215215
"`{}` must be set for {} authentication in the `{}` or `{}` `{}`",
216216
TOKEN_RESOURCE_PROP_STR,
@@ -221,7 +221,19 @@ impl AuthMechanism {
221221
)));
222222
}
223223
}
224-
_ => (),
224+
_ => {
225+
if has_token_resource {
226+
return Err(Error::invalid_argument(format!(
227+
"`{}` must not be set for {} authentication unless using the `{}` \
228+
or `{}` `{}`",
229+
TOKEN_RESOURCE_PROP_STR,
230+
MONGODB_OIDC_STR,
231+
AZURE_ENVIRONMENT_VALUE_STR,
232+
GCP_ENVIRONMENT_VALUE_STR,
233+
ENVIRONMENT_PROP_STR,
234+
)));
235+
}
236+
}
225237
}
226238
if credential
227239
.source

0 commit comments

Comments
 (0)