@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | // INVALID_USERID: The client authenticated a different user than the server expected. This error is returned when |
| 117 | 117 | // the application stated an authentication session specifying the userId and later during the authentication |
| 118 | 118 | // provides a different userId |
| 119 | - const AUTH_RESULT_INVALID_USERID = 5; |
|
| 119 | + const AUTH_RESULT_INVALID_USERID = 5; |
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | 122 | * The default OCRA Suite (RFC 6287) to use for authentication in Tiqr |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @param int $version The tiqr protocol version to use (defaults to the latest) |
| 244 | 244 | * @throws Exception |
| 245 | 245 | */ |
| 246 | - public function __construct(LoggerInterface $logger, array $options=array(), int $version = 2) |
|
| 246 | + public function __construct(LoggerInterface $logger, array $options = array(), int $version = 2) |
|
| 247 | 247 | { |
| 248 | 248 | $this->_options = $options; // Used to later get settings for Tiqr_Message_* |
| 249 | 249 | $this->logger = $logger; |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | case 'APNS': |
| 344 | 344 | case 'APNS_DIRECT': |
| 345 | 345 | $apns_version = $this->_options['apns.version'] ?? 1; |
| 346 | - if ($apns_version ==2 ) |
|
| 346 | + if ($apns_version == 2) |
|
| 347 | 347 | $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
| 348 | 348 | else |
| 349 | 349 | $message = new Tiqr_Message_APNS($this->_options, $this->logger); |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType)); |
| 363 | 363 | $message->setId(time()); |
| 364 | - $message->setText("Please authenticate for " . $this->_name); |
|
| 364 | + $message->setText("Please authenticate for ".$this->_name); |
|
| 365 | 365 | $message->setAddress($notificationAddress); |
| 366 | 366 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
| 367 | 367 | $message->send(); |
@@ -407,13 +407,13 @@ discard block |
||
| 407 | 407 | * @return string The authentication sessionKey |
| 408 | 408 | * @throws Exception when starting the authentication session failed |
| 409 | 409 | */ |
| 410 | - public function startAuthenticationSession(string $userId="", string $sessionId="", string $spIdentifier=""): string |
|
| 410 | + public function startAuthenticationSession(string $userId = "", string $sessionId = "", string $spIdentifier = ""): string |
|
| 411 | 411 | { |
| 412 | - if ($sessionId=="") { |
|
| 412 | + if ($sessionId == "") { |
|
| 413 | 413 | $sessionId = session_id(); |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - if ($spIdentifier=="") { |
|
| 416 | + if ($spIdentifier == "") { |
|
| 417 | 417 | $spIdentifier = $this->_identifier; |
| 418 | 418 | } |
| 419 | 419 | |
@@ -422,11 +422,11 @@ discard block |
||
| 422 | 422 | |
| 423 | 423 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
| 424 | 424 | |
| 425 | - if ($userId!="") { |
|
| 425 | + if ($userId != "") { |
|
| 426 | 426 | $data["userId"] = $userId; |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - $this->_stateStorage->setValue(self::PREFIX_CHALLENGE . $sessionKey, $data, self::CHALLENGE_EXPIRE); |
|
| 429 | + $this->_stateStorage->setValue(self::PREFIX_CHALLENGE.$sessionKey, $data, self::CHALLENGE_EXPIRE); |
|
| 430 | 430 | |
| 431 | 431 | return $sessionKey; |
| 432 | 432 | } |
@@ -446,9 +446,9 @@ discard block |
||
| 446 | 446 | * @return String The enrollment key |
| 447 | 447 | * @throws Exception when start the enrollement session failed |
| 448 | 448 | */ |
| 449 | - public function startEnrollmentSession(string $userId, string $displayName, string $sessionId=""): string |
|
| 449 | + public function startEnrollmentSession(string $userId, string $displayName, string $sessionId = ""): string |
|
| 450 | 450 | { |
| 451 | - if ($sessionId=="") { |
|
| 451 | + if ($sessionId == "") { |
|
| 452 | 452 | $sessionId = session_id(); |
| 453 | 453 | } |
| 454 | 454 | $enrollmentKey = $this->_uniqueSessionKey(); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | "displayName" => $displayName, |
| 458 | 458 | "sessionId" => $sessionId |
| 459 | 459 | ]; |
| 460 | - $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT . $enrollmentKey, $data, self::ENROLLMENT_EXPIRE); |
|
| 460 | + $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT.$enrollmentKey, $data, self::ENROLLMENT_EXPIRE); |
|
| 461 | 461 | $this->_setEnrollmentStatus($sessionId, self::ENROLLMENT_STATUS_INITIALIZED); |
| 462 | 462 | |
| 463 | 463 | return $enrollmentKey; |
@@ -468,9 +468,9 @@ discard block |
||
| 468 | 468 | * @param string $sessionId The application's session identifier (defaults to php session) |
| 469 | 469 | * @throws Exception when resetting the session failed |
| 470 | 470 | */ |
| 471 | - public function resetEnrollmentSession(string $sessionId=""): void |
|
| 471 | + public function resetEnrollmentSession(string $sessionId = ""): void |
|
| 472 | 472 | { |
| 473 | - if ($sessionId=="") { |
|
| 473 | + if ($sessionId == "") { |
|
| 474 | 474 | $sessionId = session_id(); |
| 475 | 475 | } |
| 476 | 476 | |
@@ -505,9 +505,9 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | * @throws Exception when an error communicating with the state storage backend was detected |
| 507 | 507 | */ |
| 508 | - public function getEnrollmentStatus(string $sessionId=""): int |
|
| 508 | + public function getEnrollmentStatus(string $sessionId = ""): int |
|
| 509 | 509 | { |
| 510 | - if ($sessionId=="") { |
|
| 510 | + if ($sessionId == "") { |
|
| 511 | 511 | $sessionId = session_id(); |
| 512 | 512 | } |
| 513 | 513 | $status = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_STATUS.$sessionId); |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | */ |
| 565 | 565 | public function getEnrollmentMetadata(string $enrollmentKey, string $authenticationUrl, string $enrollmentUrl): array |
| 566 | 566 | { |
| 567 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 567 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 568 | 568 | if (!is_array($data)) { |
| 569 | 569 | $this->logger->error('Unable to find enrollment metadata in state storage'); |
| 570 | 570 | throw new Exception('Unable to find enrollment metadata in state storage'); |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | array("identifier" =>$data["userId"], |
| 584 | 584 | "displayName"=>$data["displayName"])); |
| 585 | 585 | |
| 586 | - $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 586 | + $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 587 | 587 | |
| 588 | 588 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_RETRIEVED); |
| 589 | 589 | return $metadata; |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | */ |
| 612 | 612 | public function getEnrollmentSecret(string $enrollmentKey): string |
| 613 | 613 | { |
| 614 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 614 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 615 | 615 | if (!is_array($data)) { |
| 616 | 616 | $this->logger->error('getEnrollmentSecret: enrollment key not found'); |
| 617 | 617 | throw new RuntimeException('enrollment key not found'); |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | ]; |
| 628 | 628 | $enrollmentSecret = $this->_uniqueSessionKey(); |
| 629 | 629 | $this->_stateStorage->setValue( |
| 630 | - self::PREFIX_ENROLLMENT_SECRET . $enrollmentSecret, |
|
| 630 | + self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret, |
|
| 631 | 631 | $enrollmentData, |
| 632 | 632 | self::ENROLLMENT_EXPIRE |
| 633 | 633 | ); |
@@ -655,11 +655,11 @@ discard block |
||
| 655 | 655 | public function validateEnrollmentSecret(string $enrollmentSecret): string |
| 656 | 656 | { |
| 657 | 657 | try { |
| 658 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET . $enrollmentSecret); |
|
| 658 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret); |
|
| 659 | 659 | if (NULL === $data) { |
| 660 | 660 | throw new RuntimeException('Enrollment secret not found'); |
| 661 | 661 | } |
| 662 | - if ( !is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
| 662 | + if (!is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
| 663 | 663 | throw new RuntimeException('Invalid enrollment data'); |
| 664 | 664 | } |
| 665 | 665 | |
@@ -689,17 +689,17 @@ discard block |
||
| 689 | 689 | public function finalizeEnrollment(string $enrollmentSecret): bool |
| 690 | 690 | { |
| 691 | 691 | try { |
| 692 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET . $enrollmentSecret); |
|
| 692 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret); |
|
| 693 | 693 | if (NULL === $data) { |
| 694 | 694 | throw new RuntimeException('Enrollment secret not found'); |
| 695 | 695 | } |
| 696 | 696 | if (is_array($data)) { |
| 697 | 697 | // Enrollment is finalized, destroy our session data. |
| 698 | - $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT_SECRET . $enrollmentSecret); |
|
| 698 | + $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret); |
|
| 699 | 699 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED); |
| 700 | 700 | } else { |
| 701 | 701 | $this->logger->error( |
| 702 | - 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' . |
|
| 702 | + 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '. |
|
| 703 | 703 | 'Warning! the method will still return "true" as a result.' |
| 704 | 704 | ); |
| 705 | 705 | } |
@@ -747,7 +747,7 @@ discard block |
||
| 747 | 747 | public function authenticate(string $userId, string $userSecret, string $sessionKey, string $response): int |
| 748 | 748 | { |
| 749 | 749 | try { |
| 750 | - $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 750 | + $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 751 | 751 | if (is_null($state)) { |
| 752 | 752 | $this->logger->notice('The auth challenge could not be found in the state storage'); |
| 753 | 753 | return self::AUTH_RESULT_INVALID_CHALLENGE; |
@@ -757,9 +757,9 @@ discard block |
||
| 757 | 757 | throw $e; |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
| 761 | - $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
| 762 | - if (!is_string($sessionId) || (!is_string($challenge)) ) { |
|
| 760 | + $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
| 761 | + $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
| 762 | + if (!is_string($sessionId) || (!is_string($challenge))) { |
|
| 763 | 763 | throw new RuntimeException('Invalid state for state storage'); |
| 764 | 764 | } |
| 765 | 765 | |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | $challengeUserId = $state["userId"] ?? NULL; |
| 769 | 769 | |
| 770 | 770 | // If the application requested a specific userId, verify that that is that userId that we're now authenticating |
| 771 | - if ($challengeUserId!==NULL && ($userId !== $challengeUserId)) { |
|
| 771 | + if ($challengeUserId !== NULL && ($userId !== $challengeUserId)) { |
|
| 772 | 772 | $this->logger->error( |
| 773 | 773 | sprintf('Authentication failed: the requested userId "%s" does not match userId "%s" that is being authenticated', |
| 774 | 774 | $challengeUserId, $userId) |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | |
| 786 | 786 | if ($equal) { |
| 787 | 787 | // Set application session as authenticated |
| 788 | - $this->_stateStorage->setValue(self::PREFIX_AUTHENTICATED . $sessionId, $userId, self::LOGIN_EXPIRE); |
|
| 788 | + $this->_stateStorage->setValue(self::PREFIX_AUTHENTICATED.$sessionId, $userId, self::LOGIN_EXPIRE); |
|
| 789 | 789 | $this->logger->notice(sprintf('Authenticated user "%s" in session "%s"', $userId, $sessionId)); |
| 790 | 790 | |
| 791 | 791 | // Cleanup challenge |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | // Cleaning up only after successful authentication enables the user to retry authentication after e.g. an |
| 795 | 795 | // invalid response |
| 796 | 796 | try { |
| 797 | - $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE . $sessionKey); // May throw |
|
| 797 | + $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE.$sessionKey); // May throw |
|
| 798 | 798 | } catch (Exception $e) { |
| 799 | 799 | // Only log error |
| 800 | 800 | $this->logger->warning('Could not delete authentication session key', array('error' => $e)); |
@@ -816,9 +816,9 @@ discard block |
||
| 816 | 816 | * |
| 817 | 817 | * @throws Exception when there was an error communicating with the storage backed |
| 818 | 818 | */ |
| 819 | - public function logout(string $sessionId=""): void |
|
| 819 | + public function logout(string $sessionId = ""): void |
|
| 820 | 820 | { |
| 821 | - if ($sessionId=="") { |
|
| 821 | + if ($sessionId == "") { |
|
| 822 | 822 | $sessionId = session_id(); |
| 823 | 823 | } |
| 824 | 824 | |
@@ -858,9 +858,9 @@ discard block |
||
| 858 | 858 | * |
| 859 | 859 | * Does not throw |
| 860 | 860 | */ |
| 861 | - public function getAuthenticatedUser(string $sessionId=""): ?string |
|
| 861 | + public function getAuthenticatedUser(string $sessionId = ""): ?string |
|
| 862 | 862 | { |
| 863 | - if ($sessionId=="") { |
|
| 863 | + if ($sessionId == "") { |
|
| 864 | 864 | $this->logger->debug('Using the PHP session id, as no session id was provided'); |
| 865 | 865 | $sessionId = session_id(); |
| 866 | 866 | } |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | // We probably just generated the challenge and stored it in the StateStorage |
| 890 | 890 | // We can save a roundtrip to the storage backend here by reusing this information |
| 891 | 891 | |
| 892 | - $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 892 | + $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 893 | 893 | if (is_null($state)) { |
| 894 | 894 | $this->logger->error( |
| 895 | 895 | sprintf( |
@@ -904,22 +904,22 @@ discard block |
||
| 904 | 904 | $challenge = $state["challenge"] ?? ''; |
| 905 | 905 | $spIdentifier = $state["spIdentifier"] ?? ''; |
| 906 | 906 | |
| 907 | - if ( (strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0) ) { |
|
| 907 | + if ((strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0)) { |
|
| 908 | 908 | // Create universal Link |
| 909 | - $parameters=array(); |
|
| 909 | + $parameters = array(); |
|
| 910 | 910 | if (!is_null($userId)) { |
| 911 | - $parameters[]='u='.urlencode($userId); |
|
| 911 | + $parameters[] = 'u='.urlencode($userId); |
|
| 912 | 912 | } |
| 913 | - $parameters[]='s='.urlencode($sessionKey); |
|
| 914 | - $parameters[]='q='.urlencode($challenge); |
|
| 915 | - $parameters[]='i='.urlencode($this->getIdentifier()); |
|
| 916 | - $parameters[]='v='.urlencode($this->_protocolVersion); |
|
| 913 | + $parameters[] = 's='.urlencode($sessionKey); |
|
| 914 | + $parameters[] = 'q='.urlencode($challenge); |
|
| 915 | + $parameters[] = 'i='.urlencode($this->getIdentifier()); |
|
| 916 | + $parameters[] = 'v='.urlencode($this->_protocolVersion); |
|
| 917 | 917 | return $this->_protocolAuth.'?'.implode('&', $parameters); |
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | // Create custom URL scheme |
| 921 | 921 | // Last bit is the spIdentifier |
| 922 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 922 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | { |
| 931 | 931 | // The are two formats see: https://tiqr.org/technical/protocol/ |
| 932 | 932 | |
| 933 | - if ( (strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0) ) { |
|
| 933 | + if ((strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0)) { |
|
| 934 | 934 | // Create universal Link |
| 935 | 935 | return $this->_protocolEnroll.'?metadata='.urlencode($metadataUrl); |
| 936 | 936 | } |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | protected function _uniqueSessionKey(): string |
| 950 | 950 | { |
| 951 | 951 | |
| 952 | - return bin2hex( Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES) ); |
|
| 952 | + return bin2hex(Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES)); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | /** |
@@ -283,8 +283,7 @@ discard block |
||
| 283 | 283 | if (isset($options['ocraservice']) && $options['ocraservice']['type'] != 'tiqr') { |
| 284 | 284 | $options['ocraservice']['ocra.suite'] = $this->_ocraSuite; |
| 285 | 285 | $this->_ocraService = Tiqr_OcraService::getOcraService($options['ocraservice']['type'], $options['ocraservice'], $logger); |
| 286 | - } |
|
| 287 | - else { // Create default ocraservice |
|
| 286 | + } else { // Create default ocraservice |
|
| 288 | 287 | $this->_ocraService = Tiqr_OcraService::getOcraService('tiqr', array('ocra.suite' => $this->_ocraSuite), $logger); |
| 289 | 288 | } |
| 290 | 289 | } |
@@ -343,10 +342,11 @@ discard block |
||
| 343 | 342 | case 'APNS': |
| 344 | 343 | case 'APNS_DIRECT': |
| 345 | 344 | $apns_version = $this->_options['apns.version'] ?? 1; |
| 346 | - if ($apns_version ==2 ) |
|
| 347 | - $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
|
| 348 | - else |
|
| 349 | - $message = new Tiqr_Message_APNS($this->_options, $this->logger); |
|
| 345 | + if ($apns_version ==2 ) { |
|
| 346 | + $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
|
| 347 | + } else { |
|
| 348 | + $message = new Tiqr_Message_APNS($this->_options, $this->logger); |
|
| 349 | + } |
|
| 350 | 350 | break; |
| 351 | 351 | |
| 352 | 352 | case 'GCM': |
@@ -511,7 +511,9 @@ discard block |
||
| 511 | 511 | $sessionId = session_id(); |
| 512 | 512 | } |
| 513 | 513 | $status = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT_STATUS.$sessionId); |
| 514 | - if (is_null($status)) return self::ENROLLMENT_STATUS_IDLE; |
|
| 514 | + if (is_null($status)) { |
|
| 515 | + return self::ENROLLMENT_STATUS_IDLE; |
|
| 516 | + } |
|
| 515 | 517 | return $status; |
| 516 | 518 | } |
| 517 | 519 | |
@@ -867,8 +869,7 @@ discard block |
||
| 867 | 869 | |
| 868 | 870 | try { |
| 869 | 871 | return $this->_stateStorage->getValue("authenticated_".$sessionId); |
| 870 | - } |
|
| 871 | - catch (Exception $e) { |
|
| 872 | + } catch (Exception $e) { |
|
| 872 | 873 | $this->logger->error('getAuthenticatedUser failed', array('exception'=>$e)); |
| 873 | 874 | return NULL; |
| 874 | 875 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // Get the UID from the client certificate we use for authentication, this |
| 28 | 28 | // is set to the bundle ID. |
| 29 | - $options=$this->getOptions(); |
|
| 29 | + $options = $this->getOptions(); |
|
| 30 | 30 | $cert_filename = $options['apns.certificate']; |
| 31 | 31 | $cert_file_contents = file_get_contents($cert_filename); |
| 32 | 32 | if (false === $cert_file_contents) { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | ); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $cert=openssl_x509_parse( $cert_file_contents ); |
|
| 38 | + $cert = openssl_x509_parse($cert_file_contents); |
|
| 39 | 39 | if (false === $cert) { |
| 40 | 40 | throw new RuntimeException('Error parsing APNS client certificate'); |
| 41 | 41 | } |
@@ -60,38 +60,38 @@ discard block |
||
| 60 | 60 | $authProvider = AuthProvider\Certificate::create($authProviderOptions); |
| 61 | 61 | |
| 62 | 62 | // Create the push message |
| 63 | - $alert=Alert::create(); |
|
| 63 | + $alert = Alert::create(); |
|
| 64 | 64 | $alert->setBody($this->getText()); |
| 65 | 65 | // TODO: Set title? |
| 66 | - $payload=Payload::create()->setAlert($alert); |
|
| 66 | + $payload = Payload::create()->setAlert($alert); |
|
| 67 | 67 | $payload->setSound('default'); |
| 68 | 68 | // TODO: Can we set an expiry time for the message? |
| 69 | 69 | foreach ($this->getCustomProperties() as $name => $value) { |
| 70 | 70 | $payload->setCustomValue($name, $value); |
| 71 | 71 | } |
| 72 | 72 | $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
| 73 | - $notification=new Notification($payload, $this->getAddress()); |
|
| 73 | + $notification = new Notification($payload, $this->getAddress()); |
|
| 74 | 74 | |
| 75 | 75 | // Send the push message |
| 76 | 76 | $client = new Client($authProvider, $options['apns.environment'] == 'production'); |
| 77 | 77 | $client->addNotification($notification); |
| 78 | - $responses=$client->push(); |
|
| 79 | - if ( sizeof($responses) != 1) { |
|
| 80 | - $this->logger->warning('Unexpected number responses. Expected 1, got %n', sizeof($responses) ); |
|
| 78 | + $responses = $client->push(); |
|
| 79 | + if (sizeof($responses) != 1) { |
|
| 80 | + $this->logger->warning('Unexpected number responses. Expected 1, got %n', sizeof($responses)); |
|
| 81 | 81 | if (sizeof($responses) == 0) { |
| 82 | 82 | $this->logger->warning('Could not determine whether the notification was sent'); |
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | /** @var \Pushok\Response $response */ |
| 87 | - $response = reset($responses); // Get first response from the array |
|
| 88 | - $deviceToken=$response->getDeviceToken() ?? ''; |
|
| 87 | + $response = reset($responses); // Get first response from the array |
|
| 88 | + $deviceToken = $response->getDeviceToken() ?? ''; |
|
| 89 | 89 | // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
| 90 | - $apnsId=$response->getApnsId() ?? ''; |
|
| 90 | + $apnsId = $response->getApnsId() ?? ''; |
|
| 91 | 91 | // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
| 92 | - $statusCode=$response->getStatusCode(); |
|
| 92 | + $statusCode = $response->getStatusCode(); |
|
| 93 | 93 | $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
| 94 | - if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
| 94 | + if (strcasecmp($deviceToken, $this->getAddress())) { |
|
| 95 | 95 | $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
| 96 | 96 | } |
| 97 | 97 | if ($statusCode == 200) { |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
| 103 | - $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
| 104 | - $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
| 102 | + $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
| 103 | + $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
| 104 | + $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
| 105 | 105 | |
| 106 | 106 | $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
| 107 | 107 | throw new RuntimeException( |