Skip to content

A Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility.

License

Notifications You must be signed in to change notification settings

gokulnair2001/KeychainManager

Repository files navigation

KCM Logo

Keychain Manager

Keychain Manager is a Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility. It focuses on using all the power of Keychain with high simplicity. The easy to use methods of Keychain Manager helps to setup Keychain on any Apple device with great convenience.

๐Ÿ“” Usage

โš™๏ธ Intilisation

Before using any Keychain Manager methods we need to intialise the class. Keychain Manager supports various types of inilisation which depends upon variety of use cases

๐Ÿ—ณ Basic Initialisation

  • This initilisation stores all the Keychain items on the local device.
  • Such initilisations are best used when the app is single login based.
let KCM = KeychainManager()

๐Ÿ—ณ Prefix Initiliser

  • This initiliser helps to add a prefix value in your account string.
  • Such initilisations are best used when performing tests (Eg: test_account1_).
 let KCM = KeychainManager(keyPrefix: "test")

๐Ÿ—ณ Sharable Initiliser

  • Keychain Manger allowes developers to share the keychain values to other apps also synchronise with iCloud.
  • Such initilisations are best used when you need to share Keychain values among apps.
  • Eg: A same app running on two different devices with same iCloudID & To share data between Different apps running on same or different device
let KCM = KeychainManager(accessGroup: "TeamID.KeychainGroupID", synchronizable: true)

๐Ÿ—ณ Prefix + Sharable

  • When you need to add both prefix and sharable propert on keychain then this initialisation is the best one to use
 let KCM = KeychainManager(keyPrefix: "test", accessGroup: "TeamID.KeychainGroupID", synchronizable: true)

๐Ÿ›  Operations

Following are the methods which help to perfrom various operations:

๐Ÿ”‘ SET

  • Used to save data on keychain.
  • Keychain Manager Supports variety of data storage

String

KCM.set(value: "value", service: service_ID, account: account_name)

Bool

KCM.set(value: true, service: service_ID, account: account_name)

Custom Object

KCM.set(object: Any_Codable_Object, service: service_ID, account: account_name)

Web Credentials

KCM.set(server: server_ID, account: account_name, password: password)

Tip: Make sure Account, Service & Server parameter must be unique for every item.

๐Ÿ”‘ GET

  • Used to get Keychain Items.
  • Keychain Manager helps to GET variety of format of Data from Keychain Storage

String

let value = KCM.get(service: service_ID, account: account_name)

Bool

let value = KCM.getBool(service: service_ID, account: account_name)

Custom Object

 let value = KCM.get(object: Any_Codable_Object, service: service_ID, account: account_name)

Web Credentials

let value = KCM.get(server: server_ID, account: account_name)

Get All Values

  • Generic Password
 let value = KCM.getAllValues(secClass: .genericPassword)
  • Web Credentials
 let value = KCM.getAllValues(secClass: .webCredentials)

๐Ÿ”‘ UPDATE

  • Used to update Kechain Item Values
  • Since we have variety of SET and GET methods, similarly to update them we have variety of UPDATE methods

String

KCM.update(value: "value", service: service_ID, account: account_name)

Bool

KCM.update(value: true, service: service_ID, account: account_name)

Custom Object

KCM.update(object: Any_Codable_Object, service: service_ID, account: account_name)

Web Credentials

KCM.update(server: server_ID, account: account_name, password: password)

๐Ÿ”‘ DELETE

  • Used to delete Keychain Items

Service Deletion

 do {
    try KCMTest.delete(service: service_ID, isCustomObjectType: false)
 }
 catch {
    print(error.localizedDescription)
}
  • isCustomObjectType is used to explicitly tell Keychain Manager to delete a custom Object type.
  • By default the value of isCustomObjectType is false

Server Deletion

 do {
    try KCMTest.delete(server: server_ID)
 }
 catch {
    print(error.localizedDescription)
}

๐Ÿ”‘ VALIDATE

  • Is used to check if a certain Server or Service based keychain is valid/present.

Service

 if KCM.isValidService(service: service_ID, account: account_name) {
        print("๐Ÿ™‚")
 } else {
        print("โ˜น๏ธ")
 }

Server

 if KCM.isValidService(server: server_ID, account: account_name) {
     print("๐Ÿ™‚")
 } else {
     print("โ˜น๏ธ")
 }

โ˜๏ธ iCloud Sync

  • iCloud synchronisation needs to be set during initilisation.
  • Make sure to use the sharable initialisation at every method to save all changes on cloud.

๐Ÿ“ฑ Device Supported

No Device Version
1 iOS 13.0.0 +
2 iPadOS 13.0.0 +
3 WatchOS 6.0.0 +
4 MacOS 11.0.0 +
5 tvOS 11.0.0 +

๐Ÿ“Œ Keynotes

Make sure you know these keynotes before using Keychain Manager

  • GET Bool will return false even after deleting the Keychain item.
  • To delete a custom object make sure you explicitly tell Keychain Manager that its a custom object in the delete method.
  • By enabling iCloud sync you also enable Keychain Access Group, thus adding Keychain Sharing capability is important (How to do it?).
  • Every Keychain item stored through MacOS is also saved in form of iOS, making it easy for developers to share same keychain data among all platforms. Thus keychain manager will give access to your MacOS based keychain items on other platforms too (Read this).
  • Keychain Items stored on tvOS will not sync with other platforms (Read this).

๐Ÿ“ฆ SPM

Keychain Manger is available through Swift Package Manager. To add Keychain Manager through SPM

  • Open project in Xcode
  • Select File > Add Packages
https://github.com/gokulnair2001/KeychainManager

SPM Dialogue

๐ŸŒ Keychain Sharing

  • Open your project target
  • Select Signing & Capabilities option
  • Click plus button and search for Keychain Sharing

Keychain Sharing Capability

Screenshot 2022-06-17 at 3 38 39 PM

  • Make sure to use the same Keychain Item in other apps you add the Keychain access group ID of the initial project.

๐Ÿช„ How to contribute ?

  • Use the framework through SPM
  • If you face issues in any step open a new issue.
  • To fix issues: Fork this repository, make your changes and make a Pull Request.

โš–๏ธ License

  • Keychain Manager is available under GNU General Public License.

Like the framework ?

  • If you liked Keychain Manager do consider buying me a coffee ๐Ÿ˜Š

BMC logo+wordmark - Black

Made with โค๏ธ in ๐Ÿ‡ฎ๐Ÿ‡ณ By Gokul Nair

About

A Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages