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

Dropbox sign in #46

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Dropbox sign in #46

wants to merge 4 commits into from

Conversation

cp-pratik-k
Copy link
Collaborator

@cp-pratik-k cp-pratik-k commented May 2, 2024

Summary by CodeRabbit

  • New Features

    • Introduced classes for handling Dropbox authentication endpoints, including token exchange and user account retrieval.
    • Updated the base URLs for Google Drive API endpoints.
    • Enhanced network client configuration with new interceptors and error handling.
    • Provides functionality for intercepting network requests to add Dropbox authentication headers.
    • Added an import statement for 'dart:async' related to Google Drive authentication.
    • Introduces an OAuth2 class for managing OAuth2 flows.
    • Introduces a class 'AppSecrets' with static constants for Dropbox app key and app secret.
    • Introduces classes 'BaseURL' and 'RedirectURL' that define various API base URLs and a redirect URL for authentication.
    • Updated error handling with new error classes and status codes.
    • Renamed existing error code constants and added new ones related to various error scenarios.
    • Introduced an extension on the 'DateTime' class to calculate seconds since the epoch.
    • Introduces data models for managing Dropbox accounts, including serialization methods.
    • Introduces a 'DropboxToken' class with fields for managing token data and custom JSON converters.
    • Enhanced 'AuthService' with new dependencies and methods for Dropbox authentication.
    • Introduced a 'DropboxService' class for interacting with Dropbox services.
    • Updated preferences handling with new state providers and renamed properties.
    • Added a new function for creating state providers for encoded preferences.
    • Updated dependencies to include 'crypto' and 'url_launcher'.
    • Updated the 'ActionList' class with changes to the 'margin' property.
  • Enhancements

    • Updated app color theme to include Dropbox branding colors.
  • Documentation

    • Added new entries and paths for various packages to improve project setup and dependency management.

Copy link

coderabbitai bot commented May 2, 2024

Walkthrough

The recent changes focus on enhancing authentication capabilities and network handling in a Flutter project. Key updates include integrating OAuth2 flows, adding specific API endpoints for Dropbox and Google Drive, and refining error handling. These changes aim to bolster security, improve external service integration, and streamline network interactions within the application.

Changes

Files Changed Summary of Changes
data/lib/apis/network/client.dart Enhanced network client configuration with new interceptors and error handling.
data/lib/apis/network/interceptors/... Added interceptors for Dropbox and Google Drive authentication.
data/lib/apis/network/oauth2.dart Introduced an OAuth2 class for managing OAuth2 flows.
data/lib/apis/network/secrets.dart Added constants for Dropbox app key and app secret.
data/lib/apis/network/urls.dart Defined base URLs for Google Drive and Dropbox APIs.
data/lib/errors/... Updated error handling with new error classes and status codes.
data/lib/models/... Introduced models for Dropbox accounts and tokens.
data/lib/services/... Enhanced authentication service for Dropbox with new methods and dependencies.
data/lib/storage/... Updated preferences handling and added state providers for Dropbox-related data.
data/pubspec.yaml Updated dependencies to include crypto and url_launcher.
style/lib/buttons/buttons_list.dart Updated ActionList class with changes to the margin property.

Poem

🐇📦🌐
Code changes dance, in lines they prance,
OAuth2 whispers, in URLs they glance.
Dropbox and Drive, endpoints anew,
Secure paths paved, errors bid adieu.
Fluttering wings of crypto and launch,
In this digital realm, a secure branch. 🚀🔒


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

data/lib/apis/network/oauth2_client.dart Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Out of diff range and nitpick comments (3)
app/lib/ui/flow/accounts/components/account_tab.dart (3)

24-24: Ensure consistent vertical spacing in the container.

Consider using a variable for vertical margin to maintain consistency across the app.


32-33: Ensure consistent padding in the widget.

Consider using a variable for padding to maintain consistency across the app.


68-68: Check the padding for the action list.

