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

Authentication – Refresh, persistence & API #681

Merged
merged 63 commits into from
Jan 25, 2025

Conversation

mohannad-hassan
Copy link
Collaborator

@mohannad-hassan mohannad-hassan commented Dec 31, 2024

This PR should complete all the functionalities needed to handle the infrastructure of authentication, bar the logout API. This should be handled when adding the details of the login and profile UI.

Main Changes

  • Handling refreshing, persistence and authenticating APIs
  • Restructuring the client to ease testing the public APIs.

Some Design Points

  • I've decided to maintain the configurations setup, at least for now. The public state of the client needs to indicate two non-usable states (not-configured and not-authenticate), so I saw that it's better to unify access through a non-optional type for both of them.
  • I expect that the we might need to run startup actions (eagerly, or lazily) related to data synchronization. Currently, one action is done to restore and refresh the authentication state.
  • This is one point where design might evolve noticeably. The two previous points are expected to be revisited.

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 64.31624% with 167 lines in your changes missing coverage. Please review.

Project coverage is 40.75%. Comparing base (d9fc366) to head (ebce80b).
Report is 42 commits behind head on main.

Files with missing lines Patch % Lines
...thServiceAppAuthImpl/OAuthServiceAppAuthImpl.swift 0.00% 93 Missing ⚠️
...tionClient/Sources/AuthentincationClientImpl.swift 72.34% 26 Missing ⚠️
Core/SecurePersistence/SecurePersistence.swift 61.01% 23 Missing ⚠️
Core/SystemDependencies/KeychainAccess.swift 0.00% 9 Missing ⚠️
...re/SystemDependenciesFake/KeychainAccessFake.swift 65.38% 9 Missing ⚠️
Core/OAuthServiceFake/OAuthServiceFake.swift 93.02% 3 Missing ⚠️
...anProfileService/Sources/QuranProfileService.swift 0.00% 3 Missing ⚠️
Features/SettingsFeature/SettingsBuilder.swift 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #681      +/-   ##
==========================================
- Coverage   40.92%   40.75%   -0.18%     
==========================================
  Files         525      539      +14     
  Lines       20880    21684     +804     
==========================================
+ Hits         8546     8837     +291     
- Misses      12334    12847     +513     

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

@mohannad-hassan mohannad-hassan marked this pull request as ready for review January 1, 2025 09:53
Copy link
Collaborator

@mohamede1945 mohamede1945 left a comment

Choose a reason for hiding this comment

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

Jazak Allah khair, Mohannad!

I believe we need to refine the design of a few components to make them more reusable and minimize the chances of failure. Let me know if you have any questions or need clarification.

Thank you!

@mohannad-hassan
Copy link
Collaborator Author

@mohamede1945
Here's an update:

  • The most noticeable update is the redesign of the OAuth client part, that is used by AuthenticationClient. The OAuthService is now responsible for executing actions and updating state. The new data, or OAuthStateData should be a simple struct now.
  • Extracted that part to a separate Core module. However, I'd like your input if anything is missing from the current mocks to be the kind of fakes we're using, before this is extracted out.
  • Didn't extract Persistence out. It's now an internal type, so the API is fitted for that. I preferred not to put time into making it more general. Let me know what you think.

There is one or two points that I've put off for now:

  • Defining an enum for the available scopes Quran.com has.
  • Currently, OAuth-flow errors revert the client to a non-authenticated state. It might be needed to differentiate server failures and networking issues and other classes. I think it'll be better, in terms of its UX, not to request the user to login again in the first case.

Copy link
Collaborator

@mohamede1945 mohamede1945 left a comment

Choose a reason for hiding this comment

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

Jazak Allah khyran for the changes. This looks so great mashaa'Allah, just a couple more more changes and we should be good to merge inshaa'Allah.

Copy link
Collaborator

@mohamede1945 mohamede1945 left a comment

Choose a reason for hiding this comment

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

Thanks Mohannad a lot for such wonderful work.

import Foundation
import UIKit

public struct OAuthServiceConfiguration {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this needs to be part of the API, does it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's practically a Parameters Object.

Core/SystemDependencies/KeychainAccess.swift Show resolved Hide resolved
Package.swift Outdated Show resolved Hide resolved
@mohannad-hassan mohannad-hassan merged commit 313e3a1 into quran:main Jan 25, 2025
3 checks passed
@mohannad-hassan mohannad-hassan deleted the api-infra branch January 26, 2025 20:24
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