Skip to content
Snippets Groups Projects
Commit 547d72ab authored by Patrick Kenny's avatar Patrick Kenny
Browse files

Issue #3450693 by ptmkenny: Add validateToken() method

parent d3fb2348
No related branches found
No related tags found
1 merge request!33Pn registration tokens integration
Pipeline #187217 passed
...@@ -119,4 +119,15 @@ interface FirebasePhpMessagingApiInterface { ...@@ -119,4 +119,15 @@ interface FirebasePhpMessagingApiInterface {
?int $badge_count = NULL, ?int $badge_count = NULL,
): MulticastSendReport; ): MulticastSendReport;
/**
* Validates a registration token with Google's servers.
*
* @param string $token
* The registration token to validate.
*
* @return bool
* TRUE if the token is valid. FALSE if not.
*/
public function validateToken(string $token): bool;
} }
...@@ -213,4 +213,22 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir ...@@ -213,4 +213,22 @@ class FirebasePhpMessagingApi extends FirebasePhpMessagingService implements Fir
} }
} }
/**
* {@inheritdoc}
*/
public function validateToken(string $token): bool {
if (trim($token) === '') {
throw new FirebasePhpInvalidArgumentException('Token cannot be an empty string!');
}
/** @var non-empty-string $token */
$messaging_service = $this->getMessaging();
$output = $messaging_service->validateRegistrationTokens($token);
// We are only validating one token, so if there is a single invalid result,
// the token is invalid.
if (isset($output['invalid'][0])) {
return FALSE;
}
return TRUE;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment