CLASS
HaapiAccessorBuilder
Contents
- Methods
init(haapiConfiguration:)
setHaapiAccessorOption(option:)
setDCRConfiguration(configuration:)
build(shouldClearExistingDCRClient:completionHandler:)
build(shouldClearExistingDCRClient:)
@objcMembers public final class HaapiAccessorBuilder: NSObject
HaapiAccessorBuilder allows obtaining the accessors to access HAAPI from the current device, based on an initial static configuration and the device capabilities.
The preferred access strategy is to obtain HAAPI access tokens using client attestation, i.e. the device’s key attestation capabilities. If attestation is not supported, or if the Curity Identity Server deems the attestation data as invalid, an optional fallback strategy based on Dynamic Client Registration can be used.
The DCR-based fallback uses templatized client registration: the client configured in [haapiConfiguration] is used to register a dynamic client based on a template ID configured via [setDcrConfiguration]. The registration happens on the first time the fallback is used for a given template client ID. The resulting client data is stored on the device and considered by [HaapiAccessorBuilder] on subsequent runs.
The HaapiAccessor instances created by this class include:
- A ready-to-use HaapiManager to execute authorization flows.
- A ready-to-use OAuthTokenManager to execute OAuth requests like refreshToken and revoke.
When the DCR-based access is used, these credentials will be different from what’s supplied in the initial configuration.
The recommended way to use [HaapiAccessorBuilder] is to create a single instance and invoke build
once before going through an authorization flow via HAAPI.
let haapiConfiguration: HaapiConfiguration = ...
let dcrConfiguration: DcrConfiguration = ...
let haapiAccessor = HaapiAccessorBuilder(haapiConfiguration)
.setDcrConfiguration(dcrConfiguration)
.build()
// HAAPI flow
let haapiManager: HaapiManager = haapiAccessor.haapiManager
haapiManager.start()
// ... haapiManager.submit/follow ...
// Fetch token with OAuthTokenManager
let oAuthTokenManager: OAuthTokenManager = haapiAccessor.oAuthTokenManager
... oAuthTokenManager.fetch/refresh ...
Methods
init(haapiConfiguration:)
@objc public init(haapiConfiguration: HaapiConfiguration)
Creates an instance of HaapiManager based on the provided HaapiConfigurable
.
- Parameters:
- haapiConfiguration: The configuration used to build this instance.
Parameters
Name | Description |
---|---|
haapiConfiguration | The configuration used to build this instance. |
setHaapiAccessorOption(option:)
public func setHaapiAccessorOption(option: HaapiAccessorOption) -> HaapiAccessorBuilder
Set the option that instructs which HaapiAccessor
members are to be created. By defaulf value is HaapiAccessorOption.all
.
- Parameter option: The new HaapiAccessorOption setting.
Parameters
Name | Description |
---|---|
option | The new HaapiAccessorOption setting. |
setDCRConfiguration(configuration:)
public func setDCRConfiguration(configuration: DCRConfiguration) -> HaapiAccessorBuilder
Set the dcr configuration to use. By default, it is set to nil.
- Parameter configuration: The dcr configuration to use.
Parameters
Name | Description |
---|---|
configuration | The dcr configuration to use. |
build(shouldClearExistingDCRClient:completionHandler:)
public func build<T: HaapiManagerAccessor>(shouldClearExistingDCRClient: Bool = false,
completionHandler: @escaping (Result<T, HaapiError>) -> Void)
Creates a HaapiManagerAccessor
. It will check if the device supports key-attestation or not and it will return a configured HaapiAccessor
.
-
Parameters:
- shouldClearExistingDCRClient: Instructs the framework to clear the existing Dcr Client.
False
is the default value. - completionHandler: a handler that takes the (success or error) response to process it.
- shouldClearExistingDCRClient: Instructs the framework to clear the existing Dcr Client.
-
Note: This method should be invoked only once for any configuration. If it has to be invoked multiple times for the same configuration and
HaapiAccessorOption.all
was configured, be sure to invokeHaapiAccessor.close
before invokingbuild
again otherwise anHaapiError.haapiTokenManagerAlreadyExists
is returned.
Parameters
Name | Description |
---|---|
shouldClearExistingDCRClient | Instructs the framework to clear the existing Dcr Client. False is the default value. |
completionHandler | a handler that takes the (success or error) response to process it. |
build(shouldClearExistingDCRClient:)
public func build<T: HaapiManagerAccessor>(shouldClearExistingDCRClient: Bool = false) async throws -> T
Creates a HaapiManagerAccessor
. It will check if the device supports key-attestation or not and it will return a configured HaapiAccessor
.
This method should be invoked only once. If it has to be invoked multiple times for the same configuration and HaapiAccessorOption.all
was configured, be sure to invoke HaapiManager.close
before invoking build
again.
- Parameter shouldClearExistingDCRClient: Instructs the framework to clear the existing Dcr Client.
False
is the default value. - Throws: An HaapiError is thrown if any error occurs while instantiating the Haapi and OAuth for the provided configuration.
- Note: This method should be invoked only once for any configuration. If it has to be invoked multiple times for the same configuration and
HaapiAccessorOption.all
was configured, be sure to invokeHaapiAccessor.close
before invokingbuild
again otherwise anHaapiError.haapiTokenManagerAlreadyExists
is returned.
Parameters
Name | Description |
---|---|
shouldClearExistingDCRClient | Instructs the framework to clear the existing Dcr Client. False is the default value. |