@@ -826,13 +826,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
826826 )
827827 val request = factory.post(url.toString(), credentialsAdapter)
828828 .addParameters(parameters)
829- try {
830- DPoPProvider .generateProof(request.getUrl(), request.getHttpMethod().toString())?.let {
831- request.addHeader(DPoPProvider .DPOP_HEADER , it)
832- }
833- } catch (exception: DPoPException ) {
834- Log .e(TAG , " Error generating DPoP proof: ${exception.stackTraceToString()} " )
835- }
829+ .addDPoPHeader()
836830 return request
837831 }
838832
@@ -969,14 +963,8 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
969963 Credentials ::class .java, gson
970964 )
971965 val request = factory.post(url.toString(), credentialsAdapter)
972- request.addParameters(parameters)
973- try {
974- DPoPProvider .generateProof(request.getUrl(), request.getHttpMethod().toString())?.let {
975- request.addHeader(DPoPProvider .DPOP_HEADER , it)
976- }
977- } catch (exception: DPoPException ) {
978- Log .e(TAG , " Error generating DPoP proof: ${exception.stackTraceToString()} " )
979- }
966+ .addParameters(parameters)
967+ .addDPoPHeader()
980968 return request
981969 }
982970
@@ -1042,14 +1030,8 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
10421030 T ::class .java, gson
10431031 )
10441032 val request = factory.post(url.toString(), adapter)
1045- request.addParameters(requestParameters)
1046- try {
1047- DPoPProvider .generateProof(request.getUrl(), request.getHttpMethod().toString())?.let {
1048- request.addHeader(DPoPProvider .DPOP_HEADER , it)
1049- }
1050- } catch (exception: DPoPException ) {
1051- Log .e(TAG , " Error generating DPoP proof: ${exception.stackTraceToString()} " )
1052- }
1033+ .addParameters(requestParameters)
1034+ .addDPoPHeader()
10531035 return request
10541036 }
10551037
@@ -1073,13 +1055,7 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
10731055 factory.post(url.toString(), credentialsAdapter), clientId, baseURL
10741056 )
10751057 request.addParameters(requestParameters)
1076- try {
1077- DPoPProvider .generateProof(request.getUrl(), request.getHttpMethod().toString())?.let {
1078- request.addHeader(DPoPProvider .DPOP_HEADER , it)
1079- }
1080- } catch (exception: DPoPException ) {
1081- Log .e(TAG , " Error generating DPoP proof: ${exception.stackTraceToString()} " )
1082- }
1058+ .addDPoPHeader()
10831059 return request
10841060 }
10851061
@@ -1109,6 +1085,20 @@ public class AuthenticationAPIClient @VisibleForTesting(otherwise = VisibleForTe
11091085 return factory.get(url.toString(), userProfileAdapter)
11101086 }
11111087
1088+ /* *
1089+ * Helper method to add DPoP proof to all the [Request]
1090+ */
1091+ private fun <T > Request <T , AuthenticationException >.addDPoPHeader (): Request <T , AuthenticationException > {
1092+ try {
1093+ DPoPProvider .generateProof(getUrl(), getHttpMethod().toString())?.let {
1094+ addHeader(DPoPProvider .DPOP_HEADER , it)
1095+ }
1096+ } catch (exception: DPoPException ) {
1097+ Log .e(TAG , " Error generating DPoP proof: ${exception.stackTraceToString()} " )
1098+ }
1099+ return this
1100+ }
1101+
11121102 private companion object {
11131103 private const val SMS_CONNECTION = " sms"
11141104 private const val EMAIL_CONNECTION = " email"
0 commit comments