Laravel Homestead 的 CAS 代理:回调 url 未通过身份验证

CAS proxy with Laravel Homestead: callback url not authenticated

我需要设置一个 Laravel 应用程序,它可以使用 CAS 2.0 协议将身份验证代理到第三方服务(我也可以控制)。

为此我有:

laravel 应用程序使用 jasig/phpCAS 和 xavrsl/cas(没有足够的声誉 post 超过 2 个链接,但是 github 回购很容易通过 Google) 与 CAS 服务器交互。这是一个非常简单的应用程序,当用户通过 CAS 成功登录时,它只会显示一条消息。简单是因为我只需要设置它用于进一步开发的测试目的。

到目前为止,我已经设法使非代理身份验证工作,所以我设置的所有部分都可以正确交互和通信。

然而,当我想要启用代理身份验证时,一切都变得糟糕起来。我无法生成 Laravel 应用程序用来代表用户发出经过身份验证的请求的 PGT 票证。显然 CAS 服务器拒绝识别 pgtURL 回调的有效性(默认情况下需要是 https,但自签名证书似乎还不够)。由于所有这些仅用于测试目的,我已根据 this post 从 CAS 服务器禁用 SSL 验证,并尝试使 http 回调 url 工作。

这是我尝试连接到我的服务器时的日志:

