diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift index f5956b1b34..79d1463904 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift @@ -62,8 +62,7 @@ struct RefreshUserPoolTokens: Action { guard let authenticationResult = response?.authenticationResult, let idToken = authenticationResult.idToken, - let accessToken = authenticationResult.accessToken, - let refreshToken = authenticationResult.refreshToken + let accessToken = authenticationResult.accessToken else { let event = RefreshSessionEvent(eventType: .throwError(.invalidTokens)) await dispatcher.send(event) @@ -74,7 +73,7 @@ struct RefreshUserPoolTokens: Action { let userPoolTokens = AWSCognitoUserPoolTokens( idToken: idToken, accessToken: accessToken, - refreshToken: refreshToken + refreshToken: authenticationResult.refreshToken ?? existingTokens.refreshToken ) let signedInData = SignedInData( diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift index 33aca27a08..aa118d3c72 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift @@ -185,43 +185,6 @@ class RefreshUserPoolTokensTests: XCTestCase { userPoolFactory: identityProviderFactory) ) - await fulfillment( - of: [expectation], - timeout: 0.1 - ) - } - func testRefreshTokenMissing() async { - - let expectation = expectation(description: "refreshTokenMissing") - let identityProviderFactory: BasicSRPAuthEnvironment.CognitoUserPoolFactory = { - MockIdentityProvider( - mockGetTokensFromRefreshTokenResponse: { _ in - return GetTokensFromRefreshTokenOutput( - authenticationResult: .init( - accessToken: "accessTokenNew", - expiresIn: 100, - idToken: "idTokenNew", - refreshToken: nil)) - } - ) - } - - let action = RefreshUserPoolTokens(existingSignedIndata: .testData) - - await action.execute( - withDispatcher: MockDispatcher { event in - - if let userPoolEvent = event as? RefreshSessionEvent, - case let .throwError(error) = userPoolEvent.eventType - { - XCTAssertEqual(error, .invalidTokens) - expectation.fulfill() - } - }, - environment: Defaults.makeDefaultAuthEnvironment( - userPoolFactory: identityProviderFactory) - ) - await fulfillment( of: [expectation], timeout: 0.1