Skip to content

Commit de353d2

Browse files
committed
Support client params
1 parent 6d5c41b commit de353d2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

descopesdk/src/main/java/com/descope/android/DescopeFlow.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class DescopeFlow {
3232
*/
3333
var hooks: List<DescopeFlowHook> = emptyList()
3434

35+
/**
36+
* A map of parameters that will be sent to the flow webpage.
37+
*
38+
* These parameters should conform to basic JSON types, and can be used
39+
* in the flow editor to customize the flow's behavior.
40+
*/
41+
var clientParams: Map<String, Any> = emptyMap()
42+
3543
/**
3644
* An object that provides the [DescopeSession] value for the currently authenticated
3745
* user if there is one, or `null` otherwise.

descopesdk/src/main/java/com/descope/android/DescopeFlowCoordinator.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import com.descope.internal.others.debug
3737
import com.descope.internal.others.error
3838
import com.descope.internal.others.info
3939
import com.descope.internal.others.isUnsafeEnabled
40+
import com.descope.internal.others.toJsonObject
4041
import com.descope.internal.others.with
4142
import com.descope.internal.routes.convert
4243
import com.descope.internal.routes.getPackageOrigin
@@ -272,6 +273,7 @@ class DescopeFlowCoordinator(val webView: WebView) {
272273
ssoRedirect = pickRedirectUrl(flow?.ssoRedirect, flow?.ssoRedirectCustomScheme, useCustomSchemeFallback),
273274
magicLinkRedirect = flow?.magicLinkRedirect ?: "",
274275
isWebAuthnSupported = isWebAuthnSupported,
276+
clientJson = flow?.clientParams?.toJsonObject()?.toString()?.escapeForBackticks() ?: "{}"
275277
)
276278
) {}
277279
}
@@ -537,6 +539,7 @@ private fun setupScript(
537539
ssoRedirect: String,
538540
magicLinkRedirect: String,
539541
isWebAuthnSupported: Boolean,
542+
clientJson: String,
540543
) = """
541544
542545
window.descopeBridge = {}
@@ -590,6 +593,18 @@ function flowBridgeSetRefreshJwt(wc, refreshJwt) {
590593
}
591594
}
592595
596+
function flowBridgeMergeClientJson(wc, clientJson) {
597+
let client = {}
598+
try {
599+
client = JSON.parse(wc.getAttribute("client") || '{}')
600+
} catch (e) {}
601+
client = {
602+
...client,
603+
...JSON.parse(clientJson),
604+
}
605+
wc.setAttribute("client", JSON.stringify(client))
606+
}
607+
593608
function flowBridgePrepareWebComponent(wc) {
594609
flowBridgeSetRefreshJwt(wc, '$refreshJwt')
595610
@@ -623,6 +638,9 @@ function flowBridgePrepareWebComponent(wc) {
623638
flow.native(JSON.stringify(e.detail), window.location.href);
624639
})
625640
641+
// add incoming client params to any already exiting client parameters on the web-component
642+
flowBridgeMergeClientJson(wc, '$clientJson')
643+
626644
// ensure we support old web-components without this function
627645
wc.lazyInit?.()
628646
}

0 commit comments

Comments
 (0)