Skip to content

Commit 3485e9b

Browse files
authored
Merge branch 'main' into push-auth
2 parents be77e8a + af819f0 commit 3485e9b

17 files changed

Lines changed: 119 additions & 31 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout Code
11-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
11+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
1212
- name: Set up JDK 17
13-
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
13+
uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0
1414
with:
1515
distribution: "zulu"
1616
java-version: "17"

.github/workflows/detekt.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ jobs:
2323
# Steps represent a sequence of tasks that will be executed as part of the job
2424
steps:
2525
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
26+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2727

2828
- name: Setup detekt
29-
uses: peter-murray/setup-detekt@26449609a63e843a5b9bad8a4b63ef0ee717f7a5 # v3.0.0
29+
uses: peter-murray/setup-detekt@4c0b45d6dac2620e84abd4ea7008a8a140b9f20a # v4.0.0
3030
with:
3131
detekt_version: 1.23
3232

@@ -51,7 +51,7 @@ jobs:
5151
)" > ${{ github.workspace }}/detekt.sarif.json
5252
5353
# Uploads results to GitHub repository using the upload-sarif action
54-
- uses: github/codeql-action/upload-sarif@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
54+
- uses: github/codeql-action/upload-sarif@8aad20d150bbac5944a9f9d289da16a4b0d87c1e # v4.36.2
5555
with:
5656
# Path to SARIF file relative to the root of the repository
5757
sarif_file: ${{ github.workspace }}/detekt.sarif.json

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
contents: read
1010
packages: write
1111
steps:
12-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
12+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
1313
- name: Set up JDK 17
14-
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
14+
uses: actions/setup-java@ad2b38190b15e4d6bdf0c97fb4fca8412226d287 # v5.3.0
1515
with:
1616
distribution: "zulu"
1717
java-version: "17"

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.descope.internal.others.debug
1919
import com.descope.internal.others.error
2020
import com.descope.internal.others.info
2121
import com.descope.internal.others.isUnsafeEnabled
22+
import com.descope.internal.others.parseServerError
2223
import com.descope.internal.others.stringOrEmptyAsNull
2324
import com.descope.internal.others.with
2425
import com.descope.internal.routes.isWebAuthnSupported
@@ -103,8 +104,15 @@ internal class FlowBridge(val webView: WebView) {
103104
}
104105

