Skip to content

RUST-1663: Implement and enable reauthentication for OIDC #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 12, 2024

Conversation

pmeredit
Copy link
Contributor

@pmeredit pmeredit commented Mar 8, 2024

This ended up much easier than I expected, thanks to how well the rust driver is architected

self
),
}
.into()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem that cfg is allowed within a pattern, unfortunately.

// If the error is a reauthentication required error, we reauthenticate and
// retry the operation.
if err.is_reauthentication_required() {
let credential = self.inner.options.credential.as_ref().ok_or(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both of these errors should be impossible under the current sever spec, but this does future proof us.

@@ -1,14 +1,27 @@
use crate::{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to correct these two tests in this PR as a start on the rest of the prose tests. These tests need to assert the number of times the callback is called.... getting a shared Arc into closures with async blocks is nearly impossible. There does not appear to be a way to do it without the top level function here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ownership here is gnarly, but it can be made to work: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=437cdfd395260f80a01ddce572d97d52

The trick is that you need to clone the Arc twice: once to give an owned value to the Fn, and a second time within that callback to give an owned value to the Future. That second clone is needed because the outer callback can be called multiple times, and each time it has to produce a future that owns the value, so each time it's called it has to re-clone the Arc.

This can be boiled down a little bit to remove the async aspect, which makes it easier to see what's going on: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5f8a27ba1ae567f9ba337489d6a49a40

This is also why the distinction between Fn and FnOnce exists; if the Rust compiler knows that the closure can be called at most once, it's fine with transferring ownership from the closure to its return value: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=44aeb2634aa8e87c43e86ea349106f6a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I thought I tried cloning twice and that was what was really shocking to me. I must be misremembering

@pmeredit pmeredit merged commit 05361ce into mongodb:main Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants