|
13 | 13 | import org.springframework.util.LinkedMultiValueMap; |
14 | 14 | import org.springframework.util.MultiValueMap; |
15 | 15 | import org.springframework.web.client.RestClient; |
| 16 | +import org.springframework.web.client.RestClientException; |
| 17 | +import org.springframework.web.client.RestClientResponseException; |
16 | 18 |
|
17 | 19 | import java.security.PublicKey; |
18 | 20 | import java.util.Map; |
@@ -60,12 +62,28 @@ public AppleTokenResponse getAppleRefreshToken(String authorizationCode) { |
60 | 62 | public void revokeToken(String refreshToken) { |
61 | 63 | MultiValueMap<String, String> body = getRevokeTokenBody(refreshToken); |
62 | 64 |
|
63 | | - restClient.post() |
64 | | - .uri(appleRevokeUrl) |
65 | | - .contentType(MediaType.APPLICATION_FORM_URLENCODED) |
66 | | - .body(body) |
67 | | - .retrieve() |
68 | | - .toBodilessEntity(); |
| 65 | + try { |
| 66 | + log.info("Apple revoke request started. token={}", maskToken(refreshToken)); |
| 67 | + |
| 68 | + restClient.post() |
| 69 | + .uri(appleRevokeUrl) |
| 70 | + .contentType(MediaType.APPLICATION_FORM_URLENCODED) |
| 71 | + .body(body) |
| 72 | + .retrieve() |
| 73 | + .toBodilessEntity(); |
| 74 | + |
| 75 | + log.info("Apple revoke request succeeded. token={}", maskToken(refreshToken)); |
| 76 | + } catch (RestClientResponseException e) { |
| 77 | + log.error("Apple revoke request failed. status={}, responseBody={}, token={}", |
| 78 | + e.getStatusCode().value(), |
| 79 | + e.getResponseBodyAsString(), |
| 80 | + maskToken(refreshToken), |
| 81 | + e); |
| 82 | + throw e; |
| 83 | + } catch (RestClientException e) { |
| 84 | + log.error("Apple revoke request failed without response. token={}", maskToken(refreshToken), e); |
| 85 | + throw e; |
| 86 | + } |
69 | 87 | } |
70 | 88 |
|
71 | 89 | public Claims verifyIdentityToken(String identityToken) { |
@@ -121,5 +139,15 @@ private MultiValueMap<String, String> getCreateTokenBody(String authorizationCod |
121 | 139 | return body; |
122 | 140 | } |
123 | 141 |
|
| 142 | + private String maskToken(String token) { |
| 143 | + if (token == null || token.isBlank()) { |
| 144 | + return "EMPTY"; |
| 145 | + } |
| 146 | + if (token.length() <= 8) { |
| 147 | + return "****"; |
| 148 | + } |
| 149 | + return token.substring(0, 4) + "..." + token.substring(token.length() - 4); |
| 150 | + } |
| 151 | + |
124 | 152 |
|
125 | 153 | } |
0 commit comments