Skip to content

Authentication

TrainingKit has two runtime authentication contracts, plus a build-time key used only for schema introspection. The contracts themselves are defined in the API section; this page shows how each one surfaces in the React Native bridge.

The two runtime contracts

ContractWhat it protectsHow it travelsRequired?
API AuthenticationYour B2B API perimeter — only your authenticated backend context can call the APIA backend-issued JWT sent on your GraphQL requestsWhen enabled in your Admin Console (recommended for production)
SDK AuthenticationTrainingKit integrity — blocks forged, modified, or replayed workout payloadsThe X-TrainingKit-Device handshake that returns a TrainingKitToken, forwarded to the native SDK on launchAlways — it is mandatory to launch a workout

Full reference:

API Authentication (request JWT)

Your backend issues a short-lived JWT (signed with your RSA/ECDSA key, carrying a sub claim for the end user) and your app attaches it to every GraphQL request — typically an Authorization: Bearer <jwt> header. The API layer validates it; the SDK does not. This layer is turned on and configured (public keys, JWKS/PEM) by the B2B client in the Admin Console.

Add it alongside the device header when you build the client:

ts
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'
import { deviceIdentifier } from 'trainingkit-reactnative'

const client = new ApolloClient({
  link: new HttpLink({
    uri: 'https://your-graphql-endpoint/graphql',
    headers: {
      'X-TrainingKit-Device': deviceIdentifier(),
      Authorization: `Bearer ${backendJWT}`, // API Authentication, when enabled
    },
  }),
  cache: new InMemoryCache(),
})

Issue the JWT server-side only; never embed the signing key in the app.

SDK Authentication (device handshake + TrainingKitToken)

Launching a workout requires a device-bound token, and the bridge handles most of it for you.

  1. Send the SDK device identifier on every GraphQL request (the X-TrainingKit-Device header above). deviceIdentifier() returns it synchronously.
  2. The backend returns a TrainingKitToken in the session payload (the trainingKitToken field, also available via GraphQL extensions.trainingkit.token or the X-TrainingKit-Token header).
  3. Pass the full session object to launchWorkout — it reads trainingKitToken and forwards it to the native SDK:
ts
import { launchWorkout } from 'trainingkit-reactnative'

launchWorkout(session) // throws if trainingKitToken is missing

The token is valid for one day and bound to the current app lifecycle, so fetch the full session shortly before launch. See SDK Authentication for lifecycle, caching, and refresh rules.

Build-time only: X-Developer-Authorization-Key

This is not a runtime credential. It unlocks GraphQL schema introspection (for the Admin Console Playground or GraphQL Codegen) and is retrieved from your Admin Console API settings.

Use it only on developer machines or CI, for tooling such as codegen. Never ship it in the app bundle or hard-code it in source that ends up in the build.