Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/src/main/kotlin/dev/hotwire/core/config/HotwireConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ class HotwireConfig internal constructor() {
WebView.setWebContentsDebuggingEnabled(value)
}

/**
* Enables WebAuthn (passkey) requests from every WebView instance, using the
* embedding app's identity. Disabled by default, which matches the WebView's
* own default behavior.
*
* Your app must be associated with your website through
* [Digital Asset Links](https://developers.google.com/digital-asset-links),
* otherwise the requests are rejected. Note that the WebView reports the app's
* identity as the WebAuthn origin (`android:apk-key-hash:<hash>`), so your
* server has to accept it in addition to its web origin.
*
* Requires Android System WebView 121 or later; on older versions this
* setting has no effect.
*/
var webAuthenticationEnabled = false

/**
* Called whenever a new WebView instance needs to be (re)created. Provide
* your own implementation and subclass [HotwireWebView] if you need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ open class HotwireWebView @JvmOverloads constructor(
settings.setSupportMultipleWindows(true)
layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
initDayNightTheming()
initWebAuthentication()
}

/**
Expand Down Expand Up @@ -104,6 +105,17 @@ open class HotwireWebView @JvmOverloads constructor(
return args.joinToString(",") { gson.toJson(it) }
}

private fun initWebAuthentication() {
if (!Hotwire.config.webAuthenticationEnabled) return

if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_AUTHENTICATION)) {
WebSettingsCompat.setWebAuthenticationSupport(
settings,
WebSettingsCompat.WEB_AUTHENTICATION_SUPPORT_FOR_APP
)
}
}

@Suppress("DEPRECATION")
private fun initDayNightTheming() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
Expand Down
Loading