Skip to content

Commit

Permalink
Deprecate reject method with Reject enum and replace it with String i…
Browse files Browse the repository at this point in the history
…nstead
  • Loading branch information
Hopsaheysa committed Jan 19, 2024
1 parent 4397eef commit 3f4a051
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ enum WMTOperationEndpoints {

enum Reject {
typealias EndpointType = WPNEndpointSigned<WPNRequest<WMTRejectionData>, 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<WPNRequest<WMTRejectionDataV2>, WPNResponseBase>
static let endpoint: EndpointType = WPNEndpointSigned(endpointURLPath: "/api/auth/token/app/operation/cancel", uriId: "/operation/cancel")
}

Expand Down
24 changes: 24 additions & 0 deletions WultraMobileTokenSDK/Operations/Service/WMTOperationsImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ class WMTOperationsImpl<T: WMTUserOperation>: WMTOperations, WMTService {
}
}

@available(*, deprecated, message: "WMTRejectionReason is deprecated. Use String reason instead")
func reject(operation: WMTOperation, with reason: WMTRejectionReason, completion: @escaping(Result<Void, WMTError>) -> Void) -> Operation? {

guard validateActivation(completion) else {
Expand All @@ -321,6 +322,29 @@ class WMTOperationsImpl<T: WMTUserOperation>: WMTOperations, WMTService {
}
}

func reject(operation: WMTOperation, reason: String, completion: @escaping(Result<Void, WMTError>) -> 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<String, WMTError>) -> Void) -> Operation {

let op = WPNAsyncBlockOperation { _, markFinished in
Expand Down
12 changes: 12 additions & 0 deletions WultraMobileTokenSDK/Operations/WMTOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, WMTError>) -> 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, WMTError>) -> Void) -> Operation?

/// If the service is polling operations
var isPollingOperations: Bool { get }

Expand Down
4 changes: 2 additions & 2 deletions WultraMobileTokenSDKTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion WultraMobileTokenSDKTests/NetworkingObjectsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions docs/Using-Operations-Service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f4a051

Please sign in to comment.