iOS Client Setup for the Hypermedia Authentication API

On this page

What Is the Hypermedia Authentication API?

The Hypermedia Authentication API is a feature of the Curity Identity Server. It enables clients to leverage OAuth and OpenID Connect and the Curity Identity Server's powerful authentication engine straight from client applications — without the need of a browser. If you want to learn more about the Hypermedia Authentication API, check out the overview article.

It's All About Security

The browser plays a vital role in OAuth and OIDC flows — it makes them more secure. Browser redirects ensure that the Authorization Server delivers data to the proper client, and not to an impersonator. Thus, removing the browser from OAuth and OIDC flows may at first seem a bit reckless. As we now use an API to fulfill a vulnerable authentication and authorization flow, we require another method to make sure that the client calling the API is indeed allowed to do so.

Two security features of the Curity Identity Server ensure that the Authentication API process is just as secure as browser flows:

  • client attestation
  • proof of possession tokens

Client Attestation

Client attestation is done by verifying the running application's package ID and the signing credentials. This is processed by the Android Operation System or iOS and bound to a cryptographic key pair. After a positive attestation, the client (the mobile app) is issued a Client Attestation Token (CAT) in the form of a JWT. The concrete implementation of the attestation is out of the scope of this article, but what is important to note, is that client attestation asserts a few things about the calling client application:

  1. The app was correctly signed with the credentials configured in the Curity Identity Server for the associated OAuth client. This means that the app has not been tampered with. For example, it hasn't been decompiled, had its code changed, and recompiled into a malicious client. When using these features, decompilation cannot provide any information that could help create an impersonated client.
  2. The app runs in a safe environment, that is, on a system that has not been rooted. Otherwise, it wouldn't be possible to securely perform the verification described above.

Demonstration of Proof-of-Possession

Proof-of-Possession tokens are another way to use access tokens. The most common way used in APIs is using Bearer tokens. Bearer tokens work a bit like cash — any client who possesses a Bearer access token can successfully call an API. Proof-of-Possession tokens behave more like credit cards — only legitimate owners of these tokens can use them to access the API. This further increases the security of the communication. Even if the access token is stolen, another party can't use it.

The Hypermedia Authentication API uses a standard for Demonstration of Proof-of-Possession. By adopting this standard, access tokens used to access the Authentication API are bound to a private key that only the legitimate client possesses.

Roles of HAAPI SDKs

To facilitate the usage of these crucial security components, Curity has released SDKs to help you leverage the Hypermedia API. You will only need to use the first of these, which provides a high level interface:

Model SDKThe model SDK introduces classes representing possible responses from the authentication API. The model SDK uses the driver SDK to handle communication, then processes responses into models. These represent the instructions the API is issuing to the mobile client.
Driver SDKObtaining CATs and using DPoP to secure requests to the API is a security-sensitive process. Obtaining a CAT requires a few different steps, and the DPoP standard requires the client to generate correct headers for every request. The driver SDK is responsible for handling these low-level security concerns.

Prerequisite Setup

To call the API from an iOS app, make sure of the following:

  1. Use at least version 6.2.2. of the Curity Identity Server.

  2. You will require an iOS attestation policy. To add one, follow the instructions below:

    • Open the Facilities menu in the top right corner of the admin UI and navigate to Client Attestations at the bottom.
    • Click on the + button next to iOS Policies.
new attestation
  • Enter a suitable name for the policy and click Create.
new attestation name
  • Choose the appropriate mode. production mode tells the Curity Identity Server to validate the app against its release signing settings. Choosing non-production will validate the app against the debug signing settings. In some rare cases, it might also be necessary to overwrite Apple's Certificate Chain, but normally you shouldn't need to use this setting. Close the dialog once you choose all the settings.
