Skip to content

Commit

Permalink
✨ :: [#84] JwtStore / 키체인 AccessGroup으로 인앱과 extension의 키체인 공유
Browse files Browse the repository at this point in the history
  • Loading branch information
baekteun committed Aug 7, 2023
1 parent f009a23 commit 67ba5f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Projects/App/Support/Dotori.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
<array>
<string>group.msg.dotori</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.msg.Dotori.keychain-group</string>
</array>
</dict>
</plist>
14 changes: 11 additions & 3 deletions Projects/Core/JwtStore/Sources/KeychainJwtStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import Foundation
import JwtStoreInterface

final class KeychainJwtStore: JwtStore {
private let appIdentifierPrefix = Bundle.main.infoDictionary!["AppIdentifierPrefix"] as? String ?? ""
private var accessGroup: String {
"\(appIdentifierPrefix)com.msg.Dotori.keychain-group"
}

func save(property: JwtStoreProperties, value: String) {
let query: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrAccount: property.rawValue,
kSecValueData: value.data(using: .utf8, allowLossyConversion: false) ?? .init()
kSecValueData: value.data(using: .utf8, allowLossyConversion: false) ?? .init(),
kSecAttrAccessGroup: accessGroup
]
SecItemDelete(query)
SecItemAdd(query, nil)
Expand All @@ -17,7 +23,8 @@ final class KeychainJwtStore: JwtStore {
kSecClass: kSecClassGenericPassword,
kSecAttrAccount: property.rawValue,
kSecReturnData: kCFBooleanTrue!,
kSecMatchLimit: kSecMatchLimitOne
kSecMatchLimit: kSecMatchLimitOne,
kSecAttrAccessGroup: accessGroup
]
var dataTypeRef: AnyObject?
let status = SecItemCopyMatching(query as CFDictionary, &dataTypeRef)
Expand All @@ -31,7 +38,8 @@ final class KeychainJwtStore: JwtStore {
func delete(property: JwtStoreProperties) {
let query: NSDictionary = [
kSecClass: kSecClassGenericPassword,
kSecAttrAccount: property.rawValue
kSecAttrAccount: property.rawValue,
kSecAttrAccessGroup: accessGroup
]
SecItemDelete(query)
}
Expand Down

0 comments on commit 67ba5f7

Please sign in to comment.