Skip to content

Commit c5cb449

Browse files
committed
Reconfigure when fetching auth session if sharing keychain
1 parent f460f6a commit c5cb449

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior {
114114
public func fetchAuthSession(options: AuthFetchSessionRequest.Options?) async throws -> AuthSession {
115115
let options = options ?? AuthFetchSessionRequest.Options()
116116
let request = AuthFetchSessionRequest(options: options)
117-
let task = AWSAuthFetchSessionTask(request, authStateMachine: authStateMachine)
117+
let forceReconfigure = secureStoragePreferences?.accessGroup?.name != nil
118+
let task = AWSAuthFetchSessionTask(request,
119+
authStateMachine: authStateMachine,
120+
configuration: authConfiguration,
121+
forceReconfigure: forceReconfigure)
118122
return try await taskQueue.sync {
119123
return try await task.value
120124
} as! AuthSession

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthFetchSessionTask.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,29 @@ class AWSAuthFetchSessionTask: AuthFetchSessionTask, DefaultLogger {
1313
private let authStateMachine: AuthStateMachine
1414
private let fetchAuthSessionHelper: FetchAuthSessionOperationHelper
1515
private let taskHelper: AWSAuthTaskHelper
16+
private let configuration: AuthConfiguration
17+
private let forceReconfigure: Bool
1618

1719
var eventName: HubPayloadEventName {
1820
HubPayload.EventName.Auth.fetchSessionAPI
1921
}
2022

21-
init(_ request: AuthFetchSessionRequest, authStateMachine: AuthStateMachine) {
23+
init(_ request: AuthFetchSessionRequest, authStateMachine: AuthStateMachine, configuration: AuthConfiguration, forceReconfigure: Bool = false) {
2224
self.request = request
2325
self.authStateMachine = authStateMachine
2426
self.fetchAuthSessionHelper = FetchAuthSessionOperationHelper()
2527
self.taskHelper = AWSAuthTaskHelper(authStateMachine: authStateMachine)
28+
self.configuration = configuration
29+
self.forceReconfigure = forceReconfigure
2630
}
2731

2832
func execute() async throws -> AuthSession {
2933
log.verbose("Starting execution")
34+
if forceReconfigure {
35+
log.verbose("Reconfiguring auth state machine for keychain sharing")
36+
let event = AuthEvent(eventType: .reconfigure(configuration))
37+
await authStateMachine.send(event)
38+
}
3039
await taskHelper.didStateMachineConfigured()
3140
let doesNeedForceRefresh = request.options.forceRefresh
3241
return try await fetchAuthSessionHelper.fetch(authStateMachine,

0 commit comments

Comments
 (0)