Skip to content

Commit ed435d3

Browse files
authored
Support client inputs (#238)
1 parent 6d5c41b commit ed435d3

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ written for Android. You can read more on the [Descope Website](https://descope.
99
Add the following to your `build.gradle` dependencies:
1010

1111
```groovy
12-
implementation 'com.descope:descope-kotlin:0.16.1'
12+
implementation 'com.descope:descope-kotlin:0.17.0'
1313
```
1414

1515
## Quickstart

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+
* An optional map of client inputs that will be provided to the flow.
37+
*
38+
* These values can be used in the flow editor to customize the flow's behavior
39+
* during execution. The values set on the map must be valid JSON types.
40+
*/
41+
var clientInputs: 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?.clientInputs?.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 existing 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
}

descopesdk/src/main/java/com/descope/sdk/Sdk.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ class DescopeSdk(context: Context, projectId: String, configure: DescopeConfig.(
7878
const val NAME = "DescopeAndroid"
7979

8080
/** The Descope SDK version */
81-
const val VERSION = "0.16.1"
81+
const val VERSION = "0.17.0"
8282
}
8383
}

0 commit comments

Comments
 (0)