A126 .START phpCAS-1.3.3 ****************** [CAS.php:438]
A126 .=> phpCAS::proxy('2.0', '192.168.59.103', 8443, 'cas') [Sso.php:76]
A126 .|    => CAS_Client::__construct('2.0', true, '192.168.59.103', 8443, 'cas', true) [CAS.php:384]
A126 .|    |    Starting a new session ST-1-xVZCKeoYtmvKJzVQBTvQ-cas01exampleorg [Client.php:906]
A126 .|    |    Ticket 'ST-6-9sc0uCM1IJ1PwJiKJ9iT-cas01.example.org' found [Client.php:988]
A126 .|    <= ''
A126 .<= ''
A126 .=> phpCAS::setNoCasServerValidation() [Sso.php:98]
A126 .|    You have configured no validation of the legitimacy of the cas server. This is not recommended for production use. [CAS.php:1553]
A126 .<= ''
A126 .=> CAS_Client::handleLogoutRequests(true, false) [CAS.php:1193]
A126 .|    Not a logout request [Client.php:1689]
A126 .<= ''
A126 .=> phpCAS::allowProxyChain(CAS_ProxyChain) [Sso.php:111]
A126 .<= ''
A126 .=> phpCAS::setExtraCurlOption(81, 0) [AppServiceProvider.php:27]
A126 .<= ''
A126 .=> phpCAS::setFixedCallbackURL('http://homestead.app:8000') [AppServiceProvider.php:28]
A126 .<= ''
A126 .=> phpCAS::setPGTStorageFile('/home/vagrant/Code/storage/PGT.txt') [AppServiceProvider.php:29]
A126 .|    => CAS_PGTStorage_File::__construct(CAS_Client, '/home/vagrant/Code/storage/PGT.txt') [Client.php:2516]
A126 .|    |    => CAS_PGTStorage_AbstractStorage::__construct(CAS_Client) [File.php:119]
A126 .|    |    <= ''
A126 .|    <= ''
A126 .<= ''
A126 .=> phpCAS::forceAuthentication() [Sso.php:126]
A126 .|    => CAS_Client::forceAuthentication() [CAS.php:1015]
A126 .|    |    => CAS_Client::isAuthenticated() [Client.php:1245]
A126 .|    |    |    => CAS_Client::_wasPreviouslyAuthenticated() [Client.php:1356]
A126 .|    |    |    |    neither user nor PGT found [Client.php:1569]
A126 .|    |    |    <= false
A126 .|    |    |    CAS 2.0 ticket `ST-6-9sc0uCM1IJ1PwJiKJ9iT-cas01.example.org' is present [Client.php:1406]
A126 .|    |    |    => CAS_Client::validateCAS20('', NULL, NULL) [Client.php:1409]
A126 .|    |    |    |     [Client.php:3101]
A126 .|    |    |    |    => CAS_Client::getServerProxyValidateURL() [Client.php:3105]
A126 .|    |    |    |    |    => CAS_Client::getURL() [Client.php:507]
A126 .|    |    |    |    |    |    Final URI: http://homestead.app:8000/home [Client.php:3466]
A126 .|    |    |    |    |    <= 'http://homestead.app:8000/home'
A126 .|    |    |    |    <= 'https://192.168.59.103:8443/cas/proxyValidate?service=http%3A%2F%2Fhomestead.app%3A8000%2Fhome'
A126 .|    |    |    |    => CAS_Client::_readURL('https://192.168.59.103:8443/cas/proxyValidate?service=http%3A%2F%2Fhomestead.app%3A8000%2Fhome&ticket=ST-6-9sc0uCM1IJ1PwJiKJ9iT-cas01.example.org&pgtUrl=http%3A%2F%2Fhomestead.app%3A8000', NULL, NULL, NULL) [Client.php:3118]
A126 .|    |    |    |    |    => CAS_Request_CurlRequest::sendRequest() [AbstractRequest.php:242]
A126 .|    |    |    |    |    |    Response Body: 
A126 .|    |    |    |    |    |    
A126 .|    |    |    |    |    |    
A126 .|    |    |    |    |    |    
A126 .|    |    |    |    |    |    <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
A126 .|    |    |    |    |    |        <cas:authenticationFailure code='INVALID_PROXY_CALLBACK'>
A126 .|    |    |    |    |    |            The supplied proxy callback url &#039;http://homestead.app:8000&#039; could not be authenticated.
A126 .|    |    |    |    |    |        </cas:authenticationFailure>
A126 .|    |    |    |    |    |    </cas:serviceResponse>
A126 .|    |    |    |    |    |     [CurlRequest.php:84]
A126 .|    |    |    |    |    <= true
A126 .|    |    |    |    <= true
A126 .|    |    |    |    => CAS_AuthenticationException::__construct(CAS_Client, 'Ticket not validated', 'https://192.168.59.103:8443/cas/proxyValidate?service=http%3A%2F%2Fhomestead.app%3A8000%2Fhome&ticket=ST-6-9sc0uCM1IJ1PwJiKJ9iT-cas01.example.org&pgtUrl=http%3A%2F%2Fhomestead.app%3A8000', false, false, '<cas:serviceResponse xmlns:cas=\'http://www.yale.edu/tp/cas\'>   <cas:authenticationFailure code=\'INVALID_PROXY_CALLBACK\'>     The supplied proxy callback url &#039;http://homestead.app:8000&#039; could not be authenticated.   </cas:authenticationFailure></cas:serviceResponse>', 'INVALID_PROXY_CALLBACK', 'The supplied proxy callback url \'http://homestead.app:8000\' could not be authenticated.') [Client.php:3209]
A126 .|    |    |    |    |    => CAS_Client::getURL() [AuthenticationException.php:76]
A126 .|    |    |    |    |    <= 'http://homestead.app:8000/home'
A126 .|    |    |    |    |    CAS URL: https://192.168.59.103:8443/cas/proxyValidate?service=http%3A%2F%2Fhomestead.app%3A8000%2Fhome&ticket=ST-6-9sc0uCM1IJ1PwJiKJ9iT-cas01.example.org&pgtUrl=http%3A%2F%2Fhomestead.app%3A8000 [AuthenticationException.php:79]
A126 .|    |    |    |    |    Authentication failure: Ticket not validated [AuthenticationException.php:80]
A126 .|    |    |    |    |    Reason: [INVALID_PROXY_CALLBACK] CAS error: The supplied proxy callback url 'http://homestead.app:8000' could not be authenticated. [AuthenticationException.php:96]
A126 .|    |    |    |    |    CAS response: 
A126 .|    |    |    |    |    
A126 .|    |    |    |    |    
A126 .|    |    |    |    |    <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
A126 .|    |    |    |    |     <cas:authenticationFailure code='INVALID_PROXY_CALLBACK'>
A126 .|    |    |    |    |         The supplied proxy callback url &#039;http://homestead.app:8000&#039; could not be authenticated.
A126 .|    |    |    |    |     </cas:authenticationFailure>
A126 .|    |    |    |    |    </cas:serviceResponse> [AuthenticationException.php:101]
A126 .|    |    |    |    |    exit()
A126 .|    |    |    |    |    -
A126 .|    |    |    |    -
A126 .|    |    |    -
A126 .|    |    -
A126 .|    -

我收到了与 https 回调 urls 相同的消息,我知道它正在工作(使用自签名证书),因为我可以使用 https 访问我的 laravel 应用程序。我在 CAS 文档中没有找到任何有关如何配置 CAS 的信息,因此回调不需要 https url,并且我确实在整个主题上找到的帮助很少(根据此 walkthrough,我在第 2(b) 步失败了,因为获取 PGT 是我的应用程序想要做的第一件事,但它不能,因为回调未经过身份验证。

作为 CAS 的新手(和 Laravel/PHP),我不确定如何从那里着手,希望能提供一些帮助。

好的,我通过将我的宅基地自签名证书添加到 docker 容器信任库中解决了这个问题。由于 Cas 服务器在 tomcat 服务器上运行,我不得不通过在这里和那里设置 /etc/hosts 来使用我的宅基地本地 ip 的别名,这也导致了它的负载问题,但它们并不难无论如何要修复。如果需要,我可以对此进行扩展,但我认为我的问题过于具体,与许多人无关。