Skip to content

Commit 838090b

Browse files
Fix/add ip headers (#25)
* add ip address support * remove function * fix type and refactor construct * clean up
1 parent c918e67 commit 838090b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Controllers/AbstractOAuth2Controller.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function __construct()
5050
'X-Longitude' => $_SERVER['GEOIP_LONGITUDE']
5151
];
5252
}
53+
$clientIpAddress = $this->getClientIP();
54+
$this->headers['X-Forwarded-For'] = $clientIpAddress;
5355
$this->encryption = DI::container()->get(EncryptionProvider::class);
5456
$this->secureStorage = DI::container()->get(SecureCookieProvider::class);
5557
$this->secureStorage->setEncryptionProvider($this->encryption);
@@ -107,6 +109,22 @@ public function setEncryptionProvider(EncryptionInterface $encryptionProvider):
107109
return $this;
108110
}
109111

112+
/**
113+
* looks for a user's IP address
114+
*
115+
* @return string
116+
*/
117+
public function getClientIP(){
118+
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)){
119+
return $_SERVER["HTTP_X_FORWARDED_FOR"];
120+
}else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
121+
return $_SERVER["REMOTE_ADDR"];
122+
}else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
123+
return $_SERVER["HTTP_CLIENT_IP"];
124+
}
125+
return '';
126+
}
127+
110128
/**
111129
* Ensures that externally supplied providers are set
112130
*

0 commit comments

Comments
 (0)