SharedWebCredentials

Version Swift Version Carthage compatible

Swift library for easily working with Shared Web Credentials for iOS with Carthage support.

Released under the MIT license. Enjoy.

Installation

Carthage is the recommended way to install SharedWebCredentials. Add the following to your Cartfile:

github "soffes/SharedWebCredentials"

Prerequisites

To use Shared Web Credentials, you’ll need to setup the proper entitlements and an associated domain. Here’s documentation on how to do that.

Be sure you don’t miss:

If your app runs in iOS 9 and later and you use HTTPS to serve the file, you can create a plain text file that uses the application/json MIME type and you don’t need to sign it.

All of that signing stuff is a real pain. If you are targeting iOS 9 or later, you can skip this step!

Once you get all of that stuff setup, you can use this framework instead of the Security framework to access the credentials in a Swift-friendly way.

Usage

Start by importing the framework:

import SharedWebCredentials

Retrieve Credentials

The system will show its own UI for letting the user choose which account they want to use to sign into the app. The result will be a Credential struct or nil.

Store.get { credential, error in
    if let credential = credential {
        print("Username: \(credential.account), Password: \(credential.password)")
    }

    print("Error: \(error)")
}

It will automatically use any of the domains you have set in your com.apple.developer.associated-domains entitlement. You can optionally specify the domain argument to pick a specific one.

Adding a New Credential

Store.add(domain: "myapp.com", account: "steve", password: "password")

Removing a Credential

Store.remove(domain: "myapp.com", account: "steve")