diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift index a5d180b876..f5956b1b34 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift @@ -5,11 +5,11 @@ // SPDX-License-Identifier: Apache-2.0 // -import Amplify -import AWSPluginsCore import AWSCognitoIdentityProvider -import Foundation +import AWSPluginsCore +import Amplify import ClientRuntime +import Foundation struct RefreshUserPoolTokens: Action { @@ -28,7 +28,6 @@ struct RefreshUserPoolTokens: Action { return } - let authEnv = try environment.authEnvironment() let config = environment.userPoolConfiguration let client = try? environment.cognitoUserPoolFactory() let existingTokens = existingSignedIndata.cognitoUserPoolTokens @@ -37,29 +36,35 @@ struct RefreshUserPoolTokens: Action { for: existingSignedIndata.username, with: environment) - let asfDeviceId = try await CognitoUserPoolASF.asfDeviceID( - for: existingSignedIndata.username, - credentialStoreClient: authEnv.credentialsClient) + let deviceKey: String? = { + if case .metadata(let data) = deviceMetadata { + return data.deviceKey + } + return nil + }() - let input = await InitiateAuthInput.refreshAuthInput( - username: existingSignedIndata.username, - refreshToken: existingTokens.refreshToken, + let input = GetTokensFromRefreshTokenInput( + clientId: config.clientId, clientMetadata: [:], - asfDeviceId: asfDeviceId, - deviceMetadata: deviceMetadata, - environment: environment) + clientSecret: config.clientSecret, + deviceKey: deviceKey, + refreshToken: existingTokens.refreshToken + ) - logVerbose("\(#fileID) Starting initiate auth refresh token", environment: environment) + logVerbose( + "\(#fileID) Starting get tokens from refresh token", environment: environment) - let response = try await client?.initiateAuth(input: input) + let response = try await client?.getTokensFromRefreshToken(input: input) - logVerbose("\(#fileID) Initiate auth response received", environment: environment) + logVerbose( + "\(#fileID) Get tokens from refresh token response received", + environment: environment) guard let authenticationResult = response?.authenticationResult, - let idToken = authenticationResult.idToken, - let accessToken = authenticationResult.accessToken + let idToken = authenticationResult.idToken, + let accessToken = authenticationResult.accessToken, + let refreshToken = authenticationResult.refreshToken else { - let event = RefreshSessionEvent(eventType: .throwError(.invalidTokens)) await dispatcher.send(event) logVerbose("\(#fileID) Sending event \(event.type)", environment: environment) @@ -69,9 +74,9 @@ struct RefreshUserPoolTokens: Action { let userPoolTokens = AWSCognitoUserPoolTokens( idToken: idToken, accessToken: accessToken, - refreshToken: existingTokens.refreshToken, - expiresIn: authenticationResult.expiresIn + refreshToken: refreshToken ) + let signedInData = SignedInData( signedInDate: existingSignedIndata.signedInDate, signInMethod: existingSignedIndata.signInMethod, @@ -96,13 +101,14 @@ struct RefreshUserPoolTokens: Action { await dispatcher.send(event) } - logVerbose("\(#fileID) Initiate auth complete", environment: environment) + logVerbose("\(#fileID) Get tokens from refresh token complete", environment: environment) } } extension RefreshUserPoolTokens: DefaultLogger { public static var log: Logger { - Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) + Amplify.Logging.logger( + forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } public var log: Logger { @@ -114,7 +120,7 @@ extension RefreshUserPoolTokens: CustomDebugDictionaryConvertible { var debugDictionary: [String: Any] { [ "identifier": identifier, - "existingSignedInData": existingSignedIndata + "existingSignedInData": existingSignedIndata, ] } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/CognitoUserPoolBehavior.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/CognitoUserPoolBehavior.swift index 55efa75c81..65e6f980e7 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/CognitoUserPoolBehavior.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/CognitoUserPoolBehavior.swift @@ -29,6 +29,9 @@ protocol CognitoUserPoolBehavior { /// Throws RevokeTokenOutputError func revokeToken(input: RevokeTokenInput) async throws -> RevokeTokenOutput + /// Throws GetTokensFromRefreshTokenOutputError + func getTokensFromRefreshToken(input: GetTokensFromRefreshTokenInput) async throws -> GetTokensFromRefreshTokenOutput + // MARK: - User Attribute API's /// Throws GetUserAttributeVerificationCodeOutputError diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/InitiateAuthInput+Amplify.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/InitiateAuthInput+Amplify.swift index 166bec220c..5d0a279287 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/InitiateAuthInput+Amplify.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/InitiateAuthInput+Amplify.swift @@ -93,27 +93,6 @@ extension InitiateAuthInput { environment: environment) } - static func refreshAuthInput(username: String, - refreshToken: String, - clientMetadata: [String: String], - asfDeviceId: String, - deviceMetadata: DeviceMetadata, - environment: UserPoolEnvironment) async -> InitiateAuthInput { - - let authParameters = [ - "REFRESH_TOKEN": refreshToken - ] - - return await buildInput(username: username, - authFlowType: .refreshTokenAuth, - authParameters: authParameters, - clientMetadata: clientMetadata, - asfDeviceId: asfDeviceId, - deviceMetadata: deviceMetadata, - environment: environment) - - } - static func buildInput(username: String, authFlowType: CognitoIdentityProviderClientTypes.AuthFlowType, authParameters: [String: String], diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift index 1dbc164dff..33aca27a08 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ActionTests/FetchAuthSession/FetchUserPoolTokens/RefreshUserPoolTokensTests.swift @@ -5,10 +5,10 @@ // SPDX-License-Identifier: Apache-2.0 // -import XCTest -import Amplify -import AWSPluginsCore import AWSCognitoIdentityProvider +import AWSPluginsCore +import Amplify +import XCTest @testable import AWSCognitoAuthPlugin @@ -20,18 +20,19 @@ class RefreshUserPoolTokensTests: XCTestCase { let action = RefreshUserPoolTokens(existingSignedIndata: .testData) - await action.execute(withDispatcher: MockDispatcher { event in + await action.execute( + withDispatcher: MockDispatcher { event in - guard let event = event as? RefreshSessionEvent else { - return - } + guard let event = event as? RefreshSessionEvent else { + return + } - if case let .throwError(error) = event.eventType { - XCTAssertNotNil(error) - XCTAssertEqual(error, .noUserPool) - expectation.fulfill() - } - }, environment: MockInvalidEnvironment() + if case let .throwError(error) = event.eventType { + XCTAssertNotNil(error) + XCTAssertEqual(error, .noUserPool) + expectation.fulfill() + } + }, environment: MockInvalidEnvironment() ) await fulfillment( @@ -45,25 +46,27 @@ class RefreshUserPoolTokensTests: XCTestCase { let expectation = expectation(description: "refreshUserPoolTokens") let identityProviderFactory: BasicSRPAuthEnvironment.CognitoUserPoolFactory = { MockIdentityProvider( - mockInitiateAuthResponse: { _ in - return InitiateAuthOutput() + mockGetTokensFromRefreshTokenResponse: { _ in + return GetTokensFromRefreshTokenOutput() } ) } let action = RefreshUserPoolTokens(existingSignedIndata: .testData) - await action.execute(withDispatcher: MockDispatcher { event in + await action.execute( + withDispatcher: MockDispatcher { event in - guard let event = event as? RefreshSessionEvent else { return } + guard let event = event as? RefreshSessionEvent else { return } - if case let .throwError(error) = event.eventType { - XCTAssertNotNil(error) - XCTAssertEqual(error, .invalidTokens) - expectation.fulfill() - } - }, environment: Defaults.makeDefaultAuthEnvironment( - userPoolFactory: identityProviderFactory) + if case let .throwError(error) = event.eventType { + XCTAssertNotNil(error) + XCTAssertEqual(error, .invalidTokens) + expectation.fulfill() + } + }, + environment: Defaults.makeDefaultAuthEnvironment( + userPoolFactory: identityProviderFactory) ) await fulfillment( @@ -77,8 +80,8 @@ class RefreshUserPoolTokensTests: XCTestCase { let expectation = expectation(description: "refreshUserPoolTokens") let identityProviderFactory: BasicSRPAuthEnvironment.CognitoUserPoolFactory = { MockIdentityProvider( - mockInitiateAuthResponse: { _ in - return InitiateAuthOutput( + mockGetTokensFromRefreshTokenResponse: { _ in + return GetTokensFromRefreshTokenOutput( authenticationResult: .init( accessToken: "accessTokenNew", expiresIn: 100, @@ -90,14 +93,17 @@ class RefreshUserPoolTokensTests: XCTestCase { let action = RefreshUserPoolTokens(existingSignedIndata: .testData) - await action.execute(withDispatcher: MockDispatcher { event in + await action.execute( + withDispatcher: MockDispatcher { event in - if let userPoolEvent = event as? RefreshSessionEvent, - case .refreshIdentityInfo = userPoolEvent.eventType { - expectation.fulfill() - } - }, environment: Defaults.makeDefaultAuthEnvironment( - userPoolFactory: identityProviderFactory) + if let userPoolEvent = event as? RefreshSessionEvent, + case .refreshIdentityInfo = userPoolEvent.eventType + { + expectation.fulfill() + } + }, + environment: Defaults.makeDefaultAuthEnvironment( + userPoolFactory: identityProviderFactory) ) await fulfillment( @@ -114,7 +120,7 @@ class RefreshUserPoolTokensTests: XCTestCase { let identityProviderFactory: BasicSRPAuthEnvironment.CognitoUserPoolFactory = { MockIdentityProvider( - mockInitiateAuthResponse: { _ in + mockGetTokensFromRefreshTokenResponse: { _ in throw testError } ) @@ -128,15 +134,17 @@ class RefreshUserPoolTokensTests: XCTestCase { let action = RefreshUserPoolTokens(existingSignedIndata: .testData) - await action.execute(withDispatcher: MockDispatcher { event in + await action.execute( + withDispatcher: MockDispatcher { event in - if let userPoolEvent = event as? RefreshSessionEvent, - case let .throwError(error) = userPoolEvent.eventType { - XCTAssertNotNil(error) - XCTAssertEqual(error, .service(testError)) - expectation.fulfill() - } - }, environment: environment) + if let userPoolEvent = event as? RefreshSessionEvent, + case let .throwError(error) = userPoolEvent.eventType + { + XCTAssertNotNil(error) + XCTAssertEqual(error, .service(testError)) + expectation.fulfill() + } + }, environment: environment) await fulfillment( of: [expectation], @@ -144,4 +152,79 @@ class RefreshUserPoolTokensTests: XCTestCase { ) } + func testRefreshTokenRotation() async { + + let expectation = expectation(description: "refreshTokenRotation") + let identityProviderFactory: BasicSRPAuthEnvironment.CognitoUserPoolFactory = { + MockIdentityProvider( + mockGetTokensFromRefreshTokenResponse: { _ in + return GetTokensFromRefreshTokenOutput( + authenticationResult: .init( + accessToken: "accessTokenNew", + expiresIn: 100, + idToken: "idTokenNew", + refreshToken: "refreshTokenRotated")) + } + ) + } + + let action = RefreshUserPoolTokens(existingSignedIndata: .testData) + + await action.execute( + withDispatcher: MockDispatcher { event in + + if let userPoolEvent = event as? RefreshSessionEvent, + case let .refreshIdentityInfo(signedInData, _) = userPoolEvent.eventType + { + XCTAssertEqual( + signedInData.cognitoUserPoolTokens.refreshToken, "refreshTokenRotated") + expectation.fulfill() + } + }, + environment: Defaults.makeDefaultAuthEnvironment( + 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 + ) + } } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift index dda11d4521..29e78663e5 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/HubEventTests/AuthHubEventHandlerTests.swift @@ -423,7 +423,7 @@ class AuthHubEventHandlerTests: XCTestCase { .notStarted) let mockIdentityProvider = MockIdentityProvider( - mockInitiateAuthResponse: { _ in + mockGetTokensFromRefreshTokenResponse: { _ in throw AWSCognitoIdentityProvider.NotAuthorizedException() }) diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/MockIdentityProvider.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/MockIdentityProvider.swift index b229705b56..dc1b6e71a7 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/MockIdentityProvider.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/MockIdentityProvider.swift @@ -20,6 +20,9 @@ struct MockIdentityProvider: CognitoUserPoolBehavior { typealias MockInitiateAuthResponse = (InitiateAuthInput) async throws -> InitiateAuthOutput + typealias MockGetTokensFromRefreshTokenResponse = (GetTokensFromRefreshTokenInput) async throws + -> GetTokensFromRefreshTokenOutput + typealias MockConfirmSignUpResponse = (ConfirmSignUpInput) async throws -> ConfirmSignUpOutput @@ -88,6 +91,7 @@ struct MockIdentityProvider: CognitoUserPoolBehavior { let mockSignUpResponse: MockSignUpResponse? let mockRevokeTokenResponse: MockRevokeTokenResponse? let mockInitiateAuthResponse: MockInitiateAuthResponse? + let mockGetTokensFromRefreshTokenResponse: MockGetTokensFromRefreshTokenResponse? let mockGlobalSignOutResponse: MockGlobalSignOutResponse? let mockConfirmSignUpResponse: MockConfirmSignUpResponse? let mockRespondToAuthChallengeResponse: MockRespondToAuthChallengeResponse? @@ -116,6 +120,7 @@ struct MockIdentityProvider: CognitoUserPoolBehavior { mockSignUpResponse: MockSignUpResponse? = nil, mockRevokeTokenResponse: MockRevokeTokenResponse? = nil, mockInitiateAuthResponse: MockInitiateAuthResponse? = nil, + mockGetTokensFromRefreshTokenResponse: MockGetTokensFromRefreshTokenResponse? = nil, mockGlobalSignOutResponse: MockGlobalSignOutResponse? = nil, mockConfirmSignUpResponse: MockConfirmSignUpResponse? = nil, mockRespondToAuthChallengeResponse: MockRespondToAuthChallengeResponse? = nil, @@ -139,6 +144,7 @@ struct MockIdentityProvider: CognitoUserPoolBehavior { self.mockSignUpResponse = mockSignUpResponse self.mockRevokeTokenResponse = mockRevokeTokenResponse self.mockInitiateAuthResponse = mockInitiateAuthResponse + self.mockGetTokensFromRefreshTokenResponse = mockGetTokensFromRefreshTokenResponse self.mockGlobalSignOutResponse = mockGlobalSignOutResponse self.mockConfirmSignUpResponse = mockConfirmSignUpResponse self.mockRespondToAuthChallengeResponse = mockRespondToAuthChallengeResponse @@ -192,6 +198,11 @@ struct MockIdentityProvider: CognitoUserPoolBehavior { return try await mockRevokeTokenResponse!(input) } + /// Throws GetTokensFromRefreshTokenOutputError + func getTokensFromRefreshToken(input: GetTokensFromRefreshTokenInput) async throws -> GetTokensFromRefreshTokenOutput { + return try await mockGetTokensFromRefreshTokenResponse!(input) + } + func getUserAttributeVerificationCode(input: GetUserAttributeVerificationCodeInput) async throws -> GetUserAttributeVerificationCodeOutput { return try await mockGetUserAttributeVerificationCodeOutput!(input) } diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/AuthorizationTests/AWSAuthFetchSignInSessionOperationTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/AuthorizationTests/AWSAuthFetchSignInSessionOperationTests.swift index 7373a81917..90d56ee17c 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/AuthorizationTests/AWSAuthFetchSignInSessionOperationTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/AuthorizationTests/AWSAuthFetchSignInSessionOperationTests.swift @@ -95,9 +95,9 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AuthorizationState.sessionEstablished( AmplifyCredentials.testData), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in + let getTokensFromRefreshToken: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in resultExpectation.fulfill() - return InitiateAuthOutput(authenticationResult: .init( + return GetTokensFromRefreshTokenOutput(authenticationResult: .init( accessToken: "accessToken", expiresIn: 1000, idToken: "idToken", @@ -115,7 +115,7 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { } let plugin = configurePluginWith( - userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, + userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: getTokensFromRefreshToken) }, identityPool: { MockIdentity(mockGetCredentialsResponse: awsCredentials) }, initialState: initialState) let session = try await plugin.fetchAuthSession(options: .forceRefresh()) @@ -212,11 +212,11 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AmplifyCredentials.testDataWithExpiredTokens), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in + let getTokensFromRefreshToken: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in throw AWSCognitoIdentityProvider.NotAuthorizedException() } - let plugin = configurePluginWith(userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, initialState: initialState) + let plugin = configurePluginWith(userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: getTokensFromRefreshToken) }, initialState: initialState) let session = try await plugin.fetchAuthSession(options: AuthFetchSessionRequest.Options()) XCTAssertTrue(session.isSignedIn) @@ -261,8 +261,8 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AmplifyCredentials.testDataWithExpiredTokens), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in - return InitiateAuthOutput(authenticationResult: .init(accessToken: "accessToken", + let getTokensFromRefreshToken: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in + return GetTokensFromRefreshTokenOutput(authenticationResult: .init(accessToken: "accessToken", expiresIn: 1000, idToken: "idToken", refreshToken: "refreshToke")) @@ -273,7 +273,7 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { } let plugin = configurePluginWith( - userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, + userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: getTokensFromRefreshToken) }, identityPool: { MockIdentity(mockGetCredentialsResponse: awsCredentials) }, initialState: initialState) @@ -494,15 +494,15 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AmplifyCredentials.testDataWithExpiredTokens), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in - return InitiateAuthOutput(authenticationResult: .init(accessToken: nil, + let refreshTokenAuth: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in + return GetTokensFromRefreshTokenOutput(authenticationResult: .init(accessToken: nil, expiresIn: 1000, idToken: "idToken", refreshToken: "refreshToke")) } let plugin = configurePluginWith( - userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, + userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: refreshTokenAuth) }, initialState: initialState) let session = try await plugin.fetchAuthSession(options: AuthFetchSessionRequest.Options()) @@ -548,8 +548,8 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AmplifyCredentials.testDataWithExpiredTokens), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in - return InitiateAuthOutput(authenticationResult: .init(accessToken: "accessToken", + let refreshTokenAuth: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in + return GetTokensFromRefreshTokenOutput(authenticationResult: .init(accessToken: "accessToken", expiresIn: 1000, idToken: "idToken", refreshToken: "refreshToke")) @@ -559,7 +559,7 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { return GetCredentialsForIdentityOutput(credentials: nil, identityId: "ss") } let plugin = configurePluginWith( - userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, + userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: refreshTokenAuth) }, identityPool: { MockIdentity(mockGetCredentialsResponse: awsCredentials) }, initialState: initialState) @@ -714,12 +714,12 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AmplifyCredentials.testDataWithExpiredTokens), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in + let refreshTokenAuth: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in throw AWSCognitoIdentityProvider.NotAuthorizedException(message: "NotAuthorized") } let plugin = configurePluginWith( - userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, + userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: refreshTokenAuth) }, initialState: initialState) let session = try await plugin.fetchAuthSession(options: AuthFetchSessionRequest.Options()) @@ -816,8 +816,8 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { AmplifyCredentials.testDataWithExpiredTokens), .notStarted) - let initAuth: MockIdentityProvider.MockInitiateAuthResponse = { _ in - return InitiateAuthOutput(authenticationResult: .init(accessToken: "accessToken", + let refreshTokenAuth: MockIdentityProvider.MockGetTokensFromRefreshTokenResponse = { _ in + return GetTokensFromRefreshTokenOutput(authenticationResult: .init(accessToken: "accessToken", expiresIn: 1000, idToken: "idToken", refreshToken: "refreshToke")) @@ -827,7 +827,7 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests { throw NSError(domain: NSURLErrorDomain, code: 1, userInfo: nil) } let plugin = configurePluginWith( - userPool: { MockIdentityProvider(mockInitiateAuthResponse: initAuth) }, + userPool: { MockIdentityProvider(mockGetTokensFromRefreshTokenResponse: refreshTokenAuth) }, identityPool: { MockIdentity(mockGetCredentialsResponse: awsCredentials) }, initialState: initialState) diff --git a/Package.resolved b/Package.resolved index b145620421..b1ec33ad5e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/awslabs/aws-sdk-swift", "state" : { - "revision" : "f812c7441555058da0fcecf5314780c1770b11a1", - "version" : "1.5.14" + "revision" : "8b5336764297d34157bd580374b5f6e182746759", + "version" : "1.5.18" } }, { @@ -77,8 +77,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/smithy-lang/smithy-swift", "state" : { - "revision" : "85bfbaff8a77ffc0415878de50186e6cfea30a04", - "version" : "0.151.0" + "revision" : "a6cac0739d76ef08e2d927febc682d9898e76fe2", + "version" : "0.152.0" } }, { diff --git a/Package.swift b/Package.swift index 5d5b87709a..d0667c7d8d 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,7 @@ let platforms: [SupportedPlatform] = [ .watchOS(.v9) ] let dependencies: [Package.Dependency] = [ - .package(url: "https://github.com/awslabs/aws-sdk-swift", exact: "1.5.14"), + .package(url: "https://github.com/awslabs/aws-sdk-swift", exact: "1.5.18"), .package(url: "https://github.com/stephencelis/SQLite.swift.git", exact: "0.15.3"), .package(url: "https://github.com/mattgallagher/CwlPreconditionTesting.git", from: "2.1.0"), .package(url: "https://github.com/aws-amplify/amplify-swift-utils-notifications.git", from: "1.1.0")