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

refactor(oidc): Move qrcode module inside oidc #4687

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

zecakeh
Copy link
Collaborator

@zecakeh zecakeh commented Feb 19, 2025

Because it uses the OIDC API and it is accessed via Oidc::login_with_qr_code().

The second commit makes LoginWithQrCode use OidcBackend instead of its own OauthClient. It will allow to share code when the server backend is switched to the oauth2 crate too. It will also allow to expose the device authorization grant directly in Oidc, if necessary.

Will allow to share code when the backend is switched to the oauth2 crate too.

It will also allow to expose the device authorization grant directly in Oidc, if necessary.

Signed-off-by: Kévin Commaille <[email protected]>
@zecakeh zecakeh requested a review from a team as a code owner February 19, 2025 10:08
@zecakeh zecakeh requested review from Hywan and removed request for a team February 19, 2025 10:08
@poljar poljar requested review from poljar and removed request for Hywan February 19, 2025 10:10
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 8 lines in your changes missing coverage. Please review.

Project coverage is 85.87%. Comparing base (2eb2ae7) to head (1b3f35a).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...matrix-sdk/src/authentication/oidc/qrcode/login.rs 76.47% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4687      +/-   ##
==========================================
- Coverage   85.89%   85.87%   -0.02%     
==========================================
  Files         292      291       -1     
  Lines       33912    33930      +18     
==========================================
+ Hits        29129    29139      +10     
- Misses       4783     4791       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

Sorry I left some musings on our current test situation, not really anything that's blocking this PR.

Comment on lines +244 to +271
#[cfg(all(feature = "e2e-encryption", not(target_arch = "wasm32")))]
async fn request_device_authorization(
&self,
_device_authorization_endpoint: Url,
_client_id: oauth2::ClientId,
_scopes: Vec<oauth2::Scope>,
) -> Result<
oauth2::StandardDeviceAuthorizationResponse,
oauth2::basic::BasicRequestTokenError<oauth2::HttpClientError<reqwest::Error>>,
> {
unimplemented!()
}

#[cfg(all(feature = "e2e-encryption", not(target_arch = "wasm32")))]
async fn exchange_device_code(
&self,
_token_endpoint: Url,
_client_id: oauth2::ClientId,
_device_authorization_response: &oauth2::StandardDeviceAuthorizationResponse,
) -> Result<
OidcSessionTokens,
oauth2::RequestTokenError<
oauth2::HttpClientError<reqwest::Error>,
oauth2::DeviceCodeErrorResponse,
>,
> {
unimplemented!()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest, I don't really like this backend trait and that we're using it to test the OIDC submodule.

I wish we properly mocked things instead and added a oidc() subtype to the MatrixMockServer.

I know it's annoying to mock the OIDC stuff, but if the server changes under our feet we don't have any proof that it did so. Furthermore we don't have any integration tests that use MAS either.

I guess it's still a good step to centralize the logic instead of having this additional OIDC client thing, and then we can mock things using wiremock and MatrixMockServer and eventually get rid of this mock backend and trait.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had planned to slightly refactor the tests before changing to the oauth2 crate, to reduce duplication and simplify the migration. Maybe I can do this instead then.

@poljar poljar merged commit 25d3999 into matrix-org:main Feb 24, 2025
42 checks passed
@zecakeh zecakeh deleted the mv-qrcode branch February 24, 2025 12:48
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.

2 participants