プロキシだとhttpでアクセスするのでその周りだろうなってことで
このあたりでエラーが出ている。
vendor/aacotroneo/laravel-saml2/src/Aacotroneo/Saml2/Http/Controllers/Saml2Controller.php
の
<?php
public function acs(Saml2Auth $saml2Auth, $idpName)
{
$errors = $saml2Auth->acs();
の所のエラーが
array(2) {
["error"]=>
array(1) {
[0]=>
string(16) "invalid_response"
}
["last_error_reason"]=>
string(130) "The response was received at http://example.com/saml2/******/acs instead of https://example.com/saml2/******/acs"
}
という感じ。
たどっていって
vendor/aacotroneo/laravel-saml2/src/Aacotroneo/Saml2/Saml2Auth.php
の
<?php
function acs()
{
@var
$auth = $this->auth;
$auth->processResponse();
$errors = $auth->getErrors();
でエラーを拾っているので
vendor/onelogin/php-saml/src/Saml2/Auth.php->processResponse()
vendor/onelogin/php-saml/src/Saml2/Response.php->isValid()
と進んでいくと、isValid()の
<?php
$currentURL = Utils::getSelfRoutedURLNoQuery();
...zip...
$urlComparisonLength = $security['destinationStrictlyMatches'] ? strlen($destination) : strlen($currentURL);
if (strncmp($destination, $currentURL, $urlComparisonLength) !== 0) {
$currentURLNoRouted = Utils::getSelfURLNoQuery();
$urlComparisonLength = $security['destinationStrictlyMatches'] ? strlen($destination) : strlen($currentURLNoRouted);
if (strncmp($destination, $currentURLNoRouted, $urlComparisonLength) !== 0) {
throw new ValidationError(
"The response was received at $currentURL instead of $destination",
ValidationError::WRONG_DESTINATION
);
}
}
のところで、$currentURLが http://example.com/saml2//asc で、$destinationが https://example.com/saml2//asc だから strncmp($destination, $currentURL, $urlComparisonLength) !== 0 ではないですよっていうエラー。
対処法を考えると
vendor/onelogin/php-saml/src/Saml2/Utils.php の所を読んでると、なんかやっぱりProxyを配慮してるっぽい。
<?php
public static function getSelfProtocol()
{
$protocol = 'http';
if (self::$_protocol) {
$protocol = self::$_protocol;
} elseif (self::getSelfPort() == 443) {
$protocol = 'https';
} elseif (self::getProxyVars() && isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$protocol = $_SERVER['HTTP_X_FORWARDED_PROTO'];
} elseif (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
$protocol = 'https';
}
return $protocol;
}
self::getProxyVars() がtrueで、$_SERVER['HTTP_X_FORWARDED_PROTO']が存在してればそれになるっぽい。
HTTP_X_FORWARDED_PROTOは当然存在してるので、じゃあ getProxyVars()はというと単純にreturn self::$_proxyVarsしてて、
<?php
@param
public static function setProxyVars($proxyVars)
{
self::$_proxyVars = (bool)$proxyVars;
}
なんだけど、当然これもX-Forwarded-ForとかX-Forwarded-Protoとか存在してるわけで…あれー。
なんかProviderまで遡りそう
vendor/aacotroneo/laravel-saml2/src/Aacotroneo/Saml2/Saml2ServiceProvider.php
で OneLogin_Saml2_Utils::setProxyVars(true); しているところがあった。
<?php
if (config('saml2_settings.proxyVars', false)) {
OneLogin_Saml2_Utils::setProxyVars(true);
}
おぉー。
ということで、
config/saml2_settings.phpの
'proxyVars' => false,
をtrueにして完了