parse-community / Parse-Swift

The Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, Linux, Android, Windows)
https://parseplatform.org
MIT License
306 stars 69 forks source link

feat: add access group and keychain synchronization #378

Closed cbaker6 closed 2 years ago

cbaker6 commented 2 years ago

New Pull Request Checklist

Issue Description

Items in keychain currently can't be synced across apps or groups.

Related issue: #n/a

Approach

Follow Apple's guide to add an access group and enable synchronizing keychain across devices. The method below has been added:

/**
     Sets all of the items in the Parse Keychain to a specific access group.
     Apps in the same access group can share Keychain items. See Apple's
      [documentation](https://developer.apple.com/documentation/security/ksecattraccessgroup)
      for more information.
     - parameter accessGroup: The name of the access group.
     - parameter synchronizeAcrossDevices: **true** to synchronize, **false** to disable synchronization.
     - throws: An error of type `ParseError`.
     - returns: **true** if the Keychain was moved to the new `accessGroup`, **false** otherwise.
     - warning: Setting `synchronizeAcrossDevices == true` requires `accessGroup` to be
     set to a valid [keychain group](https://developer.apple.com/documentation/security/ksecattraccessgroup).
     */
    @discardableResult static public func setAccessGroup(_ accessGroup: String?,
                                                         synchronizeAcrossDevices: Bool) throws -> Bool

// Call the method
do {
  try ParseSwift.setAccessGroup("name.of.access.group", synchronizeAcrossDevices: false)
} catch {
  // Handle error
}

All Keychain items can be synced except for ParseInstallation and ParseVersion as both of these are unique to it's respective install.

TODOs before merging

parse-github-assistant[bot] commented 2 years ago

Thanks for opening this pull request!

codecov[bot] commented 2 years ago

Codecov Report

Merging #378 (b530234) into main (89e5e69) will increase coverage by 0.23%. The diff coverage is 98.90%.

@@            Coverage Diff             @@
##             main     #378      +/-   ##
==========================================
+ Coverage   89.06%   89.29%   +0.23%     
==========================================
  Files         156      157       +1     
  Lines       14778    14970     +192     
==========================================
+ Hits        13162    13368     +206     
+ Misses       1616     1602      -14     
Impacted Files Coverage Δ
Sources/ParseSwift/Storage/ParseStorage.swift 82.14% <ø> (ø)
Sources/ParseSwift/Types/ParseACL.swift 93.58% <ø> (ø)
Sources/ParseSwift/Storage/KeychainStore.swift 97.86% <98.40%> (+2.21%) :arrow_up:
Sources/ParseSwift/Objects/ParseInstallation.swift 85.27% <100.00%> (ø)
Sources/ParseSwift/Objects/ParseObject.swift 87.29% <100.00%> (ø)
Sources/ParseSwift/Objects/ParseUser.swift 86.34% <100.00%> (+0.19%) :arrow_up:
Sources/ParseSwift/Parse.swift 91.28% <100.00%> (+2.61%) :arrow_up:
...es/ParseSwift/Protocols/ParseHookRequestable.swift 100.00% <100.00%> (ø)
Sources/ParseSwift/Types/ParseConfig.swift 100.00% <100.00%> (+1.09%) :arrow_up:
...es/ParseSwift/Types/ParseKeychainAccessGroup.swift 100.00% <100.00%> (ø)
... and 8 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.