Swiftpack.co - Package - auth0/SimpleKeychain

SimpleKeychain

CircleCI Coverage Status Version License Platform

A wrapper to make it really easy to deal with iOS Keychain and store your user's credentials securely.

Key Features

  • Simple interface to store user's credentials (e.g. JWT) in the Keychain.
  • Store credentials under an Access Group to enable Keychain Sharing.
  • TouchID/FaceID integration with a reusable LAContext instance.

Table of Contents

Requirements

  • iOS 9.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 11.4+ / 12.x
  • Swift 4.x / 5.x

Installation

CocoaPods

If you are using Cocoapods, add this line to your Podfile:

pod "SimpleKeychain"

Then run pod install.

For more information on Cocoapods, check their official documentation.

Carthage

If you are using Carthage, add the following line to your Cartfile:

github "auth0/SimpleKeychain"

Then run carthage bootstrap.

For more information about Carthage usage, check their official documentation.

SPM

If you are using the Swift Package Manager, open the following menu item in Xcode:

File > Swift Packages > Add Package Dependency...

In the Choose Package Repository prompt add this url:

https://github.com/auth0/SimpleKeychain.git

Then, press Next and complete the remaining steps.

For more information on SPM, check its official documentation.

Usage

Save a JWT token or password

let jwt = // user's JWT token obtained after login
A0SimpleKeychain().setString(jwt, forKey: "auth0-user-jwt")

Obtain a JWT token or password

let jwt = A0SimpleKeychain().string(forKey: "auth0-user-jwt")

Share a JWT Token with other apps using iOS Access Group

let jwt = // user's JWT token obtained after login
let keychain = A0SimpleKeychain(service: "Auth0", accessGroup: "ABCDEFGH.com.mydomain.myaccessgroup")
keychain.setString(jwt, forKey: "auth0-user-jwt")

Store and retrieve a JWT token using TouchID/FaceID

Let's save the JWT first:

let jwt = // user's JWT token obtained after login
let keychain = A0SimpleKeychain()
keychain.useAccessControl = true
keychain.defaultAccessiblity = .whenPasscodeSetThisDeviceOnly
keychain.setTouchIDAuthenticationAllowableReuseDuration(5.0)
keychain.setString(jwt, forKey: "auth0-user-jwt")

If there is an existent value under the key auth0-user-jwt saved with AccessControl and A0SimpleKeychainItemAccessibleWhenPasscodeSetThisDeviceOnly, iOS will prompt the user to enter their passcode or fingerprint before updating the value.

Then let's obtain the value:

let message = NSLocalizedString("Please enter your passcode/fingerprint to login with awesome App!.", comment: "Prompt TouchID message")
let keychain = A0SimpleKeychain()
let jwt = keychain.string(forKey: "auth0-user-jwt", promptMessage: message)

Remove a JWT token or password

A0SimpleKeychain().deleteEntry(forKey: "auth0-user-jwt")

Contributing

Just clone the repo, run carthage bootstrap and you're ready to contribute!

What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple sources, either social identity providers such as Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce (amongst others), or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS, or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed JSON Web Tokens to call your APIs and flow the user identity securely.
  • Analytics of how, when, and where users are logging in.
  • Pull data from other sources and add it to the user profile through JavaScript rules.

Create a Free Auth0 Account

  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub, or Microsoft Account to login.

Issue Reporting

If you have found a bug or to request a feature, please raise an issue. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

Github

link
Stars: 345

Dependencies

Used By

Total: 0

Releases

0.12.1 - 2020-10-19 20:38:38

Fixed

  • Fixed macOS version check on Big Sur #99 (Widcket)

0.12.0 - 2020-10-15 17:25:32

⚠️ This release adds support for Xcode 12 and drops support for Xcode < 11.4

Changed

0.11.1 - 2020-03-26 21:38:56

Fixed

  • Disabled LAContext attribute in simulator [SDK-1476] #91 (Widcket)

0.11.0 - 2020-02-27 16:40:33

Changed

  • Marked up A0SimpleKeychain+KeyPair to admit that keys may not exist #86 (cysp)

Fixed

  • Fixed A0LocalAuthenticationCapable macro #81 (Widcket)

0.10.0 - 2020-02-07 14:04:49

Added

Changed

  • Reused LocalAuthentication context #74 (eaceto)

0.9.0 - 2019-04-24 08:02:04

Changed

0.8.1 - 2018-04-30 19:25:44

Added

Changed

Fixed

0.8.0 - 2017-06-06 04:47:48

Full Changelog

Added

Changed

0.7.0 - 2017-06-06 04:42:08

Full Changelog

Closed issues:

  • Always getting "Error trying to access to non available kSecUseOperationPrompt in iOS7" log #24
  • Default accessiblity should be kSecAttrAccessibleWhenUnlockedThisDeviceOnly #17

Merged pull requests:

  • Update default accessibility #26 (tupakapoor)
  • Only show ios7 error message when attempting to use access control #25 (tupakapoor)

0.6.1 - 2015-10-29 21:19:00

0.6.0 - 2015-10-29 20:30:48

Full Changelog

Merged pull requests:

0.5.0 - 2015-08-13 19:30:54

Full Changelog

Fixed bugs:

  • -[A0SimpleKeychain queryNewKey:value:] leaks accessControl #18

Merged pull requests:

0.4.0 - 2015-08-13 19:30:53

Full Changelog

Closed issues:

  • Enhancement: Update to swift 1.2 #13
  • Code Errors in Your README. #11
  • TouchID does not show up #10

Merged pull requests:

0.3.0 - 2015-08-13 19:30:52

Full Changelog

Closed issues:

  • how to disable touch ID dialog #8
  • Xcode analysis raises 'nil value' issue #7

Merged pull requests:

  • TouchId: Determine reason for failed dataForKey: call #9 (Yspadadden)

0.2.2 - 2015-08-13 19:30:51

Full Changelog

Closed issues:

  • dyld: Symbol not found: _kSecAttrAccessControl #5

Merged pull requests:

  • Value stored into 'NSMutableDictionary' cannot be nil #6 (nsarno)

0.2.1 - 2015-08-13 19:30:50

Full Changelog

Merged pull requests:

  • Fixed issue with TouchId and hasValueForKey: #4 (Yspadadden)

0.2.0 - 2015-08-13 19:30:49

Full Changelog

Merged pull requests:

0.1.0 - 2015-08-13 19:30:48

Merged pull requests:

  • Generate KeyPair in Keychain #1 (hzalaz)

* This Change Log was automatically generated by github_changelog_generator