GithubHelp home page GithubHelp logo

nvdnkpr / simplekeychain Goto Github PK

View Code? Open in Web Editor NEW

This project forked from auth0/simplekeychain

0.0 3.0 0.0 114 KB

A Keychain helper for iOS to make it very simple to store/obtain values from iOS Keychain

License: MIT License

simplekeychain's Introduction

SimpleKeychain

CI 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.
  • Support for iOS 8 Access Control for fine grained access control. (Only for iOS 8+)
  • TouchID and Keychain integration with iOS 8 new accesibility field kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly. (Only for iOS 8+)

Usage

NSString *message = NSLocalizedString(@"Please enter your passcode/fingerprint to login with awesome App!.", @"Prompt TouchID message");
A0SimpleKeychain *keychain = [A0SimpleKeychain keychain];
NSString *jwt = [keychain stringForKey:@"auth0-user-jwt" promptMessage:message];

For more examples click here

Requirements

At least iOS 7, if you want to use kSecAttrAccessControl with the flag useAccessControl you need to have iOS 8+.

Installation

SimpleKeychain is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SimpleKeychain"

Or you can add A0SimpleKeychain.h and A0SimpleKeychain.m to your project.

###Swift

In order to use A0SimpleKeychain class in Swift, you'll need to import it's header file in Xcode's Bridging Header. For example if using CocoaPods just add this line in your bridging header:

#import <SimpleKeychain/A0SimpleKeychain.h>

##A0SimpleKeychain

###Save a JWT token or password

NSString *jwt = //user's JWT token obtained after login
[[A0SimpleKeychain keychain] setString:jwt forKey:@"auth0-user-jwt"];
let jwt = //user's JWT token obtained after login
A0SimpleKeychain.keychain().setString(jwt, forKey:"auth0-user-jwt")

###Obtain a JWT token or password

NSString *jwt = [[A0SimpleKeychain keychain] stringForKey:@"auth0-user-jwt"];
let jwt = A0SimpleKeychain.keychain().stringForKey("auth0-user-jwt")

###Share JWT Token with other apps using iOS Access Group

NSString *jwt = //user's JWT token obtained after login
A0SimpleKeychain *keychain = [A0SimpleKeychain keychainWithService:@"Auth0" accessGroup:@"ABCDEFGH.com.mydomain.myaccessgroup"];
[keychain setString:jwt forKey:@"auth0-user-jwt"];
let jwt = //user's JWT token obtained after login
let keychain = A0SimpleKeychain.keychainWithService("Auth0", accessGroup: "ABCDEFGH.com.mydomain.myaccessgroup")
keychain.setString(jwt, forKey:"auth0-user-jwt")

###Store and retrieve JWT token using TouchID and Keychain AcessControl attribute (iOS 8 Only).

Let's save the JWT first:

NSString *jwt = //user's JWT token obtained after login
A0SimpleKeychain *keychain = [A0SimpleKeychain keychain];
keychain.useAcessControl = YES;
keychain.defaultAccesiblity = A0SimpleKeychainItemAccessibleWhenPasscodeSetThisDeviceOnly;
[keychain setString:jwt forKey:@"auth0-user-jwt"];
let jwt = //user's JWT token obtained after login
let keychain = A0SimpleKeychain.keychain()
keychain.useAcessControl = true
keychain.defaultAccesiblity = .WhenPasscodeSetThisDeviceOnly
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

NSString *message = NSLocalizedString(@"Please enter your passcode/fingerprint to login with awesome App!.", @"Prompt TouchID message");
A0SimpleKeychain *keychain = [A0SimpleKeychain keychain];
NSString *jwt = [keychain stringForKey:@"auth0-user-jwt" promptMessage:message];
let message = NSLocalizedString("Please enter your passcode/fingerprint to login with awesome App!.", comment: "Prompt TouchID message")
let keychain = A0SimpleKeychain.keychain()
let jwt = keychain.stringForKey("auth0-user-jwt", promptMessage:message)

###Remove a JWT token or password

[[A0SimpleKeychain keychain] deleteEntryForKey:@"auth0-user-jwt"];
A0SimpleKeychain.keychain().deleteEntryForKey("auth0-user-jwt")

##Contributing

Just clone the repo, and run pod install from the Example directory and you're ready to contribute!.

License

SimpleKeychain is available under the MIT license. See the [LICENSE file](LICENSE file) for more info.

Author

Auth0

What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont 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 account in Auth0

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

simplekeychain's People

Contributors

hzalaz avatar jstart avatar mgonto avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.