Skip to content
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

RUST-1936: Create public interface for oidc authentication #1091

Merged
merged 25 commits into from
May 7, 2024

Conversation

pmeredit
Copy link
Contributor

@pmeredit pmeredit commented May 1, 2024

No description provided.

@@ -498,7 +543,7 @@ async fn do_single_step_callback(
) -> Result<()> {
let idp_response = {
let cb_context = CallbackContext {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

timeout_seconds was a bad name for an Instant.

/// }.boxed()
/// });
/// ```
#[allow(private_interfaces)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? clippy doesn't complain with it commented out

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 just missed that one :)

#[serde(skip)]
#[derivative(Debug = "ignore", PartialEq = "ignore")]
#[builder(default)]
pub(crate) oidc_callback: oidc::State,
pub oidc_callback: oidc::State,
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to collapse State and Callback into one type named Callback? State is probably a more accurate name for this type in terms of our internal usage, but API-wise the distinction between the two is not relevant and may be confusing for users when attempting to construct this type.

I'm thinking something like this:

pub struct Callback {
    inner: Arc<Mutex<Option<CallbackInner>>>,
    is_user_provided: bool,
}

type UserCallback = Box<dyn Fn(CallbackContext) -> BoxFuture<'static, Result<IdpServerResponse>> + Send + Sync>;

struct CallbackInner {
    user_callback: Arc<UserCallback>,
    kind: CallbackKind,
    cache: Cache,
}

impl Callback {
    pub fn human(...) -> Self { ... }

    pub fn machine(...) -> Self { ... }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I like this better.

@@ -44,6 +45,7 @@ const DEFAULT_ALLOWED_HOSTS: &[&str] = &[
"::1",
];

/// State is a struct that contains the callback and cache for OIDC.
#[derive(Clone)]
pub struct State {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest removing the Default impl for this type and instead adding a pub(crate) constructor method that does the same thing. Trait impls are always public, and I don't think there's any good use case for a user to call State::default().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunately, this is needed for the TypedBuilder derive, but I did add a new function, and I changed the other use of default to new.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh I had forgotten about the TypedBuilder requirement. I missed in the last PR that the field for this type in Credential was made non-optional; was that necessary for implementation/to avoid lots of unwraps? It'd be more consistent with other fields/types for Credential.oidc_callback to be an Option<Callback> (which would make the Default stuff easier since Default for Option is None), but not a huge deal if that doesn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I moved the Option inside the type. I suppose we could have options at several levels. I’m thinking the inner Arc could also be a Box

Copy link
Contributor Author

@pmeredit pmeredit May 1, 2024

Choose a reason for hiding this comment

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

Oh no, I remember now, it’s because of interior mutability requirements: If I set the top level to None at construction time, it's impossible to later change it for azure/gcp builtins.

@pmeredit
Copy link
Contributor Author

pmeredit commented May 1, 2024

Not sure what is going on with all these failed tests where none of the sub tests actually failed.

@abr-egn
Copy link
Contributor

abr-egn commented May 2, 2024

Not sure what is going on with all these failed tests where none of the sub tests actually failed.

This means that the tests themselves passed but something else in the script failed, gotta look at the script output rather than the test breakdown. In this case it looks like doctests are failing: https://parsley.mongodb.com/evergreen/mongo_rust_driver_load_balancer_test_load_balancer_5.0_patch_a28225810b02f3c4461fce6489e95b6c84805ff2_6632d54c72f6240007a8b920_24_05_01_23_50_38/0/task?bookmarks=0,4892&shareLine=4534

Copy link
Contributor

@isabelatkinson isabelatkinson left a comment

Choose a reason for hiding this comment

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

some small docs suggestions for consistency with the rest of the driver, otherwise looks good!

src/client/auth/oidc.rs Outdated Show resolved Hide resolved
/// Callback provides an interface for creating human and machine functions that return
/// access tokens for use in human and machine OIDC flows.
#[non_exhaustive]
pub struct Function {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be non-pub?

src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
src/client/auth/oidc.rs Outdated Show resolved Hide resolved
pmeredit and others added 7 commits May 7, 2024 13:11
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
Co-authored-by: Isabel Atkinson <[email protected]>
@pmeredit
Copy link
Contributor Author

pmeredit commented May 7, 2024

some small docs suggestions for consistency with the rest of the driver, otherwise looks good!

I should have looked at doc examples myself 😂

@pmeredit pmeredit merged commit 241fe3d into mongodb:main May 7, 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