Skip to content

Commit e31b43c

Browse files
committed
make validateSession public
1 parent 4c9973b commit e31b43c

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

Sources/XcodesLoginKit/AuthenticationState.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
//
77

88

9-
public enum AuthenticationState: Equatable {
9+
public enum AuthenticationState: Equatable, Sendable {
1010
case unauthenticated
1111
case waitingForSecondFactor(TwoFactorOption, AuthOptionsResponse, AppleSessionData)
1212
case authenticated(AppleSession)
1313
case notAppleDeveloper
1414
}
1515

16-
public enum TwoFactorOption: Equatable {
16+
public enum TwoFactorOption: Equatable, Sendable {
1717
case smsSent(AuthOptionsResponse.TrustedPhoneNumber)
1818
case codeSent
1919
case smsPendingChoice
2020
case securityKey
2121
}
2222

2323
@preconcurrency
24-
public struct AuthOptionsResponse: Equatable, Decodable {
24+
public struct AuthOptionsResponse: Equatable, Decodable, Sendable {
2525
public let trustedPhoneNumbers: [TrustedPhoneNumber]?
2626
public let trustedDevices: [TrustedDevice]?
2727
public let securityCode: SecurityCodeInfo?
@@ -69,7 +69,7 @@ public struct AuthOptionsResponse: Equatable, Decodable {
6969
trustedPhoneNumbers?.count == 1 && canFallBackToSMS
7070
}
7171

72-
public struct TrustedPhoneNumber: Equatable, Decodable, Identifiable {
72+
public struct TrustedPhoneNumber: Equatable, Decodable, Identifiable, Sendable {
7373
public let id: Int
7474
public let numberWithDialCode: String
7575

@@ -79,7 +79,7 @@ public struct AuthOptionsResponse: Equatable, Decodable {
7979
}
8080
}
8181

82-
public struct TrustedDevice: Equatable, Decodable {
82+
public struct TrustedDevice: Equatable, Decodable, Sendable {
8383
public let id: String
8484
public let name: String
8585
public let modelName: String
@@ -91,7 +91,7 @@ public struct AuthOptionsResponse: Equatable, Decodable {
9191
}
9292
}
9393

94-
public struct SecurityCodeInfo: Equatable, Decodable {
94+
public struct SecurityCodeInfo: Equatable, Decodable, Sendable {
9595
public let length: Int
9696
public let tooManyCodesSent: Bool
9797
public let tooManyCodesValidated: Bool
@@ -118,7 +118,7 @@ public struct AuthOptionsResponse: Equatable, Decodable {
118118
}
119119
}
120120

121-
public struct AppleSessionData: Equatable, Identifiable {
121+
public struct AppleSessionData: Equatable, Identifiable, Sendable {
122122
public let serviceKey: String
123123
public let sessionID: String
124124
public let scnt: String
@@ -132,12 +132,12 @@ public struct AppleSessionData: Equatable, Identifiable {
132132
}
133133
}
134134

135-
public struct ServiceError: Decodable, Equatable {
135+
public struct ServiceError: Decodable, Equatable, Sendable {
136136
let code: String
137137
let message: String
138138
}
139139

140-
public struct FSAChallenge: Equatable, Decodable {
140+
public struct FSAChallenge: Equatable, Decodable, Sendable {
141141
public let challenge: String
142142
public let keyHandles: [String]
143143
public let allowedCredentials: String

Sources/XcodesLoginKit/Client.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public class Client {
8484

8585
switch httpResponse.statusCode {
8686
case 200:
87-
let authenticationSession: AppleSession = try await networkService.requestObject(URLRequest.olympusSession)
88-
return AuthenticationState.authenticated(authenticationSession)
87+
return try await self.validateSession()
8988
case 401:
9089
throw AuthenticationError.invalidUsernameOrPassword(username: accountName)
9190
case 403:
@@ -275,10 +274,11 @@ public class Client {
275274

276275
func updateSession(serviceKey: String, sessionID: String, scnt: String) async throws -> AuthenticationState {
277276
try await networkService.requestVoid(URLRequest.trust(serviceKey: serviceKey, sessionID: sessionID, scnt: scnt))
278-
return try await loadSession()
277+
return try await validateSession()
279278
}
280279

281-
func loadSession() async throws -> AuthenticationState {
280+
@MainActor
281+
public func validateSession() async throws -> AuthenticationState {
282282
let authenticationSession: AppleSession = try await networkService.requestObject(URLRequest.olympusSession)
283283
return AuthenticationState.authenticated(authenticationSession)
284284
}

0 commit comments

Comments
 (0)