Skip to content

Commit

Permalink
Fix/add ip headers (#25)
Browse files Browse the repository at this point in the history
* add ip address support

* remove function

* fix type and refactor construct

* clean up
  • Loading branch information
kristen-kagei authored Apr 26, 2023
1 parent c918e67 commit 838090b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Controllers/AbstractOAuth2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function __construct()
'X-Longitude' => $_SERVER['GEOIP_LONGITUDE']
];
}
$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 @@ -107,6 +109,22 @@ public function setEncryptionProvider(EncryptionInterface $encryptionProvider):
return $this;
}

/**
* looks for a user's IP address
*
* @return string
*/
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)) {
return $_SERVER["REMOTE_ADDR"];
}else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
return $_SERVER["HTTP_CLIENT_IP"];
}
return '';
}

/**
* Ensures that externally supplied providers are set
*
Expand Down

0 comments on commit 838090b

Please sign in to comment.