kishikawakatsumi / keychainaccess Goto Github PK
View Code? Open in Web Editor NEWSimple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.
License: MIT License
Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.
License: MIT License
Can I use this code to save/edit/delete wifi entries to the OSX keychain?
I won't pretend to know enough about build schemes etc for this, but on trying to update my builds, I get this error:
Scheme KeychainAccess-tvOS is not currently configured for the build action
I am guessing that this is to do with taking the schemes out of the project file. I can build with version == 2.3.1
, but not with ~>2.2.0
(which resolves to 2.3.2
) which I was using previously, and, interestingly enough, not with == 2.2.0
(which says it resolves to 2.2.0
).
My Carthage build command is carthage update --no-use-binaries --no-skip-current --platform ios
.
Is this perhaps because of not sharing build schemes or some such thing?
Swift 2.0 is now official / released with Xcode 7. This should be merged to Master and Swift 2.0 branch deleted. Additionally you might want to start a Swift 2.1 branch...
I'm getting the following error when I try to run carthage update
pointed at your swift-2.0 branch:
*** Building scheme "KeychainAccess-iOS" in KeychainAccess.xcworkspace
A shell task failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/n/Documents/Digest/digest_app_ios/DigestApp/Carthage/Checkouts/KeychainAccess/Lib/KeychainAccess/Keychain.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
Segmentation fault: 11
Thoughts?
Keychain.swift:556:12: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true
Keychain.swift:1100:48: 'kSecUseNoAuthenticationUI' was deprecated in iOS 9.0: Use a kSecAuthenticationUI instead.
Hi All,
Im not sure if im doing this correctly, but im trying to subclass KeychainAccess..
The problem is that I cannot override any constructor cause the only designated is private and I cant call convenience constructors from the subclass..
My final goal is to create a singleton with Keychain:
static let sharedInstance = KeychainManager()
where.. class KeychainManager : Keychain
Can anyone give me hand to understand?
Thanks
I am trying to remove all keychain items from my app. Although, the code fails when the keychain is already empty.
Tried both keychain.remove()
by looping over all keys, and also tried keychain.removeAll()
, yet both failed with the same error.
Please see the StackOverflow question I posted that could not be solved.
http://stackoverflow.com/questions/36993530/using-keychainaccess-to-remove-all-items
Hi
I was wondering, which Xcode version was used to compile the pre-built binaries from https://github.com/kishikawakatsumi/KeychainAccess/releases? (2.2.0 specifically).
I'm asking because a specific (and weird) issue I experienced using Carthage to embed KeychainAccess in my project. More details here: Carthage/Carthage#832
Could it be that they were created using an older version dan Xcode 7.0.1 (maybe one of the beta builds?)
Im getting an error after I install via Cocoapods:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Libtool /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Products/Debug-iphonesimulator/libPods-Orb-KeychainAccess.a normal x86_64
cd /Users/Mathias/Desktop/Orb/Pods
export IPHONEOS_DEPLOYMENT_TARGET=8.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -L/Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Products/Debug-iphonesimulator -filelist /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-Orb-KeychainAccess.build/Objects-normal/x86_64/Pods-Orb-KeychainAccess.LinkFileList -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-Orb-KeychainAccess.build/Objects-normal/x86_64/Pods_Orb_KeychainAccess.swiftmodule -framework Foundation -o /Users/Mathias/Library/Developer/Xcode/DerivedData/Orb-gabuteysqfjkydacbhuayztonsub/Build/Products/Debug-iphonesimulator/libPods-Orb-KeychainAccess.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table ] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
I have other pods in my podfile that works. Not sure what happened here
Cheers!
Hey
This is a tedious t crossing issue, but I noticed that the MIT licence the project is licensed under isn't reflected in the source file and it appears that the source as a whole is all rights reserved.
It would make possible to code as following:
let keychain = Keychain(service:"hoge")
if let username = keychain.allKeys().first { // username will contain "[email protected]"
let password = keychain[username]
}
Thank you for your great library.
I'd like you to tag like '2.0.0-beta.4'
Because I want to add dependency in *.podspec, but podspec doesn't allow symbols like :git
, :branch
.
can do this in Podfile.
pod 'KeychainAccess', :git => 'https://github.com/kishikawakatsumi/KeychainAccess.git', :branch => 'swift-2.0'
cannot do this in *.podspec
s.dependency 'KeychainAccess', :git => 'https://github.com/kishikawakatsumi/KeychainAccess.git', :branch => 'swift-2.0'
want
s.dependency 'KeychainAccess', '~> 2.0.0-beta.4'
Best π
if
statement at line 873 always going false and returning credentials as empty array at line 889
The library can use the Swift 2.0 try-catch mechanism to handle errors instead of the current return of a FailableOf-object.
the readme states that iOS7+ is required but the pod requires iOS8
I am needing to store user/pass info in OS X keychain, but not with an AppStore App. I am able to use DeveloperID for this library ? I am not able to use keychain sharing as that is disallowed for non MAS apps.
keychain["\(PartConfigurationViewController.formName)_all_fields"] = "\(self.dataSource.requiredFields.count)"
keychain["\(PartConfigurationViewController.formName)_invalid_fields"] = String(self.dataSource.invalidFields.count)
Whenever I run these methods, I get two errors saying same thing:
error:[-67594] failed to convert data to string
Can you guess why this is causing a problem?? self.dataSource.invalidFields.count is just Int type, btw.
I think it would good to cut an official release for swift 2.0 as it's now officially released.
Thanks!
Is iOS 7 no longer supported?
In the docs it says this wrapper can be used in iOS7, however, when I try to install it in CocoaPods it says:
[!] The platform of the target
XXX
(iOS 7.0) is not compatible withKeychainAccess (1.1.1)
which has a minimum requirement of iOS 8.0 - OS X 10.9.
Is it true that it is only available on iOS8 and above ?
Good morning,
I am wondering if there is a way to get OSX to stop prompting each time the keychain is accessed. I click "Always allow" and it still prompts every time I access a particular value stored in the keychain.
let keychain = Keychain(service: "com.mycompany.myapp");
// Causes prompt #1
let someValue = keychain[Constants.SomeKey];
// Causes prompt #2
let someValue2 = keychain[Constants.SomeKey2];
It was my understanding that by initializing the Keychain with a service, all key/value pairs in this context would be authorized as a group.
Cheers,
Adam
Is this possible? Is it possible to see if a value exists at a given key in a keychain secured with Touch ID without prompting the user for their finger print?
If not, is there a way to check if the keychain, as a whole, exists without prompting for authentication?
I was torn as to whether I should ask this on here or on StackOverflow. I hope you don't mind me asking here? π π . I figured since I'm using your framework and couldn't find anything about my question in the README, I'd be coming back to you with any answer I got on SO to see how I do it via KeychainAccess.
Many thanks!
Is it possible to set a keychain key on iOS and get it on Apple Watch? would iCloud keychain need to be set in the settings.
Hi,
I have a wrapper class for KeychainAccess:
class KeychainHelper: NSObject {
let keychain: Keychain
class var sharedInstance: KeychainHelper {
struct Singleton {
static let instance = KeychainHelper()
}
return Singleton.instance
}
override init() {
self.keychain = Keychain(service: "com.myDomain.myAppName")
super.init()
}
var username:String? {
get{
return keychain["username"]
}
set{
keychain["username"] = username
}
}
}
And wrote a test for it:
func testUserName() {
if let existingUserName = KeychainHelper.sharedInstance.username{
let testUserName = "[email protected]"
KeychainHelper.sharedInstance.username = testUserName
XCTAssertEqual(testUserName, KeychainHelper.sharedInstance.username)
KeychainHelper.sharedInstance.username = existingUserName
XCTAssertEqual(existingUserName, KeychainHelper.sharedInstance.username)
}
else{
let testUserName = "[email protected]"
KeychainHelper.sharedInstance.username = testUserName
if let receivedUserName = KeychainHelper.sharedInstance.username{
XCTAssertEqual(testUserName, receivedUserName)
}
else{
XCTFail("username was not written to keychain!")
}
KeychainHelper.sharedInstance.username = nil
if let receivedUserName = KeychainHelper.sharedInstance.username{
XCTAssertEqual(receivedUserName, KeychainHelper.sharedInstance.username)
}
}
}
The test fails, because no value can be fetched from Keychain. If I "po kechain" I get the result []. Any ideas?
/Users/allaire/Dropbox/Projects/agendrix/ios/Pods/KeychainAccess/Lib/KeychainAccess/Keychain.swift:289:19: Unnecessary check for 'iOS'; minimum deployment target ensures guard will always be true
var query = options.query()
query[kSecAttrAccount as String] = key
#if os(iOS)
if #available(iOS 9.0, *) {
query[kSecUseAuthenticationUI as String] = kCFBooleanFalse
} else if #available(iOS 8.0, *) {
query[kSecUseNoAuthenticationUI as String] = kCFBooleanTrue
}
#endif
Sorry I have to ask a newbie question, but I cannot find a good answer. Will deleting the app clean the keyChain stored data?
Documentation mentions things such as:
try keychain.set("01234567-89ab-cdef-0123-456789abcdef", key: "kishikawakatsumi")
Two issues here:
There is no such function. There is however a function called set
forKey
.
Secondly, this method does not actually throw any errors, so writing the above will result in a Swift warning.
So I am not sure how to even handle errors.
Documentation needs updating.
i was not able to import this library to an Objc project successfully.
i was reading through the minimum requirement for such compatibility and i noticed that the Swift classes do not carry @objc keyword with them so is this intentional or is it okay to contribute a patch for making the library Objc portable ?
I try to enable the keychain synchronization together with a Touch ID enabled login.
Unfortunately I receive the following error whenever I set .synchronizable(true):
OSStatus error:[-50] One or more parameters passed to a function were not valid.
error: Optional(Error Domain=com.kishikawakatsumi.KeychainAccess.error Code=-50 "One or more parameters passed to a function were not valid." UserInfo=0x7fb271d3e6b0 {NSLocalizedDescription=One or more parameters passed to a function were not valid.})
And thats the example code:
let keychain = Keychain(service: "my.service").synchronizable(true)
keychain.remove("default.tenantid")
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let failable = keychain
.authenticationPrompt("Please auth!")
.getStringOrError("default.tenantid")
if failable.succeeded {
var tenantId: String? = failable.value
if tenantId == nil{
tenantId = NSUUID().UUIDString
let error = keychain
.accessibility(.WhenPasscodeSetThisDeviceOnly, authenticationPolicy: .UserPresence)
.set(tenantId!, key: "default.tenantid")
if error != nil {
println("error: \(error)")
// Error handling if needed...
}
}
//logged in
println(tenantId)
} else {
println("error: \(failable.error?.localizedDescription)")
// Error handling if needed...
}
}
What's wrong?
It cannot be compiled with a error "Cannot invoke 'takeUnretainedValue' with no arguments".
takeUnretainedValue
's arguments changed at beta4?
It would be nice to have a target inside the KeychainAccess project specifically for iOS.
As I can't use Cocoapods due to embedded frameworks are not supported I've included your KeychainAccess as git submodule into my iOS project and checked out the tag 2.3.5
Unfortunately I receive a an unexpected Mach- O header code
after archiving when trying to upload to iTunes Connect.
This is due to the fact the KeychainAccess library is built for OS X by default (Base SDK is set to OS X).
Please add a second framework target, so this can be embedded in iOS projects without modifying your code / settings.
Hi,
I am looking solution for have same ID for device even when user delete app and then install it again. I found that others are using keychain for this. But I've read about some problems that sometimes Keychain returns nil and the second problem could be that ID from keychain would be shared across devices and I really don't want that. I guess that when I set synchronizable to false that there shoudn't be second issue. But what about first one? Is it possible that sometimes Keychain returns nil even if there are saved data? For example link here: soffes/SAMKeychain#75 Should I combine this with NSUserDefaults? When app is launched for first time get ID from keychain and save it to NSUserDefaults for other needs. Thanks for help
Hello,
I'm frequently getting this error:
Error Domain=com.kishikawakatsumi.KeychainAccess.error Code=-34018 "Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements."
I noticed it tends to happen when the application comes back from Background. Any idea where this could come from?
Everytime I killed the app, my keychain's value are empty/nil.
I'm storing the value like this :
var keychain = Keychain(service: "myapp.app.service")
keychain["login"] = login
keychain["auth_token"] = auth_token
Then in my appDelegate didFinishLaunchingWithOptions, I do this var
var keychain = Keychain(service: "myapp.app.service")
let login = keychain["login"]
let auth_token = keychain["auth_token"]
println(login)
println(keychain)
And after I kill the app and open it again, both my login and keychain are NIL. Anyone has any idea why my Keychains value are nil even though I never delete them? (I've tried both solution KeychainWrapper and KeychainAccess, both same behavior).
When attributes[kSecAttrAccessible]
does not exist on following:
https://github.com/kishikawakatsumi/KeychainAccess/blob/master/Lib%2FKeychainAccess%2FKeychain.swift#L373
Should be:
pod 'KeychainAccess', :git => 'https://github.com/kishikawakatsumi/KeychainAccess.git', :branch => 'swift-2.0'
ie. using the line github "kishikawakatsumi/KeychainAccess"
doesn't work but github "kishikawakatsumi/KeychainAccess" "master"
in the Cartfile does.
I'm using Carthage 0.6.5 and Xcode 6.3.1.
Hello,
I can't manage to use KeychainAccess with Carthage.
I get the following error:
*** Building scheme "KeychainAccess" in KeychainAccess.xcworkspace fatal error: SDK count 7 in scheme KeychainAccess is not supported: file /Users/mdiep/Repositories/Carthage/Carthage/Source/CarthageKit/Xcode.swift, line 959
Caught signal triggered by the Swift runtime! Illegal instruction: 4
I just add github "kishikawakatsumi/KeychainAccess"
in my Cartfile
If I remove KeychainAccess from the Cartfile, everything runs fine with the command line carthage update --platform iOS --no-use-binaries
Thanks for your help!
Hi,
I'm new to Swift and I am trying to store the Keychains locally only and not across device. I tried setting .synchronizable(false), but I still get a "AfterFirstUnlock" which says that the Keychain migrates to new device. Also, keychain.accessibility(.AlwaysThisDeviceOnly) doesn't seem to work, still get "AfterFirstUnlock" when print(keychain.accessibility). Is there a way to set the Keychain to be only this device and not sync with icloud.
Sorry if this is a dumb question.
Thanks
When setting KeychainAccess Targets we are unable to link the binary with the framework library. The file does not appear in the drop-down. To get around this we dragged the file in from Finder. It compiles and runs via the simulator. However, it crashes on the iPhone.
Currently I'm not able to create a Swift 2 version of my library because i have a dependency with KeychainAccess.
rt
.Download build from test flight
.Login or store something in keychain
.Force close app multiple time
After 4-5 force close , keychain got cleared
APPLICATION_EXTENSION_API_ONLY = YES
can prevent following warning when using KeychainAccess from App Extension project.
ld: warning: linking against dylib not safe for use in application extensions: β¦Carthage/Build/iOS/KeychainAccess.framework/KeychainAccess
CocoaPods recently added support for Swift. Could we add an KeyChain.podspec file to make this great lib available through CocoaPods?
When I'm returning all values, I noticed there are only two methods: allItems and allKeys.
Is there a way to return just key value pairs in one dictionary??
For example, [ "last_name" : "value1", "first_name" : "value2" ].
Thank you!
@available(iOS, introduced=8.0, deprecated=9.0, message="Use a kSecAuthenticationUI instead.")
public let kSecUseNoAuthenticationUI: CFString
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.