Problem/Motivation

APNs token validation is not handled yet. Let's add support and tests for it.

Issue fork apns_php-3600668

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ptmkenny created an issue. See original summary.

ptmkenny’s picture

Summary by opus 4.8:

 ApnsPhpMessagingApi::validateToken() is a stub: it throws on an empty/whitespace
 string and otherwise returns TRUE for every non-empty token
 (dev/apns_php/src/Service/ApnsPhpMessagingApi.php:142). The unit test
 testValidateTokenAcceptsNonEmpty codifies that stub as correct. The
 log_token_validation_result config key is never read, and
 ApnsPhpInvalidTokenException is unused.

 Why no probe: unlike FCM (which firebase_php validates via
 validateRegistrationTokens), APNs has no pre-validation endpoint (confirmed
 against Apple's docs + the Pushok README). A token's validity is only knowable from
 the response to a real send (getStatusCode() / getErrorReason()). Apple's
 guidance: stop using tokens that return Unregistered / BadDeviceToken /
 DeviceTokenNotForTopic; treat 403 (Forbidden / ExpiredProviderToken — these are
 auth/JWT, not device-token, problems), 413, 429, and 5xx as transient and keep
 the token.

ptmkenny’s picture

Summary of implementation:

 dev/apns_php — validateToken is now a real classifier

  - src/Service/ApnsPhpMessagingApi.php: validateToken(ApnsResponseInterface): bool — 200→true;
  410/400-BadDeviceToken/DeviceTokenNotForTopic→false; everything else throws a categorized exception via match. Wired
  log_token_validation_result (redacted, hashed-token logging via new hashTokenForLog). Moved the empty-token guard into
  sendMessageMultipleDevices.
  - src/Exception/: new ApnsPhpAuthenticationException (403), ApnsPhpPayloadException (400-non-token/413),
  ApnsPhpServerException (429/5xx) — all extend ApnsPhpException.
  - src/ApnsPhpMessagingApiInterface.php: signature + docstring rewritten (the wrong "Google's servers" text is gone;
  documents the throw contract).
  - Tests: replaced the three stub tests with response-driven cases (200/410/400-bad/400-not-for-topic, 403→auth,
  413→payload, 429/503→server, redaction-on/off) and relocated the empty-token assertions to the send path.
ptmkenny’s picture

Title: Add token validation » Implement token validation from APNs responses

  • ptmkenny committed 770f69c6 on 1.0.x
    feat: #3600668 Implement token validation from APNs responses
    
    By:...
ptmkenny’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.