feat: Add Microsoft authentication adapter#472
Conversation
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds complete Microsoft OAuth authentication support to ParseSwift: core callback APIs, async/await wrappers, Combine publishers, and comprehensive tests for each API style. ChangesMicrosoft Authentication Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I will reformat the title to use the proper commit message syntax. |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
Tests/ParseSwiftTests/ParseMicrosoftCombineTests.swift (1)
89-358: ⚡ Quick winAdd Combine tests for insecure-mode Microsoft overloads.
The suite doesn’t currently exercise
loginPublisher(id:accessToken:)andlinkPublisher(id:accessToken:), so one supported auth mode remains unvalidated in this layer.Proposed test additions
+ func testLoginInsecureMode() { + var subscriptions = Set<AnyCancellable>() + let expectation1 = XCTestExpectation(description: "Login insecure mode") + + var serverResponse = LoginSignupResponse() + serverResponse.authData = [ + serverResponse.microsoft.__type: [ + "id": "testing-id", + "access_token": "testing-token" + ] + ] + + let encoded = try! serverResponse.getEncoder().encode(serverResponse, skipKeys: .none) + MockURLProtocol.mockRequests { _ in + MockURLResponse(data: encoded, statusCode: 200, delay: 0.0) + } + + User.microsoft.loginPublisher(id: "testing-id", accessToken: "testing-token") + .sink(receiveCompletion: { completion in + if case let .failure(error) = completion { XCTFail(error.localizedDescription) } + expectation1.fulfill() + }, receiveValue: { user in + XCTAssertEqual(user, User.current) + XCTAssertTrue(user.microsoft.isLinked) + }) + .store(in: &subscriptions) + + wait(for: [expectation1], timeout: 20.0) + } + + func testLinkInsecureMode() throws { + var subscriptions = Set<AnyCancellable>() + let expectation1 = XCTestExpectation(description: "Link insecure mode") + + _ = try loginNormally() + MockURLProtocol.removeAll() + + let serverResponse = LoginSignupResponse() + let encoded = try! serverResponse.getEncoder().encode(serverResponse, skipKeys: .none) + MockURLProtocol.mockRequests { _ in + MockURLResponse(data: encoded, statusCode: 200, delay: 0.0) + } + + User.microsoft.linkPublisher(id: "testing-id", accessToken: "testing-token") + .sink(receiveCompletion: { completion in + if case let .failure(error) = completion { XCTFail(error.localizedDescription) } + expectation1.fulfill() + }, receiveValue: { user in + XCTAssertEqual(user, User.current) + XCTAssertTrue(user.microsoft.isLinked) + }) + .store(in: &subscriptions) + + wait(for: [expectation1], timeout: 20.0) + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Tests/ParseSwiftTests/ParseMicrosoftCombineTests.swift` around lines 89 - 358, Add Combine tests that call the insecure-mode Microsoft overloads by duplicating the pattern from testLoginAuthData and testLinkAuthData: create a serverResponse (LoginSignupResponse), encode/decode to produce userOnServer, mock the network with MockURLProtocol.mockRequests returning the encoded response, build authData via ParseMicrosoft<User>.AuthenticationKeys.id.makeDictionary(id: "testing", accessToken: "token_value") and then call User.microsoft.loginPublisher(id:accessToken:) and User.microsoft.linkPublisher(id:accessToken:) respectively, subscribing and asserting equality with User.current, userOnServer properties, and that microsoft.isLinked is true; name the new tests e.g. testLoginInsecureMode and testLinkInsecureMode and mirror the existing expectation/store logic so they follow the same structure as the other Combine tests.Tests/ParseSwiftTests/ParseMicrosoftTests.swift (1)
116-121: ⚡ Quick winConsider adding end-to-end tests for insecure auth mode.
While this test verifies dictionary construction for the insecure auth mode (
id+access_token), there are no tests that actually calllogin(id:accessToken:)orlink(id:accessToken:)through the full flow with mock server responses. The PR summary states that two auth payload modes are supported, but only the secure OAuth flow (code+redirect_uri) is tested end-to-end.🧪 Suggested test additions
Add tests similar to
testLoginandtestLinkLoggedInUserWithMicrosoft, but using:User.microsoft.login(id: "user_id", accessToken: "access_token") { result in // assertions }This would ensure the insecure auth mode works correctly through the complete authentication flow.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Tests/ParseSwiftTests/ParseMicrosoftTests.swift` around lines 116 - 121, Add end-to-end tests that exercise the insecure auth payload path (id + access_token) by invoking User.microsoft.login(id:accessToken:){...} and User.microsoft.link(id:accessToken:){...} and asserting success/failure and server request/response handling just like the existing testLogin and testLinkLoggedInUserWithMicrosoft tests; ensure the tests use mock server responses matching the insecure payload built by ParseMicrosoft.AuthenticationKeys.id.makeDictionary(id:accessToken:) and verify the created/linked user state and any returned session/token fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Sources/ParseSwift/Authentication/3rd`
Party/ParseMicrosoft/ParseMicrosoft.swift:
- Around line 209-211: The error message passed to completion(.failure(...)) in
ParseMicrosoft (the string that currently reads "Should have authData in
consisting of keys \"code\" and \"redirectURI\", or \"id\" and
\"accessToken\".") has a grammatical mistake; update that message in the failing
branch (the completion(.failure(...)) call) to read "Should have authData
consisting of keys \"code\" and \"redirectURI\", or \"id\" and \"accessToken\"."
so it matches the login method's phrasing.
- Around line 140-142: Update the error message string in ParseMicrosoft.swift
where the completion is invoked with completion(.failure(.init(code:
.unknownError, message: "..."))): change "Should have authData in consisting of
keys \"code\" and \"redirectURI\", or \"id\" and \"accessToken\"." to use
correct grammar by removing "in" so it reads "Should have authData consisting of
keys \"code\" and \"redirectURI\", or \"id\" and \"accessToken\"." This edit is
in the completion failure branch that validates authData.
In `@Sources/ParseSwift/Authentication/3rd`
Party/ParseMicrosoft/ParseMicrosoft+async.swift:
- Around line 28-33: The continuation.resume call is incorrect for Result-based
callbacks: in each async wrapper for the Microsoft login methods (the functions
that call self.login(code:redirectURI:id:options:completion:),
self.login(token:options:completion:) and
self.login(credential:options:completion:)) replace continuation.resume with
continuation.resume(with:) so the Result<AuthenticatedUser, ParseError> passed
into the completion is forwarded properly; keep the same completion argument but
call continuation.resume(with: result) (i.e., use resume(with:) to accept the
Result) in all three async login methods.
In `@Tests/ParseSwiftTests/ParseMicrosoftAsyncTests.swift`:
- Around line 89-285: Add async tests covering the insecure auth-mode endpoints
by creating two new `@MainActor` test methods modeled on testLogin and testLink:
implement testLoginInsecureMode() that builds a LoginSignupResponse, uses
ParseMicrosoft<User>.AuthenticationKeys.id.makeDictionary(id:accessToken:) to
create authData, encodes/decodes the server response and mocks the network, then
calls User.microsoft.login(id:accessToken:) and asserts equality with
User.current and expected fields; implement testLinkInsecureMode() that reuses
loginNormally(), prepares a LoginSignupResponse with updatedAt, mocks the
response, then calls User.microsoft.link(id:accessToken:) and asserts updatedAt,
username/password/link state similar to testLink; use the same helper types
(LoginSignupResponse, MockURLProtocol) and assertions as existing tests.
---
Nitpick comments:
In `@Tests/ParseSwiftTests/ParseMicrosoftCombineTests.swift`:
- Around line 89-358: Add Combine tests that call the insecure-mode Microsoft
overloads by duplicating the pattern from testLoginAuthData and
testLinkAuthData: create a serverResponse (LoginSignupResponse), encode/decode
to produce userOnServer, mock the network with MockURLProtocol.mockRequests
returning the encoded response, build authData via
ParseMicrosoft<User>.AuthenticationKeys.id.makeDictionary(id: "testing",
accessToken: "token_value") and then call
User.microsoft.loginPublisher(id:accessToken:) and
User.microsoft.linkPublisher(id:accessToken:) respectively, subscribing and
asserting equality with User.current, userOnServer properties, and that
microsoft.isLinked is true; name the new tests e.g. testLoginInsecureMode and
testLinkInsecureMode and mirror the existing expectation/store logic so they
follow the same structure as the other Combine tests.
In `@Tests/ParseSwiftTests/ParseMicrosoftTests.swift`:
- Around line 116-121: Add end-to-end tests that exercise the insecure auth
payload path (id + access_token) by invoking
User.microsoft.login(id:accessToken:){...} and
User.microsoft.link(id:accessToken:){...} and asserting success/failure and
server request/response handling just like the existing testLogin and
testLinkLoggedInUserWithMicrosoft tests; ensure the tests use mock server
responses matching the insecure payload built by
ParseMicrosoft.AuthenticationKeys.id.makeDictionary(id:accessToken:) and verify
the created/linked user state and any returned session/token fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 05af3ca0-e320-4204-9bc2-0afb3114ee30
📒 Files selected for processing (6)
Sources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft+async.swiftSources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft+combine.swiftSources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft.swiftTests/ParseSwiftTests/ParseMicrosoftAsyncTests.swiftTests/ParseSwiftTests/ParseMicrosoftCombineTests.swiftTests/ParseSwiftTests/ParseMicrosoftTests.swift
|
Implemented the CodeRabbit feedback in 515a86d: added insecure auth mode coverage for callback, async/await, and Combine flows; fixed the authData validation message grammar; and made the async continuation forwarding explicit with resume(with:). @coderabbitai review |
|
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Tests/ParseSwiftTests/ParseMicrosoftCombineTests.swift`:
- Line 91: Several XCTestExpectation instances in ParseMicrosoftCombineTests
(e.g., the variable expectation1 and the other expectations at the mentioned
locations) use the generic description "Save" which is misleading; update each
XCTestExpectation(description: "...") to a clear, specific description that
matches the operation being tested (for example "SaveUser", "FetchObjects",
"DeleteObject", "UpdateRecord", etc.) so failures show the actual intent—locate
the expectations declared at the referenced positions (the one currently named
expectation1 and the expectations at the other noted lines) and replace the
string literal "Save" with an accurate, descriptive name for that test step.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e31a496d-8316-4d7d-99ac-210b7965b582
📒 Files selected for processing (5)
Sources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft+async.swiftSources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft.swiftTests/ParseSwiftTests/ParseMicrosoftAsyncTests.swiftTests/ParseSwiftTests/ParseMicrosoftCombineTests.swiftTests/ParseSwiftTests/ParseMicrosoftTests.swift
🚧 Files skipped from review as they are similar to previous changes (3)
- Tests/ParseSwiftTests/ParseMicrosoftAsyncTests.swift
- Sources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft+async.swift
- Sources/ParseSwift/Authentication/3rd Party/ParseMicrosoft/ParseMicrosoft.swift
|
This PR is ready for maintainer review. I addressed the CodeRabbit findings in 515a86d, and the visible CodeRabbit / Commit Message / Snyk checks are now green. The upstream CI workflow is currently waiting for maintainer approval to run for this fork PR. |
|
Bounty payment address if needed: BSC / BEP20 wallet |
|
Correction: bounty payment address if needed: BSC / BEP20 wallet 0xEF8139503b8416FB0eded1d33F7eBcCA3C32A83E. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
I rechecked this branch after the latest CodeRabbit note. The expectation descriptions in ParseMicrosoftCombineTests are already operation-specific on the current head commit af06fc3 and are no longer using the generic "Save" label. If CodeRabbit is still showing the earlier finding, it may be reflecting the previous incremental review window rather than the latest head state. |
Summary
Addresses the Microsoft Graph adapter listed in #55.
Testing
Summary by CodeRabbit
Release Notes