Adding the SDKs to a React Native app
There's no separate React Native package. Passpoint onboarding needs the native iOS and Android SDKs, so you expose them to JavaScript with a small native module that wraps the same four verbs.
This guide gives you a drop-in module for both platforms and the JS API that sits on top. It issues certificates through your Broker, the route we recommend. App Attest and Play Integrity still work if you leave the Broker out, but we'll remove them in the near future.
Building a fully native app rather than a React Native one? Start from the iOS example app or the Android example app instead.
Prerequisites
Set up the native SDKs first, exactly as a native app would. Nothing here replaces that.
- iOS — add the Swift Package and complete iOS setup: the Hotspot Configuration entitlement, the Keychain access group, and registering your Broker.
- Android — add the SDK from Maven Central and complete Android setup, including registering your Broker.
- Your Broker — running, registered with Wi-DAS, and reachable from your app behind your own sign-in. Brokered issuance covers what it does.
The entitlements, permissions, and registration in those pages all still apply. The bridge below just calls the SDKs; it doesn't change what they need.
The native modules call your Broker natively, using the MyBroker adapters from the platform usage
pages. Copy the iOS adapter into your ios/ folder and the
Android adapter into the same package as the module below.
JavaScript only supplies your Broker's address and the signed-in user's access token.
1. The JavaScript API
Create a typed wrapper so the rest of your app never touches NativeModules directly. The error
code on a rejected promise is the same string on both platforms.
// widas.ts
import { NativeModules } from 'react-native';
const { WiDASModule } = NativeModules;
export type WiDASState = 'none' | 'valid' | 'expired' | 'revoked' | 'unknown';
export interface WiDASStatus {
state: WiDASState;
serial: string | null;
expiry: string | null; // ISO-8601, or null
}
export interface ConnectionResult {
serial: string;
notAfter: string; // ISO-8601
}
export interface ConfigureOptions {
brokerUrl?: string; // your Broker's endpoint; leave it out to use App Attest / Play Integrity
baseUrl?: string; // the Wi-DAS Certificate API; required on Android
keychainAccessGroup?: string; // iOS only
cloudProjectNumber?: number; // Android, Play Integrity only
}
export interface ConnectOptions {
accessToken?: string; // your own sign-in token, sent to your Broker; required with brokerUrl
requestedValidity?: string; // ISO-8601 duration
}
export const WiDAS = {
configure(clientId: string, options: ConfigureOptions = {}): Promise<void> {
return WiDASModule.configure(clientId, options);
},
connect(user: string, options: ConnectOptions = {}): Promise<ConnectionResult> {
const { accessToken = null, requestedValidity = 'P365D' } = options;
return WiDASModule.connect(user, requestedValidity, accessToken);
},
status(): Promise<WiDASStatus> {
return WiDASModule.status();
},
disconnect(): Promise<void> {
return WiDASModule.disconnect();
},
};
Each platform reads only the options it needs and ignores the rest. state is only ever unknown on
Android.
status() resolves in normal use. On Android it can reject with internal if the SDK can't read
what it stored on the device, so handle a rejection there as you would any other.
Pass a fresh accessToken on every connect(). The adapter sends it to your Broker as a bearer
token, and your Broker should work out who the user is from it rather than trusting the user value
as sent.
2. The iOS native module
Add two files to your iOS project (the ios/ folder, added to your app target), alongside your
MyBroker adapter. If your app has no Swift yet, Xcode will offer to create a bridging header when
you add the first Swift file — accept it.
// ios/WiDASModule.swift
import Foundation
import WiDAS
@objc(WiDASModule)
final class WiDASModule: NSObject {
private var widas: WiDAS?
private var usesBroker = false
private var accessToken: String?
@objc static func requiresMainQueueSetup() -> Bool { false }
@objc(configure:options:resolver:rejecter:)
func configure(_ clientId: String,
options: [String: Any],
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
let group = options["keychainAccessGroup"] as? String
let baseURL = (options["baseUrl"] as? String).flatMap(URL.init(string:)) ?? WiDAS.productionBaseURL
if let raw = options["brokerUrl"] as? String {
guard let endpoint = URL(string: raw) else {
return reject("badArgs", "brokerUrl isn't a valid URL", nil)
}
let broker = MyBroker(endpoint: endpoint, userAccessToken: { [weak self] in
self?.currentAccessToken() ?? ""
})
widas = WiDAS(clientId: clientId, broker: broker, baseURL: baseURL, keychainAccessGroup: group)
usesBroker = true
} else {
widas = WiDAS(clientId: clientId, baseURL: baseURL, keychainAccessGroup: group)
usesBroker = false
}
resolve(nil)
}
@objc(connect:requestedValidity:accessToken:resolver:rejecter:)
func connect(_ user: String,
requestedValidity: String,
accessToken: String?,
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
guard let widas else { return reject("notConfigured", "Call configure() first", nil) }
if usesBroker && (accessToken ?? "").isEmpty {
return reject("missingAccessToken", "Pass the signed-in user's accessToken to connect()", nil)
}
setAccessToken(accessToken)
Task {
do {
let result = try await widas.connect(user: user, requestedValidity: requestedValidity)
resolve([
"serial": result.serial,
"notAfter": ISO8601DateFormatter().string(from: result.notAfter),
])
} catch let error as WiDASError {
reject(error.code, error.localizedDescription, error)
} catch {
reject("internal", error.localizedDescription, error)
}
}
}
@objc(status:rejecter:)
func status(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
guard let widas else { return reject("notConfigured", "Call configure() first", nil) }
Task {
let status = await widas.status()
let iso = ISO8601DateFormatter()
resolve([
"state": status.state.rawValue,
"serial": status.serial as Any,
"expiry": status.expiry.map { iso.string(from: $0) } as Any,
])
}
}
@objc(disconnect:rejecter:)
func disconnect(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
guard let widas else { return reject("notConfigured", "Call configure() first", nil) }
Task {
do { try await widas.disconnect(); resolve(nil) }
catch let error as WiDASError { reject(error.code, error.localizedDescription, error) }
catch { reject("internal", error.localizedDescription, error) }
}
}
private let tokenLock = NSLock()
private func setAccessToken(_ token: String?) {
tokenLock.lock(); defer { tokenLock.unlock() }
accessToken = token
}
private func currentAccessToken() -> String {
tokenLock.lock(); defer { tokenLock.unlock() }
return accessToken ?? ""
}
}
// ios/WiDASModule.m
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(WiDASModule, NSObject)
RCT_EXTERN_METHOD(configure:(NSString *)clientId
options:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(connect:(NSString *)user
requestedValidity:(NSString *)requestedValidity
accessToken:(nullable NSString *)accessToken
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(status:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(disconnect:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
@end
3. The Android native module
Add the module and a package, then register the package in your app. Put your MyBroker adapter in
the same package.
// android/app/src/main/java/com/yourapp/widas/WiDASModule.kt
package com.yourapp.widas
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.ReadableMap
import com.widas.sdk.WiDAS
import com.widas.sdk.WiDASException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
class WiDASModule(private val reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
private val http = OkHttpClient()
private var widas: WiDAS? = null
private var usesBroker = false
@Volatile private var accessToken: String? = null
override fun getName() = "WiDASModule"
@ReactMethod
fun configure(clientId: String, options: ReadableMap, promise: Promise) {
val baseUrl = options.getString("baseUrl")
?: return promise.reject("badArgs", "baseUrl is required")
val brokerUrl = if (options.hasKey("brokerUrl")) options.getString("brokerUrl") else null
widas = if (brokerUrl != null) {
val broker = MyBroker(http, brokerUrl) { accessToken.orEmpty() }
WiDAS.configure(reactContext, clientId, broker, baseUrl)
} else {
val cloud = if (options.hasKey("cloudProjectNumber"))
options.getDouble("cloudProjectNumber").toLong() else null
WiDAS.configure(reactContext, clientId, baseUrl, cloud)
}
usesBroker = brokerUrl != null
promise.resolve(null)
}
@ReactMethod
fun connect(user: String, requestedValidity: String?, accessToken: String?, promise: Promise) {
val sdk = widas ?: return promise.reject("notConfigured", "Call configure() first")
if (usesBroker && accessToken.isNullOrEmpty()) {
return promise.reject("missingAccessToken", "Pass the signed-in user's accessToken to connect()")
}
this.accessToken = accessToken
scope.launch {
try {
val result = sdk.connect(user, requestedValidity)
promise.resolve(Arguments.createMap().apply {
putString("serial", result.serial)
putString("notAfter", result.notAfter.toString())
})
} catch (e: WiDASException) {
promise.reject(e.code, e.message, e)
}
}
}
@ReactMethod
fun status(promise: Promise) {
val sdk = widas ?: return promise.reject("notConfigured", "Call configure() first")
scope.launch {
try {
val status = sdk.status()
promise.resolve(Arguments.createMap().apply {
putString("state", status.state.name.lowercase())
putString("serial", status.serial)
putString("expiry", status.expiry?.toString())
})
} catch (e: WiDASException) {
promise.reject(e.code, e.message, e)
}
}
}
@ReactMethod
fun disconnect(promise: Promise) {
val sdk = widas ?: return promise.reject("notConfigured", "Call configure() first")
scope.launch {
try {
sdk.disconnect()
promise.resolve(null)
} catch (e: WiDASException) {
promise.reject(e.code, e.message, e)
}
}
}
override fun invalidate() {
scope.cancel()
super.invalidate()
}
}
Both SDKs publish each error's stable string as code, and it's the same on iOS and Android, so both
modules pass it straight to JavaScript rather than keeping a second mapping that could drift.
// android/app/src/main/java/com/yourapp/widas/WiDASPackage.kt
package com.yourapp.widas
import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
class WiDASPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
listOf(WiDASModule(reactContext))
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
emptyList()
}
Register the package in MainApplication (getPackages()), adding WiDASPackage() to the list.
4. Use it in your app
Each connect() issues a new certificate, so don't call it on every launch. Check status() first and
connect only for none, expired or revoked. On Android, unknown means a certificate was issued
but its validity couldn't be confirmed: show it as unconfirmed and check again later rather than
connecting.
import { WiDAS, WiDASStatus } from './widas';
// Resolves to the status to show, or null if it couldn't be read.
async function onLaunch(userId: string, accessToken: string): Promise<WiDASStatus | null> {
await WiDAS.configure('client-acme', {
brokerUrl: 'https://api.example.com/wi-das/certificates', // your Broker
baseUrl: 'https://partner-api.wi-das.com/',
keychainAccessGroup: '<TeamID>.com.apple.networkextensionsharing', // iOS
});
// status.state: 'none' | 'valid' | 'expired' | 'revoked', plus 'unknown' on Android
let status: WiDASStatus;
try {
status = await WiDAS.status();
} catch (e: any) {
// Android only: 'internal' means the SDK couldn't read its stored state. Log it and report it.
return null;
}
if (status.state !== 'none' && status.state !== 'expired' && status.state !== 'revoked') {
return status; // valid, or unknown: nothing to issue
}
try {
// accessToken comes from your own sign-in.
await WiDAS.connect(userId, { accessToken, requestedValidity: 'P365D' });
} catch (e: any) {
if (e.code === 'network' || e.code === 'serviceUnavailable') {
// Your Broker or Wi-DAS couldn't be reached — try again later.
} else {
// Branch on e.code — see the table below.
}
}
return WiDAS.status();
}
To use App Attest and Play Integrity instead, leave out brokerUrl and accessToken, and pass
cloudProjectNumber for Android. Only do this for an app that already depends on attestation, as
we'll remove it in the near future.
Error codes
A rejected promise carries the same code on both platforms. These match the native
iOS and Android errors.
code | Meaning | Retry? |
|---|---|---|
issuanceRejected | Issuance refused on its merits (bad CSR, validity, challenge, or an over-long CN), or a refusal from your Broker the SDK didn't recognise. | No — fix the config, or check your Broker passes the problem title through unchanged. |
serviceUnavailable | Temporary server-side fault. | Yes — back off. |
entitlementMissing | An unconfigured clientId, a missing capability, an unknown or disabled Client, or Wi-DAS doesn't entitle your Broker to issue for it. | No — fix setup/registration. |
passpointInstallFailed | The Passpoint profile wouldn't install or remove. | No — check entitlements/permissions. |
revoked | The certificate is revoked. | No — disconnect() and tell the user. |
network | Transport/connectivity failure, including your Broker being unreachable. | Yes. |
cancelled | The operation was cancelled. iOS only — on Android, cancellation propagates as CancellationException and never reaches the bridge as a code. | Optional. |
internal | An unexpected local failure (key generation, CSR construction, storage), or a bug in your Broker adapter. | No — log it and report it. |
attestationUnavailable | (Attestation only) Attestation can't run here (Simulator, or no Play Services). | No — degrade the UI. |
attestationRejected | (Attestation only) Attestation didn't match a registered app. | No — fix registration. |
notConfigured | connect/status/disconnect called before configure. | No — call configure() first. |
missingAccessToken | connect called without an accessToken on a Broker setup. | No — pass the signed-in user's token. |
badArgs | configure was given a missing baseUrl (Android) or an invalid brokerUrl (iOS). | No — fix the options. |
Both SDKs publish these strings themselves — WiDASError.code on iOS, WiDASException.code on
Android — which is why the modules above forward them rather than keeping their own mapping. A
mapping would have to be updated in lockstep with the SDKs; forwarding never drifts.
Simulators and emulators can't join a Passpoint network, so confirm onboarding on a physical device.