Skip to content

Commit

Permalink
[fix] rename method name
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Jul 12, 2024
1 parent 32354f5 commit 979c615
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
@Component
public class ApplePublicKeyGenerator {

private static final String SIGN_ALGORITHM_HEADER_KEY = "alg";
private static final String KEY_ID_HEADER_KEY = "kid";
private static final String SIGN_ALGORITHM_HEADER_KEY = "alg";

public PublicKey generatePublicKey(
Map<String, String> headers,
ApplePublicKeys applePublicKeys
) {
public PublicKey generatePublicKey(Map<String, String> headers, ApplePublicKeys applePublicKeys) {
ApplePublicKey applePublicKey = applePublicKeys
.getMatchedPublicKey(headers.get(KEY_ID_HEADER_KEY), headers.get(SIGN_ALGORITHM_HEADER_KEY));
return getPublicKey(applePublicKey);
}

private PublicKey getPublicKey(ApplePublicKey applePublicKey) {

byte[] nBytes = Base64.getUrlDecoder().decode(applePublicKey.n());
byte[] eBytes = Base64.getUrlDecoder().decode(applePublicKey.e());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.hankki.hankkiserver.external.openfeign.apple.dto;

import java.util.Optional;

public record ApplePublicKey(
String kty,
String kid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@


public record ApplePublicKeys(
List<ApplePublicKey> applePublicKeys
List<ApplePublicKey> keys
) {
public ApplePublicKey getMatchedPublicKey(String kid, String alg) {
return this.applePublicKeys.stream()
.filter(key -> key.kid().equals(kid) && key.alg().equals(alg))
.findFirst()
return keys.stream()
.filter(applePublicKey -> applePublicKey.kid().equals(kid) && applePublicKey.alg().equals(alg))
.findAny()
.orElseThrow(() -> new UnauthorizedException(AuthErrorCode.INVALID_APPLE_IDENTITY_TOKEN));
}
}

0 comments on commit 979c615

Please sign in to comment.