apple / app-store-server-library-java

MIT License
166 stars 38 forks source link

Error when decoding signedPayload #126

Closed yoonhoe-gn closed 2 weeks ago

yoonhoe-gn commented 3 weeks ago

Hello I am trying to use this sdk to verify the Apple in app purchasese. Currently I am testing in a sandbox environment and the code I am using to verify the signed payload looks like below

@Override
    protected SubscriptionReceipt verifyReceipt(AppleNotificationData subscribedNotification) {
        String signedPayload = subscribedNotification.getSignedPayload();

        try {
            Set<InputStream> rootCAs = Set.of(
                new ClassPathResource("cert/AppleRootCA-G2.cer").getInputStream(),
                new ClassPathResource("cert/AppleRootCA-G3.cer").getInputStream()
            );
            SignedDataVerifier signedPayloadVerifier = new SignedDataVerifier(rootCAs, appStoreProperties.bundleId(), appStoreProperties.appAppleId(),
                Environment.valueOf(appStoreProperties.environment()), true);

            ResponseBodyV2DecodedPayload payload = signedPayloadVerifier.verifyAndDecodeNotification(signedPayload);
            AppleSubscriptionState subscriptionState = AppleSubscriptionState.fromNotificationType(
                AppleNotificationType.fromString(payload.getNotificationType().getValue()));

the signedPayload is in the format of what has been listed and starts with ey

However, I get a

Verification failed with status VERIFICATION_FAILURE

and when I look into the error further I get an error saying that there are 3 parts but got 0

Caused by: com.auth0.jwt.exceptions.JWTDecodeException: The token was expected to have 3 parts, but got 0.

It would be appreciated what the problem might be and if possible get a sample signedPayload that I can decode