How to authenticate?

This page will help you authenticating your account with Inarix SDK.

Get your Inarix token

Before attempting authentication, you'll need an Inarix token which is provided when you authenticate one of your users using the Inarix API.

Requesting a token for one of your users should be performed within your backend environment and not on your client-side application. You should have received an Inarix Third Party Token giving you the right to register users and to request tokens for them. The Third Party Token is a long-living token and it doesn't follow the same refresh mechanism as the Inarix token.

💡

You may discover an API route in the API reference describing a refresh token mechanism. It's for your information and to know what we're using inside the SDK to refresh the Inarix token.

When your user is authenticating to your services, you can provide them an Inarix token by requesting the Inarix API and forwarding it within your service's response. It's a suggestion but you may provide the Inarix tokento your client-side application through alternative methods.

Set your authentication token

Depending on your application, you may want to set your authentication token at a specific point in its lifecycle. In the following example, we chose to set the token at application startup for simplicity.

import SwiftUI
import InarixFramework

@main
struct ios_example_sdkApp: App {
    init() {
        do {
            try InarixSDK.Settings.default.setAuthenticationToken(token: "your-token")
        } catch let err {
            debugPrint("Couldn't set the authentication token: \(err)")
        }
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Token expiration

It's important to be aware of token expiration. Typically, the Inarix SDK handles token refreshes in the background. However, there may be circumstances where the token cannot be refreshed. To address this, you should subscribe to the expired token event to be notified if the SDK is unable to refresh your token.

Building on our previous example, here’s how we would implement it:

import SwiftUI
import InarixFramework

class ExpiredTokenObserver: InarixSDK.TokenExpiredObserver {
  func onTokenExpired() {
    // TODO: Handle token expiration
    debugPrint("My token expired!")
  }
}

@main
struct ios_example_sdkApp: App {
  let tokenExpiredObserver = ExpiredTokenObserver()
  let token = "your-token"
  
  init() {
    do {
      // Set authentication token
      try InarixSDK.Settings.default.setAuthenticationToken(token: token)

      // Add observer to be notified when token is expired
      InarixSDK.Settings.default.addObserver(tokenExpiredObserver)

      debugPrint("Authentication is set!")
    } catch let err {
      debugPrint("Couldn't set the authentication token: \(err)")
    }
  }

  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }
}

What’s Next

From here, you can proceed to set up the scenario player and run your first measurement!