Storing access token and refresh token in KeyChain

こ雲淡風輕ζ 提交于 2019-12-14 02:34:37

问题


I would like to know how to effectively store the access token, refresh tokens and their expirations in the iOS keychain.

All the examples I have seen seem to store only one key-value combination. How do we store multiple key values for one keychain identifier?

If there is a better way to store the above, please let me know.


回答1:


You will first want to build a NSDictionary with the key/values you want. Next, you could use something like Lockbox to store that NSDictionary to the keychain, using the provided setDictionary:forKey: interface.

UPDATE: To change values stored in that dictionary, you only have to pass by a NSMutableDictionary (that's the common way of doing):

NSMutableDictionary *mutableDict = [[LockBox dictionaryForKey:@"YourRefreshTokenDictionaryKey"] mutableCopy];
mutableDict[@"access_token"] = @"NewAccessToken";
[LockBox setDictionary:mutableDict forKey:@"YourRefreshTokenDictionaryKey"]; 

FYI, a NSMutableDictionary is a subclass of NSDictionary, so it's safe to save that back directly to the keychain!



来源:https://stackoverflow.com/questions/29949609/storing-access-token-and-refresh-token-in-keychain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!