@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | // INVALID_USERID: The client authenticated a different user than the server expected. This error is returned when |
119 | 119 | // the application stated an authentication session specifying the userId and later during the authentication |
120 | 120 | // provides a different userId |
121 | - const AUTH_RESULT_INVALID_USERID = 5; |
|
121 | + const AUTH_RESULT_INVALID_USERID = 5; |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * The default OCRA Suite (RFC 6287) to use for authentication in Tiqr |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @param int $version The tiqr protocol version to use (defaults to the latest) |
248 | 248 | * @throws Exception |
249 | 249 | */ |
250 | - public function __construct(LoggerInterface $logger, array $options=array(), int $version = 2) |
|
250 | + public function __construct(LoggerInterface $logger, array $options = array(), int $version = 2) |
|
251 | 251 | { |
252 | 252 | $this->_options = $options; // Used to later get settings for Tiqr_Message_* |
253 | 253 | $this->logger = $logger; |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | case 'APNS': |
351 | 351 | case 'APNS_DIRECT': |
352 | 352 | $apns_version = $this->_options['apns.version'] ?? 1; |
353 | - if ($apns_version ==2 ) |
|
353 | + if ($apns_version == 2) |
|
354 | 354 | $message = new Tiqr_Message_APNS2($this->_options, $this->logger); |
355 | 355 | else |
356 | 356 | $message = new Tiqr_Message_APNS($this->_options, $this->logger); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | |
369 | 369 | $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType)); |
370 | 370 | $message->setId(time()); |
371 | - $message->setText("Please authenticate for " . $this->_name); |
|
371 | + $message->setText("Please authenticate for ".$this->_name); |
|
372 | 372 | $message->setAddress($notificationAddress); |
373 | 373 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
374 | 374 | $message->send(); |
@@ -414,13 +414,13 @@ discard block |
||
414 | 414 | * @return string The authentication sessionKey |
415 | 415 | * @throws Exception when starting the authentication session failed |
416 | 416 | */ |
417 | - public function startAuthenticationSession(string $userId="", string $sessionId="", string $spIdentifier=""): string |
|
417 | + public function startAuthenticationSession(string $userId = "", string $sessionId = "", string $spIdentifier = ""): string |
|
418 | 418 | { |
419 | - if ($sessionId=="") { |
|
419 | + if ($sessionId == "") { |
|
420 | 420 | $sessionId = session_id(); |
421 | 421 | } |
422 | 422 | |
423 | - if ($spIdentifier=="") { |
|
423 | + if ($spIdentifier == "") { |
|
424 | 424 | $spIdentifier = $this->_identifier; |
425 | 425 | } |
426 | 426 | |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | |
430 | 430 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
431 | 431 | |
432 | - if ($userId!="") { |
|
432 | + if ($userId != "") { |
|
433 | 433 | $data["userId"] = $userId; |
434 | 434 | } |
435 | 435 | |
@@ -453,9 +453,9 @@ discard block |
||
453 | 453 | * @return String The enrollment key |
454 | 454 | * @throws Exception when start the enrollement session failed |
455 | 455 | */ |
456 | - public function startEnrollmentSession(string $userId, string $displayName, string $sessionId=""): string |
|
456 | + public function startEnrollmentSession(string $userId, string $displayName, string $sessionId = ""): string |
|
457 | 457 | { |
458 | - if ($sessionId=="") { |
|
458 | + if ($sessionId == "") { |
|
459 | 459 | $sessionId = session_id(); |
460 | 460 | } |
461 | 461 | $enrollmentKey = $this->_uniqueSessionKey(); |
@@ -475,9 +475,9 @@ discard block |
||
475 | 475 | * @param string $sessionId The application's session identifier (defaults to php session) |
476 | 476 | * @throws Exception when resetting the session failed |
477 | 477 | */ |
478 | - public function resetEnrollmentSession(string $sessionId=""): void |
|
478 | + public function resetEnrollmentSession(string $sessionId = ""): void |
|
479 | 479 | { |
480 | - if ($sessionId=="") { |
|
480 | + if ($sessionId == "") { |
|
481 | 481 | $sessionId = session_id(); |
482 | 482 | } |
483 | 483 | |
@@ -512,9 +512,9 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @throws Exception when an error communicating with the state storage backend was detected |
514 | 514 | */ |
515 | - public function getEnrollmentStatus(string $sessionId=""): int |
|
515 | + public function getEnrollmentStatus(string $sessionId = ""): int |
|
516 | 516 | { |
517 | - if ($sessionId=="") { |
|
517 | + if ($sessionId == "") { |
|
518 | 518 | $sessionId = session_id(); |
519 | 519 | } |
520 | 520 | $status = $this->_getStateValue(self::PREFIX_ENROLLMENT_STATUS, $sessionId); |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | if (NULL === $data) { |
668 | 668 | throw new RuntimeException('Enrollment secret not found'); |
669 | 669 | } |
670 | - if ( !is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
670 | + if (!is_array($data) || !is_string($data["userId"] ?? NULL)) { |
|
671 | 671 | throw new RuntimeException('Invalid enrollment data'); |
672 | 672 | } |
673 | 673 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_FINALIZED); |
708 | 708 | } else { |
709 | 709 | $this->logger->error( |
710 | - 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' . |
|
710 | + 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '. |
|
711 | 711 | 'Warning! the method will still return "true" as a result.' |
712 | 712 | ); |
713 | 713 | } |
@@ -765,9 +765,9 @@ discard block |
||
765 | 765 | throw $e; |
766 | 766 | } |
767 | 767 | |
768 | - $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
769 | - $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
770 | - if (!is_string($sessionId) || (!is_string($challenge)) ) { |
|
768 | + $sessionId = $state["sessionId"] ?? NULL; // Application's sessionId |
|
769 | + $challenge = $state["challenge"] ?? NULL; // The challenge we sent to the Tiqr client |
|
770 | + if (!is_string($sessionId) || (!is_string($challenge))) { |
|
771 | 771 | throw new RuntimeException('Invalid state for state storage'); |
772 | 772 | } |
773 | 773 | |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | $challengeUserId = $state["userId"] ?? NULL; |
777 | 777 | |
778 | 778 | // If the application requested a specific userId, verify that that is that userId that we're now authenticating |
779 | - if ($challengeUserId!==NULL && ($userId !== $challengeUserId)) { |
|
779 | + if ($challengeUserId !== NULL && ($userId !== $challengeUserId)) { |
|
780 | 780 | $this->logger->error( |
781 | 781 | sprintf('Authentication failed: the requested userId "%s" does not match userId "%s" that is being authenticated', |
782 | 782 | $challengeUserId, $userId) |
@@ -824,9 +824,9 @@ discard block |
||
824 | 824 | * |
825 | 825 | * @throws Exception when there was an error communicating with the storage backed |
826 | 826 | */ |
827 | - public function logout(string $sessionId=""): void |
|
827 | + public function logout(string $sessionId = ""): void |
|
828 | 828 | { |
829 | - if ($sessionId=="") { |
|
829 | + if ($sessionId == "") { |
|
830 | 830 | $sessionId = session_id(); |
831 | 831 | } |
832 | 832 | |
@@ -866,9 +866,9 @@ discard block |
||
866 | 866 | * |
867 | 867 | * Does not throw |
868 | 868 | */ |
869 | - public function getAuthenticatedUser(string $sessionId=""): ?string |
|
869 | + public function getAuthenticatedUser(string $sessionId = ""): ?string |
|
870 | 870 | { |
871 | - if ($sessionId=="") { |
|
871 | + if ($sessionId == "") { |
|
872 | 872 | $this->logger->debug('Using the PHP session id, as no session id was provided'); |
873 | 873 | $sessionId = session_id(); |
874 | 874 | } |
@@ -912,22 +912,22 @@ discard block |
||
912 | 912 | $challenge = $state["challenge"] ?? ''; |
913 | 913 | $spIdentifier = $state["spIdentifier"] ?? ''; |
914 | 914 | |
915 | - if ( (strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0) ) { |
|
915 | + if ((strpos($this->_protocolAuth, 'https://') === 0) || (strpos($this->_protocolAuth, 'http://') === 0)) { |
|
916 | 916 | // Create universal Link |
917 | - $parameters=array(); |
|
917 | + $parameters = array(); |
|
918 | 918 | if (!is_null($userId)) { |
919 | - $parameters[]='u='.urlencode($userId); |
|
919 | + $parameters[] = 'u='.urlencode($userId); |
|
920 | 920 | } |
921 | - $parameters[]='s='.urlencode($sessionKey); |
|
922 | - $parameters[]='q='.urlencode($challenge); |
|
923 | - $parameters[]='i='.urlencode($this->getIdentifier()); |
|
924 | - $parameters[]='v='.urlencode($this->_protocolVersion); |
|
921 | + $parameters[] = 's='.urlencode($sessionKey); |
|
922 | + $parameters[] = 'q='.urlencode($challenge); |
|
923 | + $parameters[] = 'i='.urlencode($this->getIdentifier()); |
|
924 | + $parameters[] = 'v='.urlencode($this->_protocolVersion); |
|
925 | 925 | return $this->_protocolAuth.'?'.implode('&', $parameters); |
926 | 926 | } |
927 | 927 | |
928 | 928 | // Create custom URL scheme |
929 | 929 | // Last bit is the spIdentifier |
930 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
930 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
931 | 931 | } |
932 | 932 | |
933 | 933 | /** |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | { |
939 | 939 | // The are two formats see: https://tiqr.org/technical/protocol/ |
940 | 940 | |
941 | - if ( (strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0) ) { |
|
941 | + if ((strpos($this->_protocolEnroll, 'https://') === 0) || (strpos($this->_protocolEnroll, 'http://') === 0)) { |
|
942 | 942 | // Create universal Link |
943 | 943 | return $this->_protocolEnroll.'?metadata='.urlencode($metadataUrl); |
944 | 944 | } |
@@ -957,7 +957,7 @@ discard block |
||
957 | 957 | protected function _uniqueSessionKey(): string |
958 | 958 | { |
959 | 959 | |
960 | - return bin2hex( Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES) ); |
|
960 | + return bin2hex(Tiqr_Random::randomBytes(self::SESSION_KEY_LENGTH_BYTES)); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | */ |
989 | 989 | protected function _setStateValue(string $key_prefix, string $key, $value, int $expire): void { |
990 | 990 | $this->_stateStorage->setValue( |
991 | - $key_prefix . $this->_hashKey($key), |
|
991 | + $key_prefix.$this->_hashKey($key), |
|
992 | 992 | $value, |
993 | 993 | $expire |
994 | 994 | ); |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | |
1006 | 1006 | protected function _getStateValue(string $key_prefix, string $key) { |
1007 | 1007 | return $this->_stateStorage->getValue( |
1008 | - $key_prefix . $this->_hashKey($key) |
|
1008 | + $key_prefix.$this->_hashKey($key) |
|
1009 | 1009 | ); |
1010 | 1010 | } |
1011 | 1011 | |
@@ -1019,7 +1019,7 @@ discard block |
||
1019 | 1019 | */ |
1020 | 1020 | protected function _unsetStateValue(string $key_prefix, string $key): void { |
1021 | 1021 | $this->_stateStorage->unsetValue( |
1022 | - $key_prefix . $this->_hashKey($key) |
|
1022 | + $key_prefix.$this->_hashKey($key) |
|
1023 | 1023 | ); |
1024 | 1024 | } |
1025 | 1025 |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | $options = $this->getOptions(); |
24 | 24 | if (isset($options['apns.proxy_host_url'])) { |
25 | 25 | // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy |
26 | - $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress(); |
|
26 | + $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress(); |
|
27 | 27 | $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443; |
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | - $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
30 | + $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
31 | 31 | } |
32 | 32 | else { |
33 | 33 | $version_info = curl_version(); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | // Get the UID from the client certificate we use for authentication, this |
40 | 40 | // is set to the bundle ID. |
41 | - $options=$this->getOptions(); |
|
41 | + $options = $this->getOptions(); |
|
42 | 42 | $cert_filename = $options['apns.certificate']; |
43 | 43 | $cert_file_contents = file_get_contents($cert_filename); |
44 | 44 | if (false === $cert_file_contents) { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - $cert=openssl_x509_parse( $cert_file_contents ); |
|
50 | + $cert = openssl_x509_parse($cert_file_contents); |
|
51 | 51 | if (false === $cert) { |
52 | 52 | throw new RuntimeException('Error parsing APNS client certificate'); |
53 | 53 | } |
@@ -72,42 +72,42 @@ discard block |
||
72 | 72 | $authProvider = AuthProvider\Certificate::create($authProviderOptions); |
73 | 73 | |
74 | 74 | // Create the push message |
75 | - $alert=Alert::create(); |
|
75 | + $alert = Alert::create(); |
|
76 | 76 | $alert->setBody($this->getText()); |
77 | 77 | // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle() |
78 | 78 | // The tiqr service currently does not implement this. |
79 | - $payload=Payload::create()->setAlert($alert); |
|
79 | + $payload = Payload::create()->setAlert($alert); |
|
80 | 80 | $payload->setSound('default'); |
81 | 81 | foreach ($this->getCustomProperties() as $name => $value) { |
82 | 82 | $payload->setCustomValue($name, $value); |
83 | 83 | } |
84 | 84 | $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
85 | - $notification=new Notification($payload, $this->getAddress()); |
|
85 | + $notification = new Notification($payload, $this->getAddress()); |
|
86 | 86 | // Set expiration to 30 seconds from now, same as Message_APNS |
87 | 87 | $now = new DateTime(); |
88 | - $expirationInstant=$now->add(new DateInterval('PT30S')); |
|
88 | + $expirationInstant = $now->add(new DateInterval('PT30S')); |
|
89 | 89 | $notification->setExpirationAt($expirationInstant); |
90 | 90 | |
91 | 91 | // Send the push message |
92 | 92 | $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options); |
93 | 93 | $client->addNotification($notification); |
94 | - $responses=$client->push(); |
|
95 | - if ( sizeof($responses) != 1) { |
|
96 | - $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) ); |
|
94 | + $responses = $client->push(); |
|
95 | + if (sizeof($responses) != 1) { |
|
96 | + $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses))); |
|
97 | 97 | if (sizeof($responses) == 0) { |
98 | 98 | $this->logger->warning('Could not determine whether the notification was sent'); |
99 | 99 | return; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | /** @var \Pushok\Response $response */ |
103 | - $response = reset($responses); // Get first response from the array |
|
104 | - $deviceToken=$response->getDeviceToken() ?? ''; |
|
103 | + $response = reset($responses); // Get first response from the array |
|
104 | + $deviceToken = $response->getDeviceToken() ?? ''; |
|
105 | 105 | // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
106 | - $apnsId=$response->getApnsId() ?? ''; |
|
106 | + $apnsId = $response->getApnsId() ?? ''; |
|
107 | 107 | // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
108 | - $statusCode=$response->getStatusCode(); |
|
108 | + $statusCode = $response->getStatusCode(); |
|
109 | 109 | $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
110 | - if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
110 | + if (strcasecmp($deviceToken, $this->getAddress())) { |
|
111 | 111 | $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
112 | 112 | } |
113 | 113 | if ($statusCode == 200) { |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | - $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
120 | - $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
118 | + $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | + $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
120 | + $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
121 | 121 | |
122 | 122 | $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
123 | 123 | throw new RuntimeException( |