Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Credential Manager] Add raw challenge JSON data #2949

Merged
merged 11 commits into from
Feb 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +128,7 @@ public OauthRequest makeRequest(String username, String password, String twoStep
}

public void makeRequest(String userId, String webauthnNonce,
Response.Listener<WebauthnChallengeInfo> listener,
Response.Listener<JSONObject> listener,
ErrorListener errorListener) {
WebauthnChallengeRequest request = new WebauthnChallengeRequest(
userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,9 +18,9 @@ class WebauthnChallengeRequest(
twoStepNonce: String,
clientId: String,
clientSecret: String,
listener: Response.Listener<WebauthnChallengeInfo>,
listener: Response.Listener<JSONObject>,
errorListener: ErrorListener
): BaseWebauthnRequest<WebauthnChallengeInfo>(webauthnChallengeEndpointUrl, errorListener, listener) {
): BaseWebauthnRequest<JSONObject>(webauthnChallengeEndpointUrl, errorListener, listener) {
override val parameters: Map<String, String> = mapOf(
CLIENT_ID.value to clientId,
CLIENT_SECRET.value to clientSecret,
Expand All @@ -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")
Expand All @@ -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
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -357,8 +357,14 @@ public StartWebauthnChallengePayload(String mUserId, String mWebauthnNonce) {
}

public static class WebauthnChallengeReceived extends OnChanged<AuthenticationError> {
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 {
Expand Down Expand Up @@ -1412,10 +1418,10 @@ private void handleSentAuthEmail(final AuthEmailResponsePayload payload) {

private void requestWebauthnChallenge(final StartWebauthnChallengePayload payload) {
mAuthenticator.makeRequest(payload.mUserId, payload.mWebauthnNonce,
(Response.Listener<WebauthnChallengeInfo>) info -> {
(Response.Listener<JSONObject>) response -> {
WebauthnChallengeReceived event = new WebauthnChallengeReceived();
event.mChallengeInfo = info;
event.mUserId = payload.mUserId;
event.mJsonResponse = response;
emitChange(event);
},
error -> {
Expand Down
Loading