Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9789e81
Refactor handling of Application Passwords configuration
hichamboushaba Aug 30, 2025
6161d74
Rename property
hichamboushaba Aug 30, 2025
cb1cf6e
Add new property to control whether feature is enabled or not for WPC…
hichamboushaba Aug 30, 2025
225395d
Copy `WooExperimentalNetwork` logic to `WooNetwork`
hichamboushaba Aug 30, 2025
856bbe1
Remove WooExperimentalNetwork
hichamboushaba Aug 30, 2025
3444de8
Force using Jetpack tunnel when feature is disabled
hichamboushaba Aug 30, 2025
aeb3d6b
Remove unused argument
hichamboushaba Aug 30, 2025
7df9071
Remove unused remote config key
hichamboushaba Aug 30, 2025
65d2f19
Remove old code related to the initial experiment
hichamboushaba Aug 30, 2025
edc6d45
Improve log message for failed requests
hichamboushaba Aug 30, 2025
90d18fb
Add a feature flag for the feature
hichamboushaba Aug 30, 2025
a442412
Minor refactoring for the configuration class
hichamboushaba Sep 1, 2025
60312f7
Make `isEnabledForDirectAccess` enabled by default
hichamboushaba Sep 1, 2025
043d3dc
Update unit tests
hichamboushaba Sep 1, 2025
de41eb5
Fix detekt issues
hichamboushaba Sep 1, 2025
c7f9c85
Fix wear app build issue
hichamboushaba Sep 1, 2025
8ea3d7f
Fix issue for Jetpack CP sites
hichamboushaba Sep 2, 2025
bd77057
Add preference key for the experimental toggle
hichamboushaba Sep 3, 2025
44044c9
Add a preference toggle to the experimental features screen
hichamboushaba Sep 3, 2025
2ef0b44
Rename settings entry to "Experimental features"
hichamboushaba Sep 3, 2025
1700937
Merge pull request #14559 from woocommerce/issue/WOOMOB-1183-jp-app-p…
irfano Sep 5, 2025
8ee5125
Remove outdated comment section
hichamboushaba Sep 5, 2025
3e845a0
Merge branch 'trunk' into issue/WOOMOB-1126-app-passwords-network
hichamboushaba Sep 5, 2025
586a357
Remove old way for checking for app passwords support
hichamboushaba Sep 5, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.network.rest.wpapi.WPAPINetwork
import org.wordpress.android.fluxc.network.rest.wpapi.WPAPINetworkError
import org.wordpress.android.fluxc.network.rest.wpapi.WPAPINetworkingMode
import org.wordpress.android.fluxc.network.rest.wpapi.WPAPIResponse
import org.wordpress.android.fluxc.network.rest.wpapi.applicationpasswords.ApplicationPasswordsConfiguration
Expand Down Expand Up @@ -41,7 +42,7 @@ class WooNetwork @Inject constructor(
forced: Boolean,
requestTimeout: Int,
retries: Int
): WPAPIResponse<T> = handleRequest(site) {
): WPAPIResponse<T> = handleRequest(site, RequestContext(path, "GET")) {
executeGetGsonRequest(
site = site,
path = path,
Expand All @@ -60,7 +61,7 @@ class WooNetwork @Inject constructor(
path: String,
clazz: Class<T>,
body: Map<String, Any>
): WPAPIResponse<T> = handleRequest(site) {
): WPAPIResponse<T> = handleRequest(site, RequestContext(path, "POST")) {
executePostGsonRequest(
site = site,
path = path,
Expand All @@ -74,7 +75,7 @@ class WooNetwork @Inject constructor(
path: String,
clazz: Class<T>,
body: Map<String, Any>
): WPAPIResponse<T> = handleRequest(site) {
): WPAPIResponse<T> = handleRequest(site, RequestContext(path, "PUT")) {
executePutGsonRequest(
site = site,
path = path,
Expand All @@ -88,7 +89,7 @@ class WooNetwork @Inject constructor(
path: String,
clazz: Class<T>,
params: Map<String, String>
): WPAPIResponse<T> = handleRequest(site) {
): WPAPIResponse<T> = handleRequest(site, RequestContext(path, "DELETE")) {
executeDeleteGsonRequest(
site = site,
path = path,
Expand All @@ -99,6 +100,7 @@ class WooNetwork @Inject constructor(

private suspend fun <T : Any> handleRequest(
site: SiteModel,
requestContext: RequestContext,
request: suspend WPAPINetwork.() -> WPAPIResponse<T>
): WPAPIResponse<T> {
return when (site.origin) {
Expand All @@ -109,7 +111,7 @@ class WooNetwork @Inject constructor(
}

SiteModel.ORIGIN_WPCOM_REST -> {
handleRequestForJetpackSites(site) {
handleRequestForJetpackSites(site, requestContext) {
request()
}
}
Expand All @@ -122,6 +124,7 @@ class WooNetwork @Inject constructor(

private suspend fun <T : Any> handleRequestForJetpackSites(
site: SiteModel,
requestContext: RequestContext,
request: suspend WPAPINetwork.() -> WPAPIResponse<T>
): WPAPIResponse<T> {
if (!applicationPasswordsConfiguration.isEnabledForJetpack || !site.isApplicationPasswordsSupported) {
Expand All @@ -138,20 +141,14 @@ class WooNetwork @Inject constructor(

return when (val appPasswordsResponse = applicationPasswordsNetwork.request()) {
is WPAPIResponse.Success<*> -> {
AppLog.v(
AppLog.T.API,
"Request successful for site: ${site.url}, using Application Passwords"
)
(appPasswordsResponse as WPAPIResponse<T>).copyWith(
networkingMode = WPAPINetworkingMode.ApplicationPasswordsWithJetpack
)
}

is WPAPIResponse.Error<*> -> {
AppLog.w(
AppLog.T.API,
"Request to $ using Application Passwords, falling back to Jetpack Tunnel"
)
logMessageForFailedRequest(requestContext, site.url, appPasswordsResponse.error)

if (appPasswordsResponse.error.errorCode ==
ApplicationPasswordsNetwork.APPLICATION_PASSWORDS_NOT_SUPPORT_ERROR_CODE
) {
Expand All @@ -178,4 +175,21 @@ class WooNetwork @Inject constructor(
is WPAPIResponse.Error -> this.copy(networkingMode = networkingMode)
}
}

private fun logMessageForFailedRequest(requestContext: RequestContext, siteUrl: String, error: WPAPINetworkError) {
AppLog.w(
AppLog.T.API,
"Request failed using Application Passwords for Jetpack Site,\n" +
"site: ${siteUrl},\n" +
"path: ${requestContext.path},\n" +
"method: ${requestContext.method},\n" +
"error: HTTP status code ${error.volleyError.networkResponse?.statusCode}, " +
"error message: ${error.errorCode?.ifEmpty { null } ?: error.message}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice logging details, they’ll be helpful for debugging. 👍🏻

)
}

private data class RequestContext(
val path: String,
val method: String
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ public void setApplicationPasswordsAuthorizeUrl(String applicationPasswordsAutho

public boolean isApplicationPasswordsSupported() {
return mApplicationPasswordsAuthorizeUrl != null &&
!mApplicationPasswordsAuthorizeUrl.isEmpty();
!mApplicationPasswordsAuthorizeUrl.isEmpty();
}

public int getPublishedStatus() {
Expand Down