diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java index 59b4cb6a4a..26103b1c23 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/Authenticator.java @@ -24,7 +24,6 @@ import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest; import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest.WPComErrorListener; import org.wordpress.android.fluxc.network.rest.wpcom.WPComGsonRequest.WPComGsonNetworkError; -import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.WebauthnChallengeInfo; import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.WebauthnChallengeRequest; import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.WebauthnToken; import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.WebauthnTokenRequest; @@ -129,7 +128,7 @@ public OauthRequest makeRequest(String username, String password, String twoStep } public void makeRequest(String userId, String webauthnNonce, - Response.Listener listener, + Response.Listener listener, ErrorListener errorListener) { WebauthnChallengeRequest request = new WebauthnChallengeRequest( userId, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/VolleyWebauthnRequests.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/VolleyWebauthnRequests.kt index e84f4bbbd9..c9e6f0a43e 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/VolleyWebauthnRequests.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/VolleyWebauthnRequests.kt @@ -2,6 +2,8 @@ package org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn import com.android.volley.Response import com.android.volley.Response.ErrorListener +import com.google.gson.annotations.SerializedName +import org.json.JSONObject import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.BaseWebauthnRequest.WebauthnRequestParameters.AUTH_TYPE import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.BaseWebauthnRequest.WebauthnRequestParameters.CLIENT_DATA import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.BaseWebauthnRequest.WebauthnRequestParameters.CLIENT_ID @@ -16,9 +18,9 @@ class WebauthnChallengeRequest( twoStepNonce: String, clientId: String, clientSecret: String, - listener: Response.Listener, + listener: Response.Listener, errorListener: ErrorListener -): BaseWebauthnRequest(webauthnChallengeEndpointUrl, errorListener, listener) { +): BaseWebauthnRequest(webauthnChallengeEndpointUrl, errorListener, listener) { override val parameters: Map = mapOf( CLIENT_ID.value to clientId, CLIENT_SECRET.value to clientSecret, @@ -27,8 +29,7 @@ class WebauthnChallengeRequest( TWO_STEP_NONCE.value to twoStepNonce ) - override fun serializeResponse(response: String): WebauthnChallengeInfo = - gson.fromJson(response, WebauthnChallengeInfo::class.java) + override fun serializeResponse(response: String) = JSONObject(response) } @SuppressWarnings("LongParameterList") @@ -55,3 +56,8 @@ class WebauthnTokenRequest( override fun serializeResponse(response: String): WebauthnToken = gson.fromJson(response, WebauthnToken::class.java) } + +class WebauthnToken( + @SerializedName("bearer_token") + val bearerToken: String +) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/WebauthnModels.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/WebauthnModels.kt deleted file mode 100644 index b0d4876d84..0000000000 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/auth/webauthn/WebauthnModels.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn - -import com.google.gson.annotations.SerializedName - -class WebauthnChallengeInfo( - val challenge: String, - val rpId: String, - val allowCredentials: List, - val timeout: Int, - @SerializedName("two_step_nonce") - val twoStepNonce: String -) - -class WebauthnCredentialResponse( - val type: String, - val id: String, - val transports: List -) - -class WebauthnToken( - @SerializedName("bearer_token") - val bearerToken: String -) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java b/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java index 58cfe4e616..7e8e63c328 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/AccountStore.java @@ -11,6 +11,7 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import org.json.JSONObject; import org.wordpress.android.fluxc.Dispatcher; import org.wordpress.android.fluxc.Payload; import org.wordpress.android.fluxc.action.AccountAction; @@ -42,7 +43,6 @@ import org.wordpress.android.fluxc.network.rest.wpcom.auth.Authenticator.OauthResponse; import org.wordpress.android.fluxc.network.rest.wpcom.auth.Authenticator.Token; import org.wordpress.android.fluxc.network.rest.wpcom.auth.Authenticator.TwoFactorResponse; -import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.WebauthnChallengeInfo; import org.wordpress.android.fluxc.network.rest.wpcom.auth.webauthn.WebauthnToken; import org.wordpress.android.fluxc.network.xmlrpc.XMLRPCRequest.XmlRpcErrorType; import org.wordpress.android.fluxc.persistence.AccountSqlUtils; @@ -357,8 +357,14 @@ public StartWebauthnChallengePayload(String mUserId, String mWebauthnNonce) { } public static class WebauthnChallengeReceived extends OnChanged { - public WebauthnChallengeInfo mChallengeInfo; + private static final String TWO_STEP_NONCE_KEY = "two_step_nonce"; + + public JSONObject mJsonResponse; public String mUserId; + + public String getWebauthnNonce() { + return mJsonResponse.optString(TWO_STEP_NONCE_KEY); + } } public static class FinishWebauthnChallengePayload { @@ -1412,10 +1418,10 @@ private void handleSentAuthEmail(final AuthEmailResponsePayload payload) { private void requestWebauthnChallenge(final StartWebauthnChallengePayload payload) { mAuthenticator.makeRequest(payload.mUserId, payload.mWebauthnNonce, - (Response.Listener) info -> { + (Response.Listener) response -> { WebauthnChallengeReceived event = new WebauthnChallengeReceived(); - event.mChallengeInfo = info; event.mUserId = payload.mUserId; + event.mJsonResponse = response; emitChange(event); }, error -> {