matthewpalmer / Locksmith

A powerful, protocol-oriented library for working with the keychain in Swift.
MIT License
2.92k stars 266 forks source link

Cannot Update - Swift 3 branch #147

Open mdridley opened 7 years ago

mdridley commented 7 years ago
static let AuthTokenLocation = "ALSAuthToken"
static let key_Token = "token"
static let key_Expiration = "expires"

    static func saveAuthToken(_ authToken: AuthToken) {
        do {
            try Locksmith.updateData(data: [key_Token: authToken.token, key_Expiration: authToken.expiration], forUserAccount: AuthTokenLocation)
        } catch {
            print ("Could not save auth token:\(error)")
        }
    }

A Locksmith error is throwing when I call updateData. Error is returning as undefined. token is a String expiration is a Date

bdonkey commented 7 years ago

same problem here..

do {
            try Locksmith.updateData(data: ["password":password.text!], forUserAccount: loginName.text!, inService: tkcService)
        } catch {
            print("\(error)")
        }

inside of Locksmith.swift at static public fun Locksmith.updateData(...) on statement let request = UpdateRequest(service: service, account: userAccount, data: data) get debug error:

Printing description of request:
expression produced error: error: /var/folders/vl/g9k6m7y17q1_bvmsgfjxv6dr0000gn/T/./lldb/97468/expr37.swift:1:75: error: 'UpdateRequest' is not a member type of '$__lldb_context' (aka 'Locksmith')
Swift._DebuggerSupport.stringForPrintObject(Swift.UnsafePointer<Locksmith.UpdateRequest>(bitPattern: 0x1168c4510)!.pointee)
                                                                ~~~~~~~~~ ^
phatmann commented 7 years ago

The error is that the entitlement is missing. See #31 and http://stackoverflow.com/questions/20344255/secitemadd-and-secitemcopymatching-returns-error-code-34018-errsecmissingentit.

Not sure why this is happening in the new code base. Perhaps an Xcode 8 issue.

phatmann commented 7 years ago

Found some more info:

http://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator

mdridley commented 7 years ago

The above fix to add the Keychain Sharing Capability to the app fixed the issue. Thanks! (Probably needs to be added to the setup ReadMe.md)

phatmann commented 7 years ago

I am using Locksmith from a framework. Is there any way to add credentials to the test host app for unit testing?

On the other hand, I can confirm that adding credentials per above to the app that used the framework worked perfectly.

Nonouf commented 7 years ago

@phatmann Have you find a way to use Locksmith from a framework? I'm currently facing the same issue.

phatmann commented 7 years ago

@Nonouf, I changed my framework unit tests to use my app as the test host. Since the app has an Entitlements file, keychain access works properly.

So, no, I did not solve the issue, but at least I found a workaround. Perhaps you can do the same.

Nonouf commented 7 years ago

@phatmann Thanks for the tips.

I confirm for people using a framework that adding a app target to your framework, which will host your test, works well! Don't forget to select the host application of your tests target.