Merge pull request #8762 from righel/aad-auth-support-proxy

Aad auth support proxy
pull/8778/head
Luciano Righetti 2022-11-18 10:10:53 +01:00 committed by GitHub
commit 1004f2a4b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 4 deletions

View File

@ -214,7 +214,7 @@ class AadAuthenticateAuthenticate extends BaseAuthenticate
];
$url = self::$auth_provider . self::$ad_tenant . "/oauth2/v2.0/token";
$response = (new HttpSocket())->post($url, $params, $options);
$response = ($this->_createHttpSocket())->post($url, $params, $options);
if (!$response->isOk()) {
$this->_log("warning", "Error received during Bearer token fetch (context).");
@ -239,7 +239,7 @@ class AadAuthenticateAuthenticate extends BaseAuthenticate
];
$url = self::$auth_provider_user . "/v1.0/me";
$response = (new HttpSocket())->get($url, null, $options);
$response = ($this->_createHttpSocket())->get($url, null, $options);
if (!$response->isOk()) {
$this->_log("warning", "Error received during user data fetch.");
@ -303,11 +303,11 @@ class AadAuthenticateAuthenticate extends BaseAuthenticate
'Authorization' => 'Bearer ' . $authdata["access_token"]
]
];
$has_next_page = true;
$url = self::$auth_provider_user . "/v1.0/me/memberOf";
while ($has_next_page) {
$response = (new HttpSocket())->get($url, array(), $options);
$response = ($this->_createHttpSocket())->get($url, array(), $options);
if (!$response->isOk()) {
$this->_log("warning", "Error received during user group data fetch.");
@ -346,4 +346,20 @@ class AadAuthenticateAuthenticate extends BaseAuthenticate
return false;
}
/**
* Create HttpSocket with proxy settings
*
* @return HttpSocket
*/
private function _createHttpSocket()
{
$httpSocket = new HttpSocket();
$proxy = Configure::read('Proxy');
if (isset($proxy['host']) && !empty($proxy['host'])) {
$httpSocket->configProxy($proxy['host'], $proxy['port'], $proxy['method'], $proxy['user'], $proxy['password']);
}
return $httpSocket;
}
}