Skip to content

Commit

Permalink
Add custom scheme for opera users
Browse files Browse the repository at this point in the history
  • Loading branch information
itaihanski committed Jan 4, 2024
1 parent 46cec86 commit 2e92748
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ class FlowDoneActivity : AppCompatActivity() {
<!-- replace with your host, the path can change must must be reflected when running the flow -->
<data android:scheme="https" android:host="<YOUR_HOST_HERE>" android:path="/done" />
</intent-filter>

<!-- Optional: App Links are blocked by default on Opera Browsers. Add a custom scheme for that use case specifically -->
<intent-filter android:autoVerify="true"> <!-- autoVerify required for app links -->
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<!-- replace with something unique. this will only be used as a backup for Opera users. -->
<data android:scheme="myapp" android:host="auth" />
</intent-filter>
</activity>
```

Expand Down Expand Up @@ -268,6 +278,7 @@ unexpected UX. Run the flow by creating a `DescopeFlow.Runner`:
Descope.flow.create(
flowUrl = "<URL_FOR_FLOW_IN_SETUP_#1>",
deepLinkUrl = "<URL_FOR_APP_LINK_IN_SETUP_#2>",
backupCustomScheme = "<OPTIONAL_CUSTOM_SCHEME_FROM_SETUP_#2>"
).start(this@MainActivity)
```

Expand Down
15 changes: 9 additions & 6 deletions descopesdk/src/main/java/com/descope/internal/routes/Flow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.browser.customtabs.CustomTabsIntent
import com.descope.internal.http.DescopeClient
import com.descope.internal.others.with
import com.descope.sdk.DescopeFlow
import com.descope.sdk.DescopeLogger
import com.descope.sdk.DescopeLogger.Level.Info
import com.descope.types.AuthenticationResponse
import com.descope.types.DescopeException
Expand All @@ -24,15 +23,16 @@ internal class Flow(
override var currentRunner: DescopeFlow.Runner? = null
private set

override fun create(flowUrl: String, deepLinkUrl: String): DescopeFlow.Runner {
val runner = FlowRunner(flowUrl, deepLinkUrl)
override fun create(flowUrl: String, deepLinkUrl: String, backupCustomScheme: String?): DescopeFlow.Runner {
val runner = FlowRunner(flowUrl, deepLinkUrl, backupCustomScheme)
currentRunner = runner
return runner
}

inner class FlowRunner(
private val flowUrl: String,
private val deepLinkUrl: String,
private val backupCustomScheme: String?,
) : DescopeFlow.Runner {

private lateinit var codeVerifier: String
Expand All @@ -54,11 +54,14 @@ internal class Flow(
val codeChallenge = Base64.UrlSafe.encode(hashed)

// embed into url parameters
val uri = Uri.parse(flowUrl).buildUpon()
val uriBuilder = Uri.parse(flowUrl).buildUpon()
.appendQueryParameter("ra-callback", deepLinkUrl)
.appendQueryParameter("ra-challenge", codeChallenge)
.appendQueryParameter("ra-initiator", "android")
.build()
backupCustomScheme?.let {
uriBuilder.appendQueryParameter("ra-backup-callback", it)
}
val uri = uriBuilder.build()

// launch via chrome custom tabs
launchUri(context, uri)
Expand Down Expand Up @@ -91,7 +94,7 @@ internal class Flow(
}

}

}

private fun launchUri(context: Context, uri: Uri) {
Expand Down
4 changes: 3 additions & 1 deletion descopesdk/src/main/java/com/descope/sdk/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,10 @@ interface DescopeFlow {
*
* @property flowUrl the URL where the flow is hosted.
* @property deepLinkUrl a deep link back to the app that will handle the exchange.
* @property backupCustomScheme a backup custom scheme deep link for Opera browser users,
* which blocks app links by default.
*/
fun create(flowUrl: String, deepLinkUrl: String): Runner
fun create(flowUrl: String, deepLinkUrl: String, backupCustomScheme: String? = null): Runner

/**
* A helper interface that encapsulates a single flow run.
Expand Down

0 comments on commit 2e92748

Please sign in to comment.