How okta/okta-react-native works
Main Components
• React Native Layer: Represent the JavaScript modules and APIs (e.g., createConfig, signIn, signOut, getAccessToken, etc.) that expose authentication functionality to the consumer.
• Native Modules: Separate native implementations for iOS and Android:
• Android: Shown in the “android” directory (with Java classes such as OktaSdkBridgeModule.java, HttpClientImpl.java, etc.) that directly wrap the Okta OIDC Android SDK.
• iOS: Found in the “ios” directory, including bridging header files and Swift/Objective-C classes (e.g., OktaSdkBridge.swift, ReactNativeOktaSdkBridge.m) that interface with the Okta OIDC iOS SDK.
• External Dependencies: Include the external Okta OIDC libraries (for both Android and iOS) as well as any other dependency (for example, the Okta AuthJS integration for custom sign-in) that the library is built on.
• Testing and CI/CD: The “e2e”, “test”, and “.github” directories indicate end-to-end tests (with sample React Native applications and native integration tests) and workflows. It is useful to show how these tests interact with the main components.
• Build and Configuration Components: Include the “scripts”, “.circleci”, “.github/workflows”, etc. to indicate how the library is built, tested, and maintained.
Relationships and Data Flows
• How a React Native app calls the exposed authentication API (e.g., createConfig, signIn) in the JavaScript layer.
• For the native modules, illustrate separate flows:
• On Android, how the native module forwards authentication requests to the Okta OIDC Android SDK (with dependencies on build files like Gradle) and then relays responses back to JavaScript.
• On iOS, how the bridging components interact with the Okta OIDC iOS Framework using CocoaPods and exposes responses back through the React Native bridge.
• Network communication component: show that once authentication is initiated, native modules interact with external Okta authentication servers via the OAuth 2.0 Authorization Code Flow with PKCE, then return tokens and user info.
Architectural Patterns and Technologies
• Client-Bridge-Native pattern: The layered architecture which cleanly separates front-end (React Native) from the native SDK implementations.
• Use of event-driven patterns: The library uses event emitters to signal signInSuccess, signOutSuccess, onError, and onCancelled events.
• Dependency Management: Gradle for Android, CocoaPods for iOS, and package.json for JavaScript dependencies.
• Testing: End-to-end (e2e) test applications simulate full flows, while unit and integration tests (located in “test” and “ios/Tests”) ensure quality.
• CI/CD: The presence of circleci and GitHub workflows indicates continuous integration pipelines that automates build, lint, and test steps.