CLASS
HaapiTokenManagerBuilder
Contents
- Methods
init(tokenEndpoint:clientId:)setName(_:)setInternalUrlSession(_:)setHaapiTokenMinTtl(_:)disableDeviceCheckAttestation()setAttestationMaxRetryCount(maxRetries:)build()
@objcMembers public class HaapiTokenManagerBuilder: NSObject
The HaapiTokenManagerBuilder is used to instantiate a HaapiTokenManager with the settings
that are appropriate for your environment by using the Builder pattern.
An example use of the Builder to create a default HaapiTokenManager could look like this:
let urlSession = URLSession(configuration: configuration, delegate: trustAllCertsDelegate, delegateQueue: nil)
haapiTokenManager = HaapiTokenManagerBuilder(
tokenEndpoint: "https://my.curity.example.com/oauth/token",
clientId: "my-haapi-client"
)
.setInternalUrlSession(urlSession)
.build()
Methods
init(tokenEndpoint:clientId:)
public init (tokenEndpoint: URL,
clientId: String)
Initialize the Builder with the mandatory tokenEndpoint and clientId parameters
setName(_:)
public func setName(_ name: String) -> HaapiTokenManagerBuilder
Set a name for the HaapiTokenManager. The name is used as prefix in identifying the storage location where the HaapiTokenManager persists state.
When nothing is set, a default of "haapi" is used as name.
- Note: You cannot use two
HaapiTokenManagerinstances with the same name. If this condition is not fulfill, an exception is thrown when build is invoked.
setInternalUrlSession(_:)
public func setInternalUrlSession(_ urlSession: URLSession) -> HaapiTokenManagerBuilder
Set the URLSession instance that is used to make requests to the HAAPI services (e.g. the token endpoint and the HAAPI-enabled endpoints of the server)
When nothing is set, a URLSession with default settings is used.
setHaapiTokenMinTtl(_:)
public func setHaapiTokenMinTtl(_ minTtl: TimeInterval) -> HaapiTokenManagerBuilder
Set the minimum time to live (in seconds) that the HAAPI Token must be valid for. If the token expires before then, the HaapiTokenManager will try to refresh it.
When nothing is set, a value of 10 is used as minimum time to live
- Note: If
minTtlis lower or equal to 0 then an exception is thrown when build is invoked.
disableDeviceCheckAttestation()
public func disableDeviceCheckAttestation() -> HaapiTokenManagerBuilder
Allows the created HaapiTokenManager to run on a similator by turning off DeviceCheck attestation/-assertion.
When the compilation target is a simulator, DeviceCheck attestation/-assertion is automatically disabled.
This feature requires the server to be configured to have attestation validation disabled for this client.
setAttestationMaxRetryCount(maxRetries:)
public func setAttestationMaxRetryCount(maxRetries: Int) -> HaapiTokenManagerBuilder
Set the maximum allowed retry count for attestation/assertion retries. It allows the created HaapiTokenManager to retry DeviceCheck attestation/assertion
when receiving a DCError.serverUnavailable.
- Note:
DeviceCheckattestation API can sometimes fail and return an error due to device roaming networks or poor connectivity.
When nothing is set, a value of 3 is used as the maximum allowed retry count. Providing a value lower than 1 disables the retry mechanism.
build()
public func build() throws -> HaapiTokenManager
Build a new HaapiTokenManager instance from the state that is created inside the Builder
This method can abort your application if the desired name for a HaapiTokenManager already exists within the current context.
- Throws:
HaapiErrorif the configuration is incorrect.