Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keychain error #51

Open
MaxHasADHD opened this issue May 26, 2020 · 2 comments
Open

Keychain error #51

MaxHasADHD opened this issue May 26, 2020 · 2 comments

Comments

@MaxHasADHD
Copy link
Owner

I discovered that if you access the keychain soon after launching / coming to foreground keychain will return an error instead of the data. To fix this I'll be keeping the accessToken and refreshToken is memory instead of fetching from keychain every time. I'll also be changing the kSecAttrAccessible to kSecAttrAccessibleAfterFirstUnlock. As for getting the key ASAP after app launch I can only recommend trying to delay accessing the token.

Some threads on the issue
https://forums.developer.apple.com/thread/4743
https://forums.developer.apple.com/message/351282#351282

I haven't found any other solutions, but if anyone has any other suggestions I'm all ears.

@MaxHasADHD
Copy link
Owner Author

In the future I'd also love to allow apps to use their own storage to save / load the keys so you don't have to use the keychain code I wrote. I'll leave the keychain code in there though so no one is signed out. It'll just give you an extra option if you want something better or more custom.

@MaxHasADHD
Copy link
Owner Author

TraktKit 1.2.2 has been pushed up. Keychain code has been updated and will now search for a token with the new access mode kSecAttrAccessibleAfterFirstUnlock, if it not found it will update the existing values. Some other changes were made like when adding an item to keychain can now handle updating existing items if they exist instead of deleting them first. accessToken and refreshToken are cached in memory now too and are updated when those values are changed. We'll only check the keychain if the cached value is nil. signOut now also clears the refreshToken and expiration date. I'm keeping isSignedIn returning if accessToken is nil or not, but I also recommend perhaps checking if the expiration date exists in user defaults which might help determine if you're logged in if keychain decides to return a false error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant