EXTENSION
HaapiTokenManager
public extension HaapiTokenManager
Methods
createClient()
func createClient() -> HaapiClient
Create a HaapiClient instance that uses the HaapiTokenManager's state (e.g. the HAAPI token and ...)  for building outbound requests.
- Note: When creating the 
HaapiClientit will use the URLSession provided by the internal HaapiTokenManager. This allows for internal management of the DPop nonces and Client Authentication Method. 
getHaapiToken(forceFresh:dpopNonce:completionHandler:)
Obtains a HAAPI token. Takes a completionHandler that is executed after the HAAPI token is obtained or an error occurred.
- Parameter forceFresh: The boolean to indicate whether a new HAAPI token should be obtained even when the internal state already has a valid HAAPI token it can use. The default value is 
false. - Parameter dpopNonce:The most recent DPoP nonce. Any Identity Server responses may contain a DPoP-Nonce header with a nonce string. This nonce needs be provided to all subsequent calls to this method.
 - Parameter completionHandler:The handler that is called on the main thread after a HAAPI token was successfully obtained or an HaapiError occured.
 
getHaapiToken(forceFresh:completionHandler:)
Obtains a HAAPI token. Takes a completionHandler that is executed after the HAAPI token is obtained or an error occurred.
- Parameter forceFresh: The boolean to indicate whether a new HAAPI token should be obtained even when the internal state already has a valid HAAPI token it can use. The default value is 
false. - Parameter completionHandler:The handler that is called on the main thread after a HAAPI token was successfully obtained or an HaapiError occured.
 
getHaapiTokenAsync(forceFresh:dpopNonce:)
func getHaapiTokenAsync(forceFresh: Bool = false, dpopNonce: String? = nil) async throws -> DpopAccessTokenInfo
Obtains asynchronously a HAAPI token.
- Parameter forceFresh: The boolean to indicate whether a new HAAPI token should be obtained even when the internal state already has a valid HAAPI token it can use. The default value is 
false. - Parameter dpopNonce:The most recent DPoP nonce. Any Identity Server responses may contain a DPoP-Nonce header with a nonce string. This nonce needs be provided to all subsequent calls to this method.
 - Throws: 
HaapiError - Returns: A 
DpopAccessTokenInfo. - Important: The DpopAccessTokenInfo is returned on the calling thread.
 
Parameters
| Name | Description | 
|---|---|
| forceFresh | The boolean to indicate whether a new HAAPI token should be obtained even when the internal state already has a valid HAAPI token it can use. The default value is false. | 
| dpopNonce | The most recent DPoP nonce. Any Identity Server responses may contain a DPoP-Nonce header with a nonce string. This nonce needs be provided to all subsequent calls to this method. | 
getHaapiToken(forceFresh:dpopNonce:completionHandler:)
func getHaapiToken(forceFresh: Bool = false,
                   dpopNonce: String? = nil,
                   completionHandler: @escaping @Sendable (Result<DpopAccessTokenInfo, HaapiError>) -> Void)
Obtain a HAAPI token. Takes a completionHandler that is executed after the HAAPI token is obtained or an error occurred.
- Parameter forceFresh: The boolean to indicate whether a new HAAPI token should be obtained even when the internal state already has a valid HAAPI token it can use. The default value is 
false. - Parameter dpopNonce:The most recent DPoP nonce. Any Identity Server responses may contain a DPoP-Nonce header with a nonce string. This nonce needs be provided to all subsequent calls to this method.
 - Parameter completionHandler:The handler that is called on the main thread after a HAAPI token was successfully obtained or an HaapiError occured.
 
Parameters
| Name | Description | 
|---|---|
| forceFresh | The boolean to indicate whether a new HAAPI token should be obtained even when the internal state already has a valid HAAPI token it can use. The default value is false. | 
| dpopNonce | The most recent DPoP nonce. Any Identity Server responses may contain a DPoP-Nonce header with a nonce string. This nonce needs be provided to all subsequent calls to this method. | 
| completionHandler | The handler that is called on the main thread after a HAAPI token was successfully obtained or an HaapiError occured. | 
close()
func close()
Closes this HAAPI Token Manager and frees the name of this manager to be used by another instance. It is an error to use this manager after calling close(), and will cause undefined behavior.
clearState()
func clearState()
Clears all state of this manager pertaining to DeviceCheck attestation and access tokens.