Ensure that the padding aligns with the design specifications.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3cb0798 and d9c10c4.
Files ignored due to path filters (3)
  • app/assets/images/icons/dropbox.svg is excluded by !**/*.svg
  • app/ios/Podfile.lock is excluded by !**/*.lock
  • app/pubspec.lock is excluded by !**/*.lock
Files selected for processing (45)
  • .idea/libraries/Dart_Packages.xml (6 hunks)
  • .idea/libraries/Flutter_Plugins.xml (2 hunks)
  • app/android/app/src/main/AndroidManifest.xml (1 hunks)
  • app/assets/locales/app_en.arb (4 hunks)
  • app/ios/Runner/Info.plist (1 hunks)
  • app/ios/Runner/Runner.entitlements (1 hunks)
  • app/lib/domain/assets/assets_paths.dart (1 hunks)
  • app/lib/domain/extensions/app_error_extensions.dart (1 hunks)
  • app/lib/domain/handlers/deep_links_handler.dart (1 hunks)
  • app/lib/main.dart (2 hunks)
  • app/lib/ui/flow/accounts/accounts_screen.dart (3 hunks)
  • app/lib/ui/flow/accounts/accounts_screen_view_model.dart (4 hunks)
  • app/lib/ui/flow/accounts/components/account_tab.dart (3 hunks)
  • app/lib/ui/flow/home/components/hints.dart (2 hunks)
  • app/lib/ui/flow/home/home_screen_view_model.dart (1 hunks)
  • app/linux/flutter/generated_plugin_registrant.cc (1 hunks)
  • app/linux/flutter/generated_plugins.cmake (1 hunks)
  • app/macos/Flutter/GeneratedPluginRegistrant.swift (3 hunks)
  • app/pubspec.yaml (1 hunks)
  • app/windows/flutter/generated_plugin_registrant.cc (1 hunks)
  • app/windows/flutter/generated_plugins.cmake (1 hunks)
  • data/.flutter-plugins-dependencies (1 hunks)
  • data/lib/apis/dropbox/dropbox_auth_endpoints.dart (1 hunks)
  • data/lib/apis/google_drive/google_drive_endpoint.dart (3 hunks)
  • data/lib/apis/network/client.dart (3 hunks)
  • data/lib/apis/network/interceptors/dropbox_auth_interceptor.dart (1 hunks)
  • data/lib/apis/network/interceptors/google_drive_auth_interceptor.dart (2 hunks)
  • data/lib/apis/network/oauth2.dart (1 hunks)
  • data/lib/apis/network/secrets.dart (1 hunks)
  • data/lib/apis/network/urls.dart (1 hunks)
  • data/lib/errors/app_error.dart (2 hunks)
  • data/lib/errors/l10n_error_codes.dart (1 hunks)
  • data/lib/extensions/date_time_extension.dart (1 hunks)
  • data/lib/models/dropbox_account/dropbox_account.dart (1 hunks)
  • data/lib/models/dropbox_account/dropbox_account.freezed.dart (1 hunks)
  • data/lib/models/dropbox_account/dropbox_account.g.dart (1 hunks)
  • data/lib/models/token/token.dart (1 hunks)
  • data/lib/models/token/token.freezed.dart (1 hunks)
  • data/lib/models/token/token.g.dart (1 hunks)
  • data/lib/services/auth_service.dart (3 hunks)
  • data/lib/services/dropbox_services.dart (1 hunks)
  • data/lib/storage/app_preferences.dart (2 hunks)
  • data/lib/storage/provider/preferences_provider.dart (2 hunks)
  • data/pubspec.yaml (1 hunks)
  • style/lib/buttons/buttons_list.dart (1 hunks)
Files not reviewed due to errors (1)
  • data/lib/models/dropbox_account/dropbox_account.freezed.dart (no review received)
Files skipped from review due to trivial changes (9)
  • app/linux/flutter/generated_plugins.cmake
  • app/pubspec.yaml
  • app/windows/flutter/generated_plugins.cmake
  • data/lib/apis/network/interceptors/google_drive_auth_interceptor.dart
  • data/lib/apis/network/secrets.dart
  • data/lib/apis/network/urls.dart
  • data/lib/extensions/date_time_extension.dart
  • data/lib/models/dropbox_account/dropbox_account.g.dart
  • data/lib/models/token/token.g.dart
Files skipped from review as they are similar to previous changes (4)
  • .idea/libraries/Dart_Packages.xml
  • app/macos/Flutter/GeneratedPluginRegistrant.swift
  • data/.flutter-plugins-dependencies
  • data/pubspec.yaml
Additional comments not posted (51)
app/lib/domain/assets/assets_paths.dart (1)

13-13: Addition of Dropbox icon path aligns with the new Dropbox features.

app/ios/Runner/Runner.entitlements (1)

7-10: Addition of associated domains supports deep linking and OAuth2 flows.

data/lib/errors/l10n_error_codes.dart (1)

4-7: Addition of new error codes for authentication and file handling enhances user error feedback.

app/linux/flutter/generated_plugin_registrant.cc (1)

9-15: Registration of GTK and URL launcher plugins enables native capabilities on Linux.

app/windows/flutter/generated_plugin_registrant.cc (1)

9-17: Registration of various plugins enables native capabilities on Windows.

data/lib/services/dropbox_services.dart (1)

16-31: Implementation of DropboxService class is robust with proper dependency injection and error handling.

data/lib/models/token/token.dart (1)

9-39: Implementation of DropboxToken class and custom JSON converter for expiration time is accurate and efficient.

app/lib/domain/extensions/app_error_extensions.dart (1)

10-19: Extension method l10nMessage correctly maps error codes to localized messages, enhancing user feedback.

data/lib/models/dropbox_account/dropbox_account.dart (2)

8-26: The DropboxAccount class is well-defined with all necessary fields marked as required, ensuring robust data integrity. Serialization is correctly implemented.


28-40: The DropboxAccountName class is correctly implemented with required fields and JSON serialization, ensuring data consistency and ease of use.

app/lib/main.dart (1)

27-28: The setup for observing deep links is correctly placed after essential initializations, ensuring that all dependencies are ready before handling incoming links.

app/lib/domain/handlers/deep_links_handler.dart (1)

19-30: Ensure robust error handling by adding null checks for queryParameters['code'] before proceeding with token setting and account updates.

Verification successful

The shell script executed to verify the presence of null checks for queryParameters['code'] did not return any results. This could imply that there are no other occurrences of queryParameters['code'] in the Dart files of the codebase, or the search pattern might have been too restrictive or incorrect.

Given that the initial concern was about ensuring robust error handling by adding null checks, and the script did not find any instances of queryParameters['code'] being used without null checks, it suggests that the specific line of code in the review might be the only occurrence. However, to be thorough and ensure no instances were missed due to potential issues with the search pattern, I will refine and re-run the search.


The refined search for usages of queryParameters['code'] in the Dart files of the codebase has returned two relevant lines from the deep_links_handler.dart file. These lines are:

  1. A null check for queryParameters['code']:
    link.queryParameters['code'] != null
  2. Usage of queryParameters['code'] assuming it is not null:
    code: link.queryParameters['code']!

This confirms that within the deep_links_handler.dart file, there is a null check before the queryParameters['code'] is used, which aligns with the initial review comment suggesting the addition of null checks for robust error handling. Since the script did not find any other occurrences in the codebase, it appears that the implementation in deep_links_handler.dart is the only place where queryParameters['code'] is accessed, and it is done with the necessary null safety checks.

Therefore, the review comment is consistent with the codebase, and the implementation is correct as per the current coding standards in Dart for handling potential null values.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all usages of `queryParameters['code']` include null checks.

# Test: Search for the usage pattern. Expect: Null checks before usage.
rg --type dart $'queryParameters[\'code\']'

Length of output: 48



Script:

#!/bin/bash
# Description: Re-verify that all usages of `queryParameters['code']` include null checks, using a broader search pattern.

# Test: Search for the usage pattern in a broader context. Expect: Null checks before usage.
rg --type dart 'queryParameters.*code'

Length of output: 236

data/lib/apis/network/oauth2.dart (2)

9-17: The method for generating a code verifier uses a secure random generator, ensuring that the generated codes are sufficiently random and secure for OAuth2 operations.


19-49: Ensure that all optional parameters such as state and scopes are correctly included in the authorization URL. Consider adding explicit checks or validations to confirm their inclusion.

data/lib/storage/provider/preferences_provider.dart (1)

Line range hint 1-33: The method for creating regular preference providers is well-implemented, handling various data types and ensuring that preferences are correctly updated in SharedPreferences.

data/lib/storage/app_preferences.dart (1)

Line range hint 1-55: The preference providers are correctly defined and utilize robust methods for handling preferences. Ensure their consistent usage across the application for state management.

Verification successful

The verification process has confirmed that the AppPreferences class is consistently and correctly used across various parts of the application. This includes usage in service layers, UI components, and network configurations, ensuring that the state management is robust and reusable. The implementation aligns with best practices for managing application preferences.

  • Service Layer: Preferences related to Dropbox and Google Drive backup settings are managed in auth_service.dart and dropbox_services.dart.
  • UI Components: Preferences impact UI logic in files like app.dart, onboard_screen.dart, and various screens and components within the ui/flow directory.
  • Network Configuration: The Dropbox token preference is utilized in client.dart for network operations.

This thorough integration of preference providers across the application confirms the initial review comment's approval of the preference management implementation.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistent usage of preference providers across the application.

# Test: Search for the usage of preference providers. Expect: Consistent usage patterns.
rg --type dart $'AppPreferences'

Length of output: 2870

data/lib/apis/dropbox/dropbox_auth_endpoints.dart (3)

4-40: Implementation of DropboxTokenEndpoint looks correct and secure.


42-72: Implementation of DropboxRefreshTokenEndpoint is correct and adheres to best practices.


74-85: Implementation of DropboxGetUserAccountEndpoint is correct and follows best practices.

app/ios/Runner/Info.plist (1)

29-29: Addition of the cloudgallery URL scheme is correctly implemented for OAuth2 redirection.

data/lib/apis/google_drive/google_drive_endpoint.dart (2)

23-23: Update of the base URL in UploadGoogleDriveFile to BaseURL.googleDriveUploadV3 is correctly implemented.


80-80: Update of the base URL in DownloadGoogleDriveFileContent to BaseURL.googleDriveV3 is correctly implemented.

style/lib/buttons/buttons_list.dart (1)

23-30: Changes to the default values for margin and borderRadius in ActionList are appropriate and enhance UI consistency.

app/lib/ui/flow/accounts/accounts_screen_view_model.dart (1)

62-74: Implementation of signInWithDropbox and signOutWithDropbox methods in AccountsStateNotifier correctly handle authentication flow and state management.

data/lib/errors/app_error.dart (1)

Line range hint 39-92: Updates and additions to error classes in AppError are correctly implemented with appropriate localization codes and messages.

data/lib/apis/network/client.dart (1)

22-33: Configuration of dropboxAuthenticatedDioProvider with DropboxAuthInterceptor is correctly implemented for secure and efficient authentication handling.

app/android/app/src/main/AndroidManifest.xml (1)

38-50: Addition of intent filters for handling cloudgallery URL scheme is correctly implemented for OAuth2 redirection.

app/lib/ui/flow/accounts/components/account_tab.dart (2)

38-61: Review the layout and styling of the account information display.

The layout uses a column inside a row which is a common pattern for such designs. The text overflow handling and style application are correctly implemented.


84-84: Validate the use of CachedNetworkImageProvider for profile images.

Verification successful

The use of CachedNetworkImageProvider in the application has been verified and found to be consistent. It is used appropriately across different components for loading images, such as profile images and media thumbnails. This consistency in usage aligns with best practices for image handling in Flutter applications.

  • account_tab.dart: Used for profile images.
  • thumbnail_builder.dart: Used for media thumbnails.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that CachedNetworkImageProvider is used appropriately across the app for consistency.

# Test: Search for other instances of image providers. Expect: Consistent use of CachedNetworkImageProvider.
rg --type dart 'CachedNetworkImageProvider'

Length of output: 274

.idea/libraries/Flutter_Plugins.xml (1)

20-26: Ensure that the newly added plugin entries are correctly formatted.

The entries for url_launcher across different platforms are correctly added and formatted.

app/assets/locales/app_en.arb (4)

11-11: Add localization for Dropbox.

The addition of the "Dropbox" entry in the localization file is correct and follows the existing naming conventions.


32-32: Review the new error message for session expiration.

The new error message for authentication session expiration is clear and correctly localized.


58-58: Check the hint message for signing in.

The hint message for signing in with Google Drive or Dropbox is informative and encourages user interaction.


82-83: Ensure consistency in the sign-in text entries.

The sign-in text entries for Google Drive and Dropbox are consistent with the app's terminology and localization standards.

data/lib/services/auth_service.dart (9)

38-44: Review the dependency injection in the AuthService constructor.

The use of ref.read for dependency injection in the AuthService constructor is correctly implemented and follows best practices for Flutter's provider package.


50-67: Check the initialization of private fields in AuthService.

The private fields in the AuthService class are correctly initialized and encapsulated, enhancing the maintainability of the code.


74-75: Handle exceptions in silent sign-in.

The exception handling in the signInSilently method is robust, ensuring that any errors are appropriately converted to AppError.


85-86: Review exception handling in signInWithGoogle.

The method correctly handles exceptions by converting them to AppError, ensuring consistency in error handling across the service.


93-96: Check the logic for signing out from Google.

The method correctly resets the auto-backup preference upon signing out, which is a good practice for cleaning up user-specific settings.


99-117: Validate the OAuth2 flow implementation for Dropbox.

The implementation of the OAuth2 flow for Dropbox in the signInWithDropBox method is comprehensive and correctly handles the PKCE flow.


119-141: Ensure robust error handling in token setting from code.

The method setDropboxTokenFromCode includes thorough error handling and validation, ensuring the integrity of the token setting process.


143-147: Review the sign-out process for Dropbox.

The signOutWithDropBox method correctly clears the relevant state, ensuring that user data is appropriately handled upon sign-out.


149-168: Check the token refresh logic for Dropbox.

The refreshDropboxToken method correctly handles the token refresh process, including error handling and state updates.

app/lib/ui/flow/accounts/accounts_screen.dart (3)

54-55: Check the padding for the ListView.

The padding for the ListView is correctly set, taking into account system padding and additional symmetric padding.


Line range hint 58-119: Review the Google account integration.

The integration of the Google account into the accounts screen is well-implemented, with clear separation of UI components and logic.


121-170: Evaluate the Dropbox account integration.

The Dropbox account integration is correctly handled, with appropriate UI updates based on the account status and clear action definitions.

data/lib/models/token/token.freezed.dart (4)

17-33: Validate the JSON serialization for DropboxToken.

The JSON serialization and deserialization methods for DropboxToken are correctly implemented using the freezed package.


38-106: Check the copyWith implementation for DropboxToken.

The copyWith method for DropboxToken is correctly implemented, providing a way to copy the object with modified fields.


108-176: Review the implementation of the copyWith method for the implementation class.

The copyWith method for the implementation class of DropboxToken is correctly implemented, ensuring that all fields can be individually updated.


178-250: Ensure correct implementation of the DropboxToken data class.

The DropboxToken data class is correctly annotated and implemented, providing a robust structure for token data management.

app/lib/ui/flow/home/home_screen_view_model.dart (1)

29-32: Review the handling of the Google Drive auto-backup preference.

The handling of the Google Drive auto-backup preference is correctly implemented, with appropriate updates triggered by preference changes.

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.

None yet

1 participant