Skip to content

Commit f6bfb42

Browse files
committed
Migrate to SwiftKeychain v2.1.0
1 parent 06b65b1 commit f6bfb42

File tree

9 files changed

+59
-20
lines changed

9 files changed

+59
-20
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.3
1+
5.5.3

OAuth2.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,8 +1240,8 @@
12401240
isa = XCRemoteSwiftPackageReference;
12411241
repositoryURL = "https://github.com/slidoapp/SwiftKeychain";
12421242
requirement = {
1243-
branch = master;
1244-
kind = branch;
1243+
kind = upToNextMinorVersion;
1244+
minimumVersion = 2.1.0;
12451245
};
12461246
};
12471247
/* End XCRemoteSwiftPackageReference section */

OAuth2.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let package = Package(
3030
.library(name: "OAuth2", targets: ["OAuth2"]),
3131
],
3232
dependencies: [
33-
.package(url: "https://github.com/slidoapp/SwiftKeychain.git", branch: "master"),
33+
.package(url: "https://github.com/slidoapp/SwiftKeychain.git", .upToNextMinor(from: "2.1.0")),
3434
],
3535
targets: [
3636
.target(name: "OAuth2",

Sources/Base/OAuth2Base.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,26 @@ open class OAuth2Base: OAuth2Securable {
208208
return authURL.description
209209
}
210210

211-
override open func updateFromKeychainItems(_ items: [String: Any]) {
211+
override open func updateFromKeychainItems(_ items: [String: any Sendable]) {
212212
for message in clientConfig.updateFromStorableItems(items) {
213213
logger?.debug("OAuth2", msg: message)
214214
}
215215
clientConfig.secretInBody = (clientConfig.endpointAuthMethod == OAuth2EndpointAuthMethod.clientSecretPost)
216216
}
217217

218-
override open func storableCredentialItems() -> [String: Any]? {
218+
override open func storableCredentialClasses() -> [AnyClass] {
219+
return clientConfig.storableCredentialClasses()
220+
}
221+
222+
override open func storableCredentialItems() -> [String: any Sendable]? {
219223
return clientConfig.storableCredentialItems()
220224
}
221225

222-
override open func storableTokenItems() -> [String: Any]? {
226+
override open func storableTokenClasses() -> [AnyClass] {
227+
return clientConfig.storableTokenClasses()
228+
}
229+
230+
override open func storableTokenItems() -> [String: any Sendable]? {
223231
return clientConfig.storableTokenItems()
224232
}
225233

Sources/Base/OAuth2ClientConfig.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ open class OAuth2ClientConfig {
204204
}
205205
}
206206

207+
/**
208+
Enumerates all classes used for storing credential items.
209+
210+
- returns: An array containing all classes used for storing credential items
211+
*/
212+
func storableCredentialClasses() -> [AnyClass] {
213+
return []
214+
}
215+
207216
/**
208217
Creates a dictionary of credential items that can be stored to the keychain.
209218

@@ -220,6 +229,15 @@ open class OAuth2ClientConfig {
220229
return items
221230
}
222231

232+
/**
233+
Enumerates all classes used for storing token items.
234+
235+
- returns: An array containing all classes used for storing token items
236+
*/
237+
func storableTokenClasses() -> [AnyClass] {
238+
return [NSDate.self]
239+
}
240+
223241
/**
224242
Creates a dictionary of token items that can be stored to the keychain.
225243

Sources/Base/OAuth2KeychainAccount.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct OAuth2KeychainAccount: KeychainGenericPasswordType {
3737
/// Data that ends up in the keychain.
3838
var data = KeychainData()
3939

40+
/// Classes to store in the keychain.
41+
var storedClasses: [AnyClass]
42+
4043
/// Keychain access mode.
4144
let accessMode: String
4245

@@ -47,13 +50,15 @@ struct OAuth2KeychainAccount: KeychainGenericPasswordType {
4750
- parameter oauth2: The OAuth2 instance from which to retrieve settings
4851
- parameter account: The account name to use
4952
- parameter data: Data that we want to store to the keychain
53+
- parameter classes: Classes to store in the keychain
5054
*/
51-
init(oauth2: OAuth2Securable, account: String, data inData: [String: Any] = [:]) {
55+
init(oauth2: OAuth2Securable, account: String, data inData: KeychainData = [:], classes: [AnyClass] = []) {
5256
serviceName = oauth2.keychainServiceName()
5357
accountName = account
5458
accessMode = String(oauth2.keychainAccessMode)
5559
accessGroup = oauth2.keychainAccessGroup
5660
data = inData
61+
storedClasses = classes
5762
}
5863
}
5964

Sources/Base/OAuth2Securable.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ open class OAuth2Securable: OAuth2Requestable {
113113
logger?.debug("OAuth2", msg: "Looking for items in keychain")
114114

115115
do {
116-
var creds = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForClientCredentials)
116+
var creds = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForClientCredentials, classes: storableCredentialClasses())
117117
let creds_data = try creds.fetchedFromKeychain()
118118
updateFromKeychainItems(creds_data)
119119
logger?.trace("OAuth2", msg: "Client credentials updated from keychain: \(creds_data)")
@@ -123,7 +123,7 @@ open class OAuth2Securable: OAuth2Requestable {
123123
}
124124

125125
do {
126-
var toks = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForTokens)
126+
var toks = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForTokens, classes: storableTokenClasses())
127127
let toks_data = try toks.fetchedFromKeychain()
128128
updateFromKeychainItems(toks_data)
129129
logger?.trace("OAuth2", msg: "Tokens updated from keychain: \(toks_data)")
@@ -134,23 +134,27 @@ open class OAuth2Securable: OAuth2Requestable {
134134
}
135135

136136
/** Updates instance properties according to the items found in the given dictionary, which was found in the keychain. */
137-
func updateFromKeychainItems(_ items: [String: Any]) {
137+
func updateFromKeychainItems(_ items: [String: any Sendable]) {
138+
}
139+
140+
open func storableCredentialClasses() -> [AnyClass] {
141+
return []
138142
}
139143

140144
/**
141145
Items that should be stored when storing client credentials.
142146

143147
- returns: A dictionary with `String` keys and `Any` items
144148
*/
145-
open func storableCredentialItems() -> [String: Any]? {
149+
open func storableCredentialItems() -> [String: any Sendable]? {
146150
return nil
147151
}
148152

149153
/** Stores our client credentials in the keychain. */
150154
open func storeClientToKeychain() {
151155
if let items = storableCredentialItems() {
152156
logger?.debug("OAuth2", msg: "Storing client credentials to keychain")
153-
let keychain = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForClientCredentials, data: items)
157+
let keychain = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForClientCredentials, data: items, classes: storableCredentialClasses())
154158
do {
155159
try keychain.saveInKeychain()
156160
logger?.trace("OAuth2", msg: "Client credentials stored to keychain: \(items)")
@@ -161,20 +165,24 @@ open class OAuth2Securable: OAuth2Requestable {
161165
}
162166
}
163167

168+
open func storableTokenClasses() -> [AnyClass] {
169+
return []
170+
}
171+
164172
/**
165173
Items that should be stored when tokens are stored to the keychain.
166174

167175
- returns: A dictionary with `String` keys and `Any` items
168176
*/
169-
open func storableTokenItems() -> [String: Any]? {
177+
open func storableTokenItems() -> [String: any Sendable]? {
170178
return nil
171179
}
172180

173181
/** Stores our current token(s) in the keychain. */
174182
public func storeTokensToKeychain() {
175183
if let items = storableTokenItems() {
176184
logger?.debug("OAuth2", msg: "Storing tokens to keychain")
177-
let keychain = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForTokens, data: items)
185+
let keychain = OAuth2KeychainAccount(oauth2: self, account: keychainAccountForTokens, data: items, classes: storableTokenClasses())
178186
do {
179187
try keychain.saveInKeychain()
180188
logger?.trace("OAuth2", msg: "Tokens stored to keychain: \(items)")

0 commit comments

Comments
 (0)