CLASS

HaapiClient

Contents

public class HaapiClient: NSObject

The HaapiClient class makes it easier to interact with the HAAPi services of a remote host. It interacts with given HaapiTokenManager to be able to send requests that respect the HAAPI protocol (e.g. by including the HAAPI Content Type headers, the HAAPI session request header, applying DPoP to authenticate requests with the negotiated key, etc.)

The HaapiClient instance keeps tracks of a session that the client has with the HAAPI server, and will use it as needed to ensure that requests are being made within the correct session context.

A HaapiClient instance is always bound to a HaapiTokenManager. As such, it is recommended to use the HaapiTokenManager.createClient() method to create a new instance of a HaapiClient, for example:

haapiTokenManager = HaapiTokenManagerBuilder(
   tokenEndpoint: "https://curity.example.com/oauth/token"
   clientId: "my-oauth-client-id"
).build()
let haapiClient = manager.createClient()

The coupling between the HaapiClient and the HaapiTokenManager is weak, such that the HaapiClient is not aware when the coupled HaapiTokenManager is destroyed or closed. It is for this reason that the HaapiClient can return failures caused by a reference to a no-longer valid HaapiTokenManager.

Properties

dpop

public var dpop: Dpop?

The Dpop that was used when communicating to the server via the HaapiTokenManager.

Methods

performDataTask(for:completionHandler:)

public func performDataTask(
    for urlRequest: URLRequest,
    completionHandler: @escaping (Result<ResponseAndData, Error>) -> Void
)

Let the HaapiClient perform the given request as a HAAPI request asynchronously. The result of the request can be processed by a completion handler that can be given to this method.

The method can fail when the HaapiTokenManager that this client is referencing, no longer exists or is in a valid state. This will be represented by passing a HaapiError.haapiTokenManagerIsExpired or HaapiError.haapiTokenManagerIsClosed error Result to the completion handler.

Parameters

Name Description
urlRequest the request to make as HAAPI request
completionHandler a handler that takes the (success or error) response to process it

performDataTask(for:completionHandler:)

Let the HaapiClient perform the given request as a HAAPI request asynchronously. The result of the request can be processed by a completion handler that can be given to this method.

The method can fail when the HaapiTokenManager that this client is referencing, no longer exists or is in an invalid state. This will be represented by passing a HaapiError.haapiTokenManagerIsExpired or HaapiError.haapiTokenManagerIsClosed error Result to the completion handler.