From 3f4a05140be3d4387fbe48572d5e4779e1c7a7a1 Mon Sep 17 00:00:00 2001 From: Marek Stransky Date: Fri, 19 Jan 2024 15:26:09 +0100 Subject: [PATCH] Deprecate reject method with Reject enum and replace it with String instead --- .../Model/Requests/WMTRejectionData.swift | 15 ++++++++++++ .../Service/WMTOperationEndpoints.swift | 6 +++++ .../Service/WMTOperationsImpl.swift | 24 +++++++++++++++++++ .../Operations/WMTOperations.swift | 12 ++++++++++ .../IntegrationTests.swift | 4 ++-- .../NetworkingObjectsTests.swift | 2 +- docs/Using-Operations-Service.md | 4 ++-- 7 files changed, 62 insertions(+), 5 deletions(-) diff --git a/WultraMobileTokenSDK/Operations/Model/Requests/WMTRejectionData.swift b/WultraMobileTokenSDK/Operations/Model/Requests/WMTRejectionData.swift index 8fab115..97fd0e4 100644 --- a/WultraMobileTokenSDK/Operations/Model/Requests/WMTRejectionData.swift +++ b/WultraMobileTokenSDK/Operations/Model/Requests/WMTRejectionData.swift @@ -30,3 +30,18 @@ class WMTRejectionData: Codable { self.reason = reason } } + +/// Backend payload +class WMTRejectionDataV2: Codable { + + /// Operation id + let id: String + + /// Rejection reason + let reason: String + + init(operationId: String, reason: String) { + self.id = operationId + self.reason = reason + } +} diff --git a/WultraMobileTokenSDK/Operations/Service/WMTOperationEndpoints.swift b/WultraMobileTokenSDK/Operations/Service/WMTOperationEndpoints.swift index 5e8ba54..da94610 100644 --- a/WultraMobileTokenSDK/Operations/Service/WMTOperationEndpoints.swift +++ b/WultraMobileTokenSDK/Operations/Service/WMTOperationEndpoints.swift @@ -36,6 +36,12 @@ enum WMTOperationEndpoints { enum Reject { typealias EndpointType = WPNEndpointSigned, WPNResponseBase> + @available(*, deprecated, message: "Reject is deprecated. Use RejectV2 instead") + static let endpoint: EndpointType = WPNEndpointSigned(endpointURLPath: "/api/auth/token/app/operation/cancel", uriId: "/operation/cancel") + } + + enum RejectV2 { + typealias EndpointType = WPNEndpointSigned, WPNResponseBase> static let endpoint: EndpointType = WPNEndpointSigned(endpointURLPath: "/api/auth/token/app/operation/cancel", uriId: "/operation/cancel") } diff --git a/WultraMobileTokenSDK/Operations/Service/WMTOperationsImpl.swift b/WultraMobileTokenSDK/Operations/Service/WMTOperationsImpl.swift index 5e9e186..e2d0a9b 100644 --- a/WultraMobileTokenSDK/Operations/Service/WMTOperationsImpl.swift +++ b/WultraMobileTokenSDK/Operations/Service/WMTOperationsImpl.swift @@ -298,6 +298,7 @@ class WMTOperationsImpl: WMTOperations, WMTService { } } + @available(*, deprecated, message: "WMTRejectionReason is deprecated. Use String reason instead") func reject(operation: WMTOperation, with reason: WMTRejectionReason, completion: @escaping(Result) -> Void) -> Operation? { guard validateActivation(completion) else { @@ -321,6 +322,29 @@ class WMTOperationsImpl: WMTOperations, WMTService { } } + func reject(operation: WMTOperation, reason: String, completion: @escaping(Result) -> Void) -> Operation? { + + guard validateActivation(completion) else { + return nil + } + + return networking.post( + data: .init(.init(operationId: operation.id, reason: reason)), + signedWith: .possession(), + to: WMTOperationEndpoints.RejectV2.endpoint + ) { response, error in + self.processResult(response: response, error: error) { result in + switch result { + case .success: + self.operationsRegister.remove(operation: operation) + completion(.success(())) + case .failure(let err): + completion(.failure(self.adjustOperationError(err, auth: false))) + } + } + } + } + func authorize(qrOperation: WMTQROperation, uriId: String, authentication: PowerAuthAuthentication, completion: @escaping(Result) -> Void) -> Operation { let op = WPNAsyncBlockOperation { _, markFinished in diff --git a/WultraMobileTokenSDK/Operations/WMTOperations.swift b/WultraMobileTokenSDK/Operations/WMTOperations.swift index 7d19638..443b12b 100644 --- a/WultraMobileTokenSDK/Operations/WMTOperations.swift +++ b/WultraMobileTokenSDK/Operations/WMTOperations.swift @@ -130,8 +130,20 @@ public protocol WMTOperations: AnyObject { /// This completion is always called on the main thread. /// - Returns: Operation object for its state observation. @discardableResult + @available(*, deprecated, message: "WMTRejectionReason is deprecated. Use method with String reason instead") func reject(operation: WMTOperation, with: WMTRejectionReason, completion: @escaping(Result) -> Void) -> Operation? + /// Reject operation with a reason. + /// + /// - Parameters: + /// - operation: Operation that should be rejected. + /// - reason: Reason for the rejection. + /// - completion: Result callback. + /// This completion is always called on the main thread. + /// - Returns: Operation object for its state observation. + @discardableResult + func reject(operation: WMTOperation, reason: String, completion: @escaping(Result) -> Void) -> Operation? + /// If the service is polling operations var isPollingOperations: Bool { get } diff --git a/WultraMobileTokenSDKTests/IntegrationTests.swift b/WultraMobileTokenSDKTests/IntegrationTests.swift index 137fdaf..80b7c5f 100644 --- a/WultraMobileTokenSDKTests/IntegrationTests.swift +++ b/WultraMobileTokenSDKTests/IntegrationTests.swift @@ -341,7 +341,7 @@ class IntegrationTests: XCTestCase { exp.fulfill() return } - self.ops.reject(operation: opToReject, with: .unexpectedOperation) { result in + self.ops.reject(operation: opToReject, reason: "UNEXPECTED_OPERATION") { result in if case .failure(let error) = result { XCTFail("Failed to reject op: \(error.description)") } @@ -577,7 +577,7 @@ class IntegrationTests: XCTestCase { } self.ops.delegate = d3 - self.ops.reject(operation: ops[0], with: .unknown) { result in + self.ops.reject(operation: ops[0], reason: "UNKNOWN") { result in switch result { case .failure(let error): diff --git a/WultraMobileTokenSDKTests/NetworkingObjectsTests.swift b/WultraMobileTokenSDKTests/NetworkingObjectsTests.swift index f02018e..3975fa6 100644 --- a/WultraMobileTokenSDKTests/NetworkingObjectsTests.swift +++ b/WultraMobileTokenSDKTests/NetworkingObjectsTests.swift @@ -340,7 +340,7 @@ class NetworkingObjectsTests: XCTestCase { {"requestObject":{"id":"95e51995-fa60-4018-bd87-43a58f098570","reason":"UNEXPECTED_OPERATION"}} """ - let request = WMTOperationEndpoints.Reject.EndpointType.RequestData(.init(operationId: "95e51995-fa60-4018-bd87-43a58f098570", reason: .unexpectedOperation)) + let request = WMTOperationEndpoints.RejectV2.EndpointType.RequestData(.init(operationId: "95e51995-fa60-4018-bd87-43a58f098570", reason: "UNEXPECTED_OPERATION")) request.testSerialization(expectation: expectation) } diff --git a/docs/Using-Operations-Service.md b/docs/Using-Operations-Service.md index 9740dc2..1cf6e7f 100644 --- a/docs/Using-Operations-Service.md +++ b/docs/Using-Operations-Service.md @@ -194,14 +194,14 @@ func approveWithBiometry(operation: WMTOperation) { ## Reject an Operation -To reject an operation use `WMTOperations.reject`. Operation rejection is confirmed by possession factor so there is no need for creating `PowerAuthAuthentication` object. You can simply use it with the following example. +To reject an operation use `WMTOperations.reject`. Operation rejection is confirmed by a possession factor, so there is no need for creating a `PowerAuthAuthentication` object. You can simply use it with the following example. ```swift import WultraMobileTokenSDK import PowerAuth2 // Reject operation with some reason -func reject(operation: WMTOperation, reason: WMTRejectionReason) { +func reject(operation: WMTOperation, reason: String) { operationService.reject(operation: operation, reason: reason) { error in if let error = error { // show error UI