Skip to content

Commit

Permalink
Merge pull request #36 from kishikawakatsumi/credentials
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
kishikawakatsumi committed Jan 18, 2015
2 parents f834ec4 + 2a29c5d commit 8c8abcf
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Lib/KeychainAccess/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public class Keychain {
@availability(iOS, introduced=8.0)
public func getSharedPassword(completion: (account: String?, password: String?, error: NSError?) -> () = { account, password, error -> () in }) {
if let domain = server.host {
requestSharedWebCredential(domain: domain, account: nil) { (credentials, error) -> () in
self.dynamicType.requestSharedWebCredential(domain: domain, account: nil) { (credentials, error) -> () in
if let credential = credentials.first {
let account = credential["account"]
let password = credential["password"]
Expand All @@ -369,7 +369,7 @@ public class Keychain {
@availability(iOS, introduced=8.0)
public func getSharedPassword(account: String, completion: (password: String?, error: NSError?) -> () = { password, error -> () in }) {
if let domain = server.host {
requestSharedWebCredential(domain: domain, account: account) { (credentials, error) -> () in
self.dynamicType.requestSharedWebCredential(domain: domain, account: account) { (credentials, error) -> () in
if let credential = credentials.first {
if let password = credential["password"] {
completion(password: password, error: error)
Expand Down Expand Up @@ -403,21 +403,21 @@ public class Keychain {
}

@availability(iOS, introduced=8.0)
public func requestSharedWebCredential(completion: (credentials: [[String: String]], error: NSError?) -> () = { credentials, error -> () in }) {
public class func requestSharedWebCredential(completion: (credentials: [[String: String]], error: NSError?) -> () = { credentials, error -> () in }) {
requestSharedWebCredential(domain: nil, account: nil, completion: completion)
}

@availability(iOS, introduced=8.0)
public func requestSharedWebCredential(#domain: String, completion: (credentials: [[String: String]], error: NSError?) -> () = { credentials, error -> () in }) {
public class func requestSharedWebCredential(#domain: String, completion: (credentials: [[String: String]], error: NSError?) -> () = { credentials, error -> () in }) {
requestSharedWebCredential(domain: domain, account: nil, completion: completion)
}

@availability(iOS, introduced=8.0)
public func requestSharedWebCredential(#domain: String, account: String, completion: (credentials: [[String: String]], error: NSError?) -> ()) {
public class func requestSharedWebCredential(#domain: String, account: String, completion: (credentials: [[String: String]], error: NSError?) -> ()) {
requestSharedWebCredential(domain: domain as String?, account: account as String?, completion: completion)
}

private func requestSharedWebCredential(#domain: String?, account: String?, completion: (credentials: [[String: String]], error: NSError?) -> ()) {
private class func requestSharedWebCredential(#domain: String?, account: String?, completion: (credentials: [[String: String]], error: NSError?) -> ()) {
SecRequestSharedWebCredential(domain, account) { (credentials, error) -> () in
var remoteError: NSError?
if let error = error {
Expand Down Expand Up @@ -448,7 +448,7 @@ public class Keychain {
}

@availability(iOS, introduced=8.0)
public func generatePassword() -> String {
public class func generatePassword() -> String {
return SecCreateSharedWebCredentialPassword().takeUnretainedValue()
}
#endif
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs exremely easy and much more palatable to use in Swift.

<img src="https://raw.githubusercontent.com/kishikawakatsumi/KeychainAccess/master/Screenshots/01.png" width="320px" />
<img src="https://raw.githubusercontent.com/kishikawakatsumi/KeychainAccess/master/Screenshots/02.png" width="320px" />
<img src="https://raw.githubusercontent.com/kishikawakatsumi/KeychainAccess/master/Screenshots/03.png" width="320px" />

## :bulb: Features

Expand Down Expand Up @@ -342,7 +344,7 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
.authenticationPrompt("Authenticate to login to server")
.getStringOrError("kishikawakatsumi")

if failable.successed {
if failable.succeeded {
println("value: \(failable.value)")
} else {
println("error: \(failable.error?.localizedDescription)")
Expand Down Expand Up @@ -406,6 +408,20 @@ if let password = keychain.get(username) {
}
```

#### Request all associated domain's credentials

```swift
Keychain.requestSharedWebCredential { (credentials, error) -> () in

}
```

#### Generate strong random password

```swift
let password = Keychain.generatePassword()
```

#### How to set up Shared Web Credentials

> 1. Add a com.apple.developer.associated-domains entitlement to your app. This entitlement must include all the domains with which you want to share credentials.
Expand Down
Binary file added Screenshots/02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8c8abcf

Please sign in to comment.