105106
private fun bridgeOnError(error: String) {
107+
val parsed = parseServerError(error)
108+
val exception = when {
109+
parsed == null -> DescopeException.flowFailed.with(message = error)
110+
// Convert server flow cancellation to local flow cancellation for cohesive error handling
111+
parsed.code == "E102122" -> DescopeException.flowCancelled.with(message = parsed.message)
112+
else -> parsed
113+
}
106114
handler.post {
107-
listener?.onError(DescopeException.flowFailed.with(message = error))
115+
listener?.onError(exception)
108116
}
109117
}
110118

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ class DescopeFlowCoordinator(val webView: WebView) {
299299
} catch (e: DescopeException) {
300300
if (e == DescopeException.oauthNativeCancelled) {
301301
logger.info("OAuth native canceled")
302+
sendResponse(FlowBridgeResponse.Failure("OAuthNativeCancelled"))
302303
return
303304
}
304305
logger.error("OAuth native failed", e)
@@ -310,9 +311,14 @@ class DescopeFlowCoordinator(val webView: WebView) {
310311
pendingDeepLinkType = request.variant
311312
logger.info("Launching custom tab for ${request.variant}")
312313
try {
313-
launchCustomTab(webView.context, request.startUrl, flow?.presentation?.createCustomTabsIntent(webView.context))
314+
launchCustomTab(webView.context, request.startUrl, flow?.presentation?.createCustomTabsIntent(webView.context)) {
315+
// Custom tab dismissed by the user before completing the auth flow.
316+
pendingDeepLinkType = null
317+
sendResponse(FlowBridgeResponse.Failure("WebAuthCancelled"))
318+
}
314319
} catch (e: DescopeException) {
315320
logger.error("Failed to launch custom tab", e)
321+
pendingDeepLinkType = null
316322
sendResponse(FlowBridgeResponse.Failure("CustomTabFailure"))
317323
}
318324
}
@@ -325,6 +331,7 @@ class DescopeFlowCoordinator(val webView: WebView) {
325331
} catch (e: DescopeException) {
326332
if (e == DescopeException.passkeyCancelled) {
327333
logger.info("Passkeys canceled")
334+
sendResponse(FlowBridgeResponse.Failure("PasskeyCancelled"))
328335
return
329336
}
330337
val failure = when (e) {
@@ -353,6 +360,7 @@ class DescopeFlowCoordinator(val webView: WebView) {
353360
} catch (e: DescopeException) {
354361
if (e == DescopeException.passkeyCancelled) {
355362
logger.info("Passkeys canceled")
363+
sendResponse(FlowBridgeResponse.Failure("PasskeyCancelled"))
356364
return
357365
}
358366
val failure = when (e) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DescopeHelperActivity : Activity() {
3030
// interfere with user input, etc.
3131
if (listenForClose) {
3232
listenForClose = false
33+
activityHelper.onCustomTabCanceled()
3334
finish()
3435
} else {
3536
listenForClose = true

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ fun sendViewIntent(context: Context, uri: Uri) {
2727

2828
// Custom Tab
2929

30-
fun launchCustomTab(context: Context, url: String, customTabsIntent: CustomTabsIntent? = null) {
31-
launchCustomTab(context, url.toUri(), customTabsIntent)
30+
fun launchCustomTab(context: Context, url: String, customTabsIntent: CustomTabsIntent? = null, onCancel: (() -> Unit)? = null) {
31+
launchCustomTab(context, url.toUri(), customTabsIntent, onCancel)
3232
}
3333

34-
fun launchCustomTab(context: Context, uri: Uri, customTabsIntent: CustomTabsIntent? = null) {
35-
activityHelper.openCustomTab(context, customTabsIntent ?: defaultCustomTabIntent(), uri)
34+
fun launchCustomTab(context: Context, uri: Uri, customTabsIntent: CustomTabsIntent? = null, onCancel: (() -> Unit)? = null) {
35+
activityHelper.openCustomTab(context, customTabsIntent ?: defaultCustomTabIntent(), uri, onCancel)
3636
}
3737

3838
internal fun defaultCustomTabIntent(): CustomTabsIntent {

descopesdk/src/main/java/com/descope/internal/http/ClientErrors.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
package com.descope.internal.http
22

3-
import com.descope.internal.others.toMap
43
import com.descope.internal.others.with
54
import com.descope.types.DescopeException
6-
import org.json.JSONObject
7-
8-
internal fun parseServerError(response: String): DescopeException? {
9-
try {
10-
val map = JSONObject(response).toMap()
11-
val code = map["errorCode"] as? String ?: return null
12-
val desc = map["errorDescription"] as? String ?: "Descope server error"
13-
val message = map["errorMessage"] as? String
14-
return DescopeException(code = code, desc = desc, message = message)
15-
} catch (_: Exception) {
16-
return null
17-
}
18-
}
195

206
internal fun exceptionFromResponseCode(code: Int): DescopeException? {
217
val desc = failureFromResponseCode(code) ?: return null

descopesdk/src/main/java/com/descope/internal/http/DescopeClient.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.descope.internal.http
22

33
import com.descope.android.SystemInfo
4+
import com.descope.internal.others.parseServerError
45
import com.descope.sdk.DescopeConfig
56
import com.descope.sdk.DescopeSdk
67
import com.descope.types.DeliveryMethod

descopesdk/src/main/java/com/descope/internal/http/Responses.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal data class JwtServerResponse(
2121
val cookiePath: String,
2222
val cookieName: String?,
2323
val sessionCookieName: String?,
24+
val externalToken: String?,
2425
) {
2526
companion object {
2627
fun fromJson(json: String, cookies: List<HttpCookie>) = JSONObject(json).run {
@@ -49,6 +50,7 @@ internal data class JwtServerResponse(
4950
cookiePath = stringOrEmptyAsNull("cookiePath") ?: "",
5051
cookieName = cookieName,
5152
sessionCookieName = sessionCookieName,
53+
externalToken = stringOrEmptyAsNull("externalToken"),
5254
)
5355
}
5456
}

0 commit comments

Comments
 (0)