Skip to content

Commit 93bf422

Browse files
committed
Addressed review comments
1 parent 75ca5a1 commit 93bf422

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

EXAMPLES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ WebAuthProvider.login(account)
215215
> [!NOTE]
216216
> This feature is currently available in [Early Access](https://auth0.com/docs/troubleshoot/product-lifecycle/product-release-stages#early-access). Please reach out to Auth0 support to get it enabled for your tenant.
217217
218-
[DPoP](https://www.rfc-editor.org/rfc/rfc9449.html) (Demonstrating Proof of Posession) is an application-level mechanism for sender-constraining OAuth 2.0 access and refresh tokens by proving that the app is in possession of a certain private key. You can enable it by calling the `useDPoP(context:Context)` method.
218+
[DPoP](https://www.rfc-editor.org/rfc/rfc9449.html) (Demonstrating Proof of Possession) is an application-level mechanism for sender-constraining OAuth 2.0 access and refresh tokens by proving that the app is in possession of a certain private key. You can enable it by calling the `useDPoP(context:Context)` method.
219219

220220
```kotlin
221221
WebAuthProvider
@@ -252,7 +252,7 @@ httpRequest.apply{
252252
}
253253
}
254254
```
255-
If your API is issuing DPoP nonce's to prevent replay attacks, you can pass the nonce value to the `getHeaderData()` method to include it in the DPoP proof. Use the `DPoPProvider.isNonceRequiredError(response: Response)` method to check if a particular API response failed because a nonce is required.
255+
If your API is issuing DPoP nonces to prevent replay attacks, you can pass the nonce value to the `getHeaderData()` method to include it in the DPoP proof. Use the `DPoPProvider.isNonceRequiredError(response: Response)` method to check if a particular API response failed because a nonce is required.
256256

257257
```kotlin
258258
if (DPoPProvider.isNonceRequiredError(response)) {
@@ -755,7 +755,7 @@ httpRequest.apply{
755755
}
756756
}
757757
```
758-
If your API is issuing DPoP nonce's to prevent replay attacks, you can pass the nonce value to the `getHeaderData()` method to include it in the DPoP proof. Use the `DPoPProvider.isNonceRequiredError(response: Response)` method to check if a particular API response failed because a nonce is required.
758+
If your API is issuing DPoP nonces to prevent replay attacks, you can pass the nonce value to the `getHeaderData()` method to include it in the DPoP proof. Use the `DPoPProvider.isNonceRequiredError(response: Response)` method to check if a particular API response failed because a nonce is required.
759759

760760
```kotlin
761761
if (DPoPProvider.isNonceRequiredError(response)) {

auth0/src/main/java/com/auth0/android/dpop/DPoPProvider.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public object DPoPProvider {
118118
}
119119

120120
/**
121-
* Method to clear the DPoP key pair from the keystore. It must be called when the user logs out from a session
121+
* Method to clear the DPoP key pair from the keystore. It must be called when the user logs out
122122
* to prevent reuse of the key pair in subsequent sessions.
123123
*
124124
* ```kotlin
@@ -130,7 +130,7 @@ public object DPoPProvider {
130130
* }
131131
*
132132
* ```
133-
* **Note** : It is the developers responsibility to invoke this method to clear the keystore when logging out a session.
133+
* **Note** : It is the developer's responsibility to invoke this method to clear the keystore when logging out .
134134
* @throws DPoPException if there is an error deleting the key pair.
135135
*/
136136
@Throws(DPoPException::class)
@@ -175,7 +175,7 @@ public object DPoPProvider {
175175
}
176176

177177
/**
178-
* Generates a new key pair for DPoP if it does not already exist. This should be called before making any requests that require DPoP proof.
178+
* Generates a new key pair for DPoP if it does not already exist. This should be called before making any requests that require a DPoP proof.
179179
*
180180
* ```kotlin
181181
*
@@ -201,7 +201,7 @@ public object DPoPProvider {
201201

202202
/**
203203
* Generates the header data for a request that requires DPoP proof of possession. The `Authorization` header value is created
204-
* using the access token and token type. The `DPoP` header value contains the generated DPoP proof
204+
* using the access token and token type. The `DPoP` header value contains the generated DPoP proof.
205205
*
206206
* ```kotlin
207207
*

auth0/src/main/java/com/auth0/android/request/RetryInterceptor.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@ internal class RetryInterceptor : Interceptor {
1616

1717
//Handling DPoP Nonce retry
1818
if (DPoPProvider.isNonceRequiredError(response) && currentRetryCount < DPoPProvider.MAX_RETRY_COUNT) {
19-
DPoPProvider.storeNonce(response)
20-
val accessToken =
21-
request.headers[AUTHORIZATION_HEADER]?.substringAfter(DPOP_LIMITER)?.trim()
22-
val dpopProof = DPoPProvider.generateProof(
23-
httpUrl = request.url.toString(),
24-
httpMethod = request.method,
25-
accessToken = accessToken,
26-
nonce = DPoPProvider.auth0Nonce
27-
)
28-
if (dpopProof != null) {
29-
response.close()
30-
val newRequest = request.newBuilder()
31-
.header(DPoPProvider.DPOP_HEADER, dpopProof)
32-
.header(RETRY_COUNT_HEADER, (currentRetryCount + 1).toString())
33-
.build()
34-
return chain.proceed(newRequest)
19+
synchronized(this) {
20+
DPoPProvider.storeNonce(response)
21+
val accessToken =
22+
request.headers[AUTHORIZATION_HEADER]?.substringAfter(DPOP_LIMITER)?.trim()
23+
val dpopProof = DPoPProvider.generateProof(
24+
httpUrl = request.url.toString(),
25+
httpMethod = request.method,
26+
accessToken = accessToken,
27+
nonce = DPoPProvider.auth0Nonce
28+
)
29+
if (dpopProof != null) {
30+
response.close()
31+
val newRequest = request.newBuilder()
32+
.header(DPoPProvider.DPOP_HEADER, dpopProof)
33+
.header(RETRY_COUNT_HEADER, (currentRetryCount + 1).toString())
34+
.build()
35+
return chain.proceed(newRequest)
36+
}
3537
}
3638
}
3739
return response

auth0/src/test/java/com/auth0/android/provider/WebAuthProviderTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public class WebAuthProviderTest {
322322
//jwk
323323

324324
@Test
325-
public fun enablingDPoPWillGenerateNEwKEyPairIfOneDoesNotExist() {
325+
public fun enablingDPoPWillGenerateNewKeyPairIfOneDoesNotExist() {
326326
`when`(mockKeyStore.hasKeyPair()).thenReturn(false)
327327
val context: Context = mock()
328328
WebAuthProvider.useDPoP(context)
@@ -348,7 +348,7 @@ public class WebAuthProviderTest {
348348
}
349349

350350
@Test
351-
public fun shouldNotHaveDpopJwkOnLoginIfDPoPIsEnabled() {
351+
public fun shouldHaveDpopJwkOnLoginIfDPoPIsEnabled() {
352352
`when`(mockKeyStore.hasKeyPair()).thenReturn(true)
353353
`when`(mockKeyStore.getKeyPair()).thenReturn(Pair(mock(), FakeECPublicKey()))
354354

auth0/src/test/java/com/auth0/android/request/DefaultClientTest.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class DefaultClientTest {
8383
@Test
8484
public fun shouldHaveLoggingDisabledByDefault() {
8585
val netClient = DefaultClient(enableLogging = false)
86-
assertThat(DefaultClient().okHttpClient.interceptors, hasSize(1))
86+
assertThat(netClient.okHttpClient.interceptors, hasSize(1))
8787
val interceptor: Interceptor = netClient.okHttpClient.interceptors[0]
8888
assert(
8989
interceptor is RetryInterceptor,
@@ -92,7 +92,12 @@ public class DefaultClientTest {
9292

9393
@Test
9494
public fun shouldHaveRetryInterceptorEnabled() {
95-
assertThat(DefaultClient().okHttpClient.interceptors, hasSize(1))
95+
val netClient = DefaultClient(enableLogging = false)
96+
assertThat(netClient.okHttpClient.interceptors, hasSize(1))
97+
val interceptor: Interceptor = netClient.okHttpClient.interceptors[0]
98+
assert(
99+
interceptor is RetryInterceptor,
100+
)
96101
}
97102

98103
@Test

0 commit comments

Comments
 (0)