@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | /** |
| 75 | 75 | * Enrollment status codes |
| 76 | 76 | */ |
| 77 | - const ENROLLMENT_STATUS_IDLE = 1; // Nothing happens |
|
| 77 | + const ENROLLMENT_STATUS_IDLE = 1; // Nothing happens |
|
| 78 | 78 | const ENROLLMENT_STATUS_INITIALIZED = 2; // An enrollment session has begun |
| 79 | - const ENROLLMENT_STATUS_RETRIEVED = 3; // The device has retrieved the metadata |
|
| 80 | - const ENROLLMENT_STATUS_PROCESSED = 4; // The device has snet back a secret |
|
| 81 | - const ENROLLMENT_STATUS_FINALIZED = 5; // The application has stored the secret |
|
| 82 | - const ENROLLMENT_STATUS_VALIDATED = 6; // A first succesful authentication was performed |
|
| 79 | + const ENROLLMENT_STATUS_RETRIEVED = 3; // The device has retrieved the metadata |
|
| 80 | + const ENROLLMENT_STATUS_PROCESSED = 4; // The device has snet back a secret |
|
| 81 | + const ENROLLMENT_STATUS_FINALIZED = 5; // The application has stored the secret |
|
| 82 | + const ENROLLMENT_STATUS_VALIDATED = 6; // A first succesful authentication was performed |
|
| 83 | 83 | |
| 84 | 84 | const PREFIX_ENROLLMENT_SECRET = 'enrollsecret'; |
| 85 | 85 | const PREFIX_ENROLLMENT = 'enroll'; |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param array $options |
| 159 | 159 | * @param int $version The protocol version to use (defaults to the latest) |
| 160 | 160 | */ |
| 161 | - public function __construct(LoggerInterface $logger, $options=array(), $version = 2) |
|
| 161 | + public function __construct(LoggerInterface $logger, $options = array(), $version = 2) |
|
| 162 | 162 | { |
| 163 | 163 | $this->_options = $options; |
| 164 | 164 | $this->logger = $logger; |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | $this->logger->info(sprintf('Creating and sending a %s push notification', $notificationType)); |
| 313 | 313 | $message->setId(time()); |
| 314 | - $message->setText("Please authenticate for " . $this->_name); |
|
| 314 | + $message->setText("Please authenticate for ".$this->_name); |
|
| 315 | 315 | $message->setAddress($notificationAddress); |
| 316 | 316 | $message->setCustomProperty('challenge', $this->_getChallengeUrl($sessionKey)); |
| 317 | 317 | $message->send(); |
@@ -380,13 +380,13 @@ discard block |
||
| 380 | 380 | * @param String $spIdentifier If SP and IDP are 2 different things, pass the url/identifier of the SP the user is logging into. |
| 381 | 381 | * For setups where IDP==SP, just leave this blank. |
| 382 | 382 | */ |
| 383 | - public function startAuthenticationSession($userId="", $sessionId="", $spIdentifier="") |
|
| 383 | + public function startAuthenticationSession($userId = "", $sessionId = "", $spIdentifier = "") |
|
| 384 | 384 | { |
| 385 | - if ($sessionId=="") { |
|
| 385 | + if ($sessionId == "") { |
|
| 386 | 386 | $sessionId = session_id(); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - if ($spIdentifier=="") { |
|
| 389 | + if ($spIdentifier == "") { |
|
| 390 | 390 | $spIdentifier = $this->_identifier; |
| 391 | 391 | } |
| 392 | 392 | |
@@ -396,11 +396,11 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | $data = array("sessionId"=>$sessionId, "challenge"=>$challenge, "spIdentifier" => $spIdentifier); |
| 398 | 398 | |
| 399 | - if ($userId!="") { |
|
| 399 | + if ($userId != "") { |
|
| 400 | 400 | $data["userId"] = $userId; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $this->_stateStorage->setValue(self::PREFIX_CHALLENGE . $sessionKey, $data, self::CHALLENGE_EXPIRE); |
|
| 403 | + $this->_stateStorage->setValue(self::PREFIX_CHALLENGE.$sessionKey, $data, self::CHALLENGE_EXPIRE); |
|
| 404 | 404 | |
| 405 | 405 | return $sessionKey; |
| 406 | 406 | } |
@@ -420,9 +420,9 @@ discard block |
||
| 420 | 420 | * to php session) |
| 421 | 421 | * @return String The enrollment key |
| 422 | 422 | */ |
| 423 | - public function startEnrollmentSession($userId, $displayName, $sessionId="") |
|
| 423 | + public function startEnrollmentSession($userId, $displayName, $sessionId = "") |
|
| 424 | 424 | { |
| 425 | - if ($sessionId=="") { |
|
| 425 | + if ($sessionId == "") { |
|
| 426 | 426 | $sessionId = session_id(); |
| 427 | 427 | } |
| 428 | 428 | $enrollmentKey = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT); |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | "displayName" => $displayName, |
| 432 | 432 | "sessionId" => $sessionId |
| 433 | 433 | ]; |
| 434 | - $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT . $enrollmentKey, $data, self::ENROLLMENT_EXPIRE); |
|
| 434 | + $this->_stateStorage->setValue(self::PREFIX_ENROLLMENT.$enrollmentKey, $data, self::ENROLLMENT_EXPIRE); |
|
| 435 | 435 | $this->_setEnrollmentStatus($sessionId, self::ENROLLMENT_STATUS_INITIALIZED); |
| 436 | 436 | |
| 437 | 437 | return $enrollmentKey; |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | * @param $sessionId The application's session identifier (defaults |
| 443 | 443 | * to php session) |
| 444 | 444 | */ |
| 445 | - public function resetEnrollmentSession($sessionId="") |
|
| 445 | + public function resetEnrollmentSession($sessionId = "") |
|
| 446 | 446 | { |
| 447 | - if ($sessionId=="") { |
|
| 447 | + if ($sessionId == "") { |
|
| 448 | 448 | $sessionId = session_id(); |
| 449 | 449 | } |
| 450 | 450 | |
@@ -489,9 +489,9 @@ discard block |
||
| 489 | 489 | * A first successful authentication was performed |
| 490 | 490 | * (todo: currently not used) |
| 491 | 491 | */ |
| 492 | - public function getEnrollmentStatus($sessionId="") |
|
| 492 | + public function getEnrollmentStatus($sessionId = "") |
|
| 493 | 493 | { |
| 494 | - if ($sessionId=="") { |
|
| 494 | + if ($sessionId == "") { |
|
| 495 | 495 | $sessionId = session_id(); |
| 496 | 496 | } |
| 497 | 497 | $status = $this->_stateStorage->getValue("enrollstatus".$sessionId); |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | */ |
| 551 | 551 | public function getEnrollmentMetadata($enrollmentKey, $authenticationUrl, $enrollmentUrl) |
| 552 | 552 | { |
| 553 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 553 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 554 | 554 | if (!is_array($data)) { |
| 555 | 555 | $this->logger->error('Unable to find enrollment metadata in state storage'); |
| 556 | 556 | return false; |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | array("identifier" =>$data["userId"], |
| 570 | 570 | "displayName"=>$data["displayName"])); |
| 571 | 571 | |
| 572 | - $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 572 | + $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 573 | 573 | |
| 574 | 574 | $this->_setEnrollmentStatus($data["sessionId"], self::ENROLLMENT_STATUS_RETRIEVED); |
| 575 | 575 | return $metadata; |
@@ -590,14 +590,14 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | public function getEnrollmentSecret($enrollmentKey) |
| 592 | 592 | { |
| 593 | - $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT . $enrollmentKey); |
|
| 593 | + $data = $this->_stateStorage->getValue(self::PREFIX_ENROLLMENT.$enrollmentKey); |
|
| 594 | 594 | $secret = $this->_uniqueSessionKey(self::PREFIX_ENROLLMENT_SECRET); |
| 595 | 595 | $enrollmentData = [ |
| 596 | 596 | "userId" => $data["userId"], |
| 597 | 597 | "sessionId" => $data["sessionId"] |
| 598 | 598 | ]; |
| 599 | 599 | $this->_stateStorage->setValue( |
| 600 | - self::PREFIX_ENROLLMENT_SECRET . $secret, |
|
| 600 | + self::PREFIX_ENROLLMENT_SECRET.$secret, |
|
| 601 | 601 | $enrollmentData, |
| 602 | 602 | self::ENROLLMENT_EXPIRE |
| 603 | 603 | ); |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $this->_stateStorage->unsetValue(self::PREFIX_ENROLLMENT_SECRET.$enrollmentSecret); |
| 648 | 648 | } else { |
| 649 | 649 | $this->logger->error( |
| 650 | - 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. ' . |
|
| 650 | + 'Enrollment status is not finalized, enrollmentsecret was not found in state storage. '. |
|
| 651 | 651 | 'Warning! the method will still return "true" as a result.' |
| 652 | 652 | ); |
| 653 | 653 | } |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | */ |
| 678 | 678 | public function authenticate($userId, $userSecret, $sessionKey, $response) |
| 679 | 679 | { |
| 680 | - $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 680 | + $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 681 | 681 | if (is_null($state)) { |
| 682 | 682 | $this->logger->info('The auth challenge could not be found in the state storage'); |
| 683 | 683 | return self::AUTH_RESULT_INVALID_CHALLENGE; |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | $challengeUserId = $state["userId"]; |
| 692 | 692 | } |
| 693 | 693 | // Check if we're dealing with a second factor |
| 694 | - if ($challengeUserId!=NULL && ($userId != $challengeUserId)) { |
|
| 694 | + if ($challengeUserId != NULL && ($userId != $challengeUserId)) { |
|
| 695 | 695 | $this->logger->error( |
| 696 | 696 | 'Authentication failed: the first factor user id does not match with that of the second factor' |
| 697 | 697 | ); |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | $this->_stateStorage->setValue("authenticated_".$sessionId, $userId, self::LOGIN_EXPIRE); |
| 710 | 710 | |
| 711 | 711 | // Clean up the challenge. |
| 712 | - $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 712 | + $this->_stateStorage->unsetValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 713 | 713 | $this->logger->info('Authentication succeeded'); |
| 714 | 714 | return self::AUTH_RESULT_AUTHENTICATED; |
| 715 | 715 | } |
@@ -722,9 +722,9 @@ discard block |
||
| 722 | 722 | * @param String $sessionId The application's session identifier (defaults |
| 723 | 723 | * to the php session). |
| 724 | 724 | */ |
| 725 | - public function logout($sessionId="") |
|
| 725 | + public function logout($sessionId = "") |
|
| 726 | 726 | { |
| 727 | - if ($sessionId=="") { |
|
| 727 | + if ($sessionId == "") { |
|
| 728 | 728 | $sessionId = session_id(); |
| 729 | 729 | } |
| 730 | 730 | |
@@ -759,9 +759,9 @@ discard block |
||
| 759 | 759 | * @return mixed An array with user data if a user was logged in or NULL if |
| 760 | 760 | * no user is logged in. |
| 761 | 761 | */ |
| 762 | - public function getAuthenticatedUser($sessionId="") |
|
| 762 | + public function getAuthenticatedUser($sessionId = "") |
|
| 763 | 763 | { |
| 764 | - if ($sessionId=="") { |
|
| 764 | + if ($sessionId == "") { |
|
| 765 | 765 | $this->logger->debug('Using the PHP session id, as no session id was provided'); |
| 766 | 766 | $sessionId = session_id(); |
| 767 | 767 | } |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | */ |
| 781 | 781 | protected function _getChallengeUrl($sessionKey) |
| 782 | 782 | { |
| 783 | - $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE . $sessionKey); |
|
| 783 | + $state = $this->_stateStorage->getValue(self::PREFIX_CHALLENGE.$sessionKey); |
|
| 784 | 784 | if (is_null($state)) { |
| 785 | 785 | $this->logger->error( |
| 786 | 786 | 'Unable find an existing challenge url in the state storage based on the existing session key' |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | return false; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - $userId = NULL; |
|
| 791 | + $userId = NULL; |
|
| 792 | 792 | $challenge = $state["challenge"]; |
| 793 | 793 | if (isset($state["userId"])) { |
| 794 | 794 | $userId = $state["userId"]; |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | $spIdentifier = $state["spIdentifier"]; |
| 797 | 797 | |
| 798 | 798 | // Last bit is the spIdentifier |
| 799 | - return $this->_protocolAuth."://".(!is_null($userId)?urlencode($userId).'@':'').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 799 | + return $this->_protocolAuth."://".(!is_null($userId) ?urlencode($userId).'@' : '').$this->getIdentifier()."/".$sessionKey."/".$challenge."/".urlencode($spIdentifier)."/".$this->_protocolVersion; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | protected function _uniqueSessionKey($prefix) |
| 821 | 821 | { |
| 822 | 822 | $value = 1; |
| 823 | - while ($value!=NULL) { |
|
| 823 | + while ($value != NULL) { |
|
| 824 | 824 | $sessionKey = $this->_ocraWrapper->generateSessionKey(); |
| 825 | 825 | $value = $this->_stateStorage->getValue($prefix.$sessionKey); |
| 826 | 826 | } |