Skip to content

Commit

Permalink
chore: apple login token 체크용 로직
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast committed Jan 24, 2024
1 parent 21f6c4c commit 5655ee7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public String get(String authorizationCode) {
authorizationCode
).getIdToken();

// return TokenDecoder.decodePayload(idToken, AppleIdTokenPayload.class);
return idToken;
return TokenDecoder.decodePayload(idToken, AppleIdTokenPayload.class);
}

private String generateClientSecret() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.uspray.uspray.external.client.oauth2.apple;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Base64;

public class TokenDecoder {

public static <T> T decodePayload(String token, Class<T> targetClass) {
public static <T> String decodePayload(String token, Class<T> targetClass) {

String[] tokenParts = token.split("\\.");
String payloadJWT = tokenParts[1];
Base64.Decoder decoder = Base64.getUrlDecoder();
String payload = new String(decoder.decode(payloadJWT));
ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return payload;

try {
return objectMapper.readValue(payload, targetClass);
} catch (Exception e) {
throw new RuntimeException("Error decoding token payload", e);
}
// ObjectMapper objectMapper = new ObjectMapper()
// .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//
// try {
// return objectMapper.readValue(payload, targetClass);
// } catch (Exception e) {
// throw new RuntimeException("Error decoding token payload", e);
// }
}
}

0 comments on commit 5655ee7

Please sign in to comment.