ios attestation configuration
  1. You will also need a client with the API capability which uses the iOS attestation policy.

    • Go to ProfilesToken ServiceClients, and edit the client of your choice.
    • In the Capabilities section, make sure your client has at least these two enabled: Hypermedia Authentication API and Code Flow. Use any URL for the redirect URL (e.g. https://localhost) and choose no-authentication as the Client authentication method.
    • Scroll down to the Client Application Settings tab and open the Advanced section. Enable the Attestation, and select ios as attestation type. Enter your App ID following the instructions available next to the input field and choose the Attestation Policy that you've previously created.
    • If you want to test or develop the app using a simulated device turn on the Disable Attestation Validation option. When this is on, the client and server will still perform the Attestation, but the server will not validate the attestation. Attestation functionality does not work on simulated iOS devices, so you have to enable this option when using a simulator. Remember not to use this setting for production clients!
client attestation settings

Remember to commit all the changes made to the configuration.

Note that you can also use the configuration CLI or RESTCONF API to set these settings.

Integrate HAAPI into a Mobile App

You can obtain the SDK from the Curity GitHub. You can add the SDK to your project either by using the Swift Package Manager or through CocoaPods.

You can add the following to your Package.swift file:

.package(url: "https://github.com/curityio/ios-idsvr-haapi-sdk-dist")

If you're not using the Package.swift file, and you prefer to add the dependencies directly in Xcode, follow these steps:

  • In Xcode choose FileAdd Packages... from the menu.
  • Enter https://github.com/curityio/ios-idsvr-haapi-sdk-dist to the search field.
  • Choose the desired version policy (you can leave the default settings).
  • Click Add Package to add the dependency.

The SDK exposes two classes: HaapiTokenManager and OAuthTokenManager. The managers accept a configuration object and are responsible for communication with the Curity Identity Server. The HaapiManager exposes the following methods:

  • start
  • followLink
  • submitForm
  • close

The first three are used to call subsequent steps of the authentication flow. Each method returns a HaapiResult, through a completion handler. The HaapiResult encloses a HaapiRepresentation, a ProblemRepresentation or an Error. HaapiRepresentation is a sealed interface, implementations of which represent concrete response objects from the authentication API.

The app should call the API until it eventually gets an OAuthAuthorizationResponseStep, which signals that the authentication has finished, and the app can now obtain access, refresh and ID tokens from the Curity Identity Server. This can be easily done using the OAuthTokenManager object's fetchAccessToken method.

The OAuthTokenManager also exposes a refreshAccessToken method for refreshing access tokens.

Below is a trivial example of calling the API with the SDK. Note that no additional work concerning Client Attestation or DPoP is needed. Thanks to the SDK, these are still used in communication with the API.

import IdsvrHaapiSdk
let haapiConfiguration = HaapiConfiguration(name: name,
clientId: "ios-client",
baseURL: URL(string: "https://idsvr.example.com")!,
tokenEndpointURL: URL(string: "https://idsvr.example.com/oauth/v2/oauth-token")!,
authorizationEndpointURL: URL(string: "https://idsvr.example.com/oauth/v2/oauth-authorize")!,
appRedirect: "app://redirect",
isAutoRedirect: true,
urlSession: URLSessionConfiguration.default)
let haapiManager = HaapiManager(haapiConfiguration: haapiConfiguration)
let tokenManager = OAuthTokenManager(oauthTokenConfiguration: haapiConfiguration)
haapiManager.start(OAuthAuthorizationParameters(scopes: ["openid", "profile"]),
{ haapiResult in
if (haapiResult is OAuthAuthorizationResponseStep) {
with: haapiResult.oauthAuthorizationResponseProperties.code,
completionHandler: { oauthResponse in
if (oauthResponse is SuccessfulTokenResponse) {
} else {

Also checkout the iOS Swift HAAPI Code Example, which provides an automated setup and also demonstrates and end-to-end demo app, that shows how to implement all OAuth lifecycle events.


To use the hypermedia authentication API in a mobile app you first must do some prerequisite setup and integrate the Curity SDKs. You can then quickly integrate a hardened OpenID Connect flow into your mobile app.

For further details on the API, have a look at the Authentication API documentation. If you need help setting up the API or SDK, or have any other questions or comments, please do not hesitate to contact us.