Repository navigation
FR-25958 FR-25959 FR-25952 feat: Expo config plugin, new architecture, multi-region and getOrRefreshAccessToken #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dianaKhortiuk-frontegg
merged 8 commits into
master
from
claude/determined-rubin-dp6k5f
Oct 27, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2555817
Add Expo config plugin, multi-region, getOrRefreshAccessToken and Tur…
claude 6f20799
fix(android): pass BuildConfig SDK options to initWithRegions
claude 861855e
fix(expo): initialize Android regions in MainApplication.onCreate
claude 28a75bf
fix(android): settle getOrRefreshAccessToken without region, network …
claude 5bcd03e
ci: run on Node 22, which the expo dev dependency requires
claude 891e76e
fix(android): retry region init after a failed SDK initialization
claude 227155b
fix(android): reject INVALID_REGION only for an unconfigured region key
claude 28ba607
docs: say when selectedRegion updates after initWithRegion
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 18.10.0 | ||
| 22 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
|
|
||
| <application> | ||
|
|
||
| </application> | ||
| <queries> | ||
| <intent> | ||
| <action android:name="android.intent.action.VIEW"/> | ||
| <category android:name="android.intent.category.BROWSABLE"/> | ||
| <data android:scheme="https"/> | ||
| </intent> | ||
| </queries> | ||
|
|
||
| </manifest> |
102 changes: 102 additions & 0 deletions
102
android/src/main/java/com/frontegg/reactnative/AccessTokenRefresher.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.frontegg.reactnative | ||
|
|
||
| import android.content.Context | ||
| import com.frontegg.android.FronteggAuth | ||
| import com.frontegg.android.utils.FronteggConstantsProvider | ||
| import com.frontegg.android.utils.JWTHelper | ||
| import com.frontegg.android.utils.NetworkGate | ||
| import java.io.IOException | ||
| import java.time.Instant | ||
| import kotlinx.coroutines.delay | ||
| import kotlinx.coroutines.withTimeoutOrNull | ||
|
|
||
| private const val MINIMUM_ACCESS_TOKEN_VALIDITY_SECONDS = 15 | ||
| private const val AUTH_STATE_SETTLE_TIMEOUT_MS = 20_000L | ||
| private const val CONCURRENT_REFRESH_TIMEOUT_MS = 10_000L | ||
| private const val AUTH_STATE_POLL_INTERVAL_MS = 200L | ||
|
|
||
| internal suspend fun fetchValidAccessToken(auth: FronteggAuth, context: Context): String? { | ||
| if (auth.isMultiRegion && auth.selectedRegion == null) { | ||
| return null | ||
| } | ||
| val settled = waitWhile(AUTH_STATE_SETTLE_TIMEOUT_MS) { | ||
| auth.initializing.value || auth.refreshingToken.value | ||
| } | ||
| if (!settled) { | ||
| throw IllegalStateException("Timed out waiting for authentication state to settle") | ||
| } | ||
| if (auth.refreshToken.value == null) { | ||
| return null | ||
| } | ||
|
|
||
| val currentAccessToken = auth.accessToken.value | ||
| if (hasMoreThanMinimumValidity(currentAccessToken)) { | ||
| return currentAccessToken | ||
| } | ||
|
|
||
| val offlineModeEnabled = isOfflineModeEnabled(context) | ||
| if (!NetworkGate.isNetworkLikelyGood(context)) { | ||
| if (offlineModeEnabled) { | ||
| return currentAccessToken | ||
| } | ||
| throw IOException("No network connection to refresh the access token") | ||
| } | ||
|
|
||
| val refreshedAccessToken = refreshUntilValid(auth) | ||
| if (refreshedAccessToken != null) { | ||
| return refreshedAccessToken | ||
| } | ||
| if (auth.refreshToken.value == null) { | ||
| return null | ||
| } | ||
| if (offlineModeEnabled && !NetworkGate.isNetworkLikelyGood(context)) { | ||
| return auth.accessToken.value | ||
| } | ||
| throw IOException("Access token could not be refreshed") | ||
| } | ||
|
|
||
| private suspend fun refreshUntilValid(auth: FronteggAuth): String? { | ||
| if (!auth.refreshTokenAndWait()) { | ||
| return null | ||
| } | ||
| if (hasMoreThanMinimumValidity(auth.accessToken.value)) { | ||
| return auth.accessToken.value | ||
| } | ||
| waitWhile(CONCURRENT_REFRESH_TIMEOUT_MS) { auth.refreshingToken.value } | ||
| if (hasMoreThanMinimumValidity(auth.accessToken.value)) { | ||
| return auth.accessToken.value | ||
| } | ||
| if (!auth.refreshTokenAndWait()) { | ||
| return null | ||
| } | ||
| return auth.accessToken.value?.takeIf { hasMoreThanMinimumValidity(it) } | ||
| } | ||
|
|
||
| private suspend fun waitWhile(timeoutMs: Long, condition: () -> Boolean): Boolean { | ||
| val finished = withTimeoutOrNull(timeoutMs) { | ||
| while (condition()) { | ||
| delay(AUTH_STATE_POLL_INTERVAL_MS) | ||
| } | ||
| true | ||
| } | ||
| return finished == true | ||
| } | ||
|
|
||
| // Same source the SDK is initialized from, both by its auto-init and by RegionsInitializer. | ||
| private fun isOfflineModeEnabled(context: Context): Boolean { | ||
| return runCatching { | ||
| FronteggConstantsProvider.fronteggConstants(context).enableOfflineMode | ||
| }.getOrDefault(false) | ||
| } | ||
|
|
||
| private fun hasMoreThanMinimumValidity(accessToken: String?): Boolean { | ||
| if (accessToken == null) { | ||
| return false | ||
| } | ||
| return try { | ||
| val secondsLeft = JWTHelper.decode(accessToken).exp - Instant.now().epochSecond | ||
| secondsLeft > MINIMUM_ACCESS_TOKEN_VALIDITY_SECONDS | ||
| } catch (e: Exception) { | ||
| false | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.