Skip to content

Commit

Permalink
Updated AbstractOAuth2Controller with X-Real-IP
Browse files Browse the repository at this point in the history
Added additional PHP Server variable to check when attempting to determine the client's IP address.
  • Loading branch information
jaredbiehler authored May 3, 2023
1 parent 838090b commit f2e0f47
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Controllers/AbstractOAuth2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public function __construct()
'X-Longitude' => $_SERVER['GEOIP_LONGITUDE']
];
}
$clientIpAddress = $this->getClientIP();
$this->headers['X-Forwarded-For'] = $clientIpAddress;
if (!is_null($clientIpAddress = $this->getClientIP())) {
$this->headers['X-Forwarded-For'] = $clientIpAddress;
}
$this->encryption = DI::container()->get(EncryptionProvider::class);
$this->secureStorage = DI::container()->get(SecureCookieProvider::class);
$this->secureStorage->setEncryptionProvider($this->encryption);
Expand Down Expand Up @@ -109,20 +110,24 @@ public function setEncryptionProvider(EncryptionInterface $encryptionProvider):
return $this;
}

/**
/**
* looks for a user's IP address
*
* @return string
* @return string|null
*/
public function getClientIP(){
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)){
return $_SERVER["HTTP_X_FORWARDED_FOR"];
}else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
public function getClientIP()
{
if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
return $_SERVER["HTTP_X_REAL_IP"];
} else if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
return $_SERVER["HTTP_X_FORWARDED_FOR"];
} else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
return $_SERVER["REMOTE_ADDR"];
}else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
} else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
return $_SERVER["HTTP_CLIENT_IP"];
}
return '';
}

return null;
}

/**
Expand Down

0 comments on commit f2e0f47

Please sign in to comment.