使用Laravel Homestead的CAS代理:回调url未经过认证


CAS proxy with Laravel Homestead: callback url not authenticated

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

我输入:

  • 运行在本地Docker容器上的CAS服务器,配置为允许通过HTTP和HTTPS中的所有服务
  • 在本地homestead vm上运行的laravel应用程序(我将127.0.0.1映射到homestead.app)
  • 第三方应用程序(基于django的python应用程序)也通过runserver本地运行,这是我需要进行身份验证的请求(所以我需要有laravel应用程序作为代理,然后向该应用程序发出请求)。

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

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

然而,当我想启用代理身份验证时,一切都变得一团糟。我无法生成PGT票证,Laravel应用程序将使用它代表用户进行身份验证请求。显然,CAS服务器拒绝承认pgtURL回调的有效性(默认情况下需要是https,但自签名证书似乎还不够)。由于所有这些将仅用于测试目的,我已经从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回调url,我知道工作(与自签名证书),因为我可以访问我的laravel应用程序使用https。我没有在CAS文档中找到关于如何配置CAS的任何内容,因此回调不需要https url,而且我确实在整个主题上找到了很少的帮助(根据此演练,我在步骤2(b)中失败,因为获得PGT是我的应用程序要做的第一件事,它不能因为回调未经过身份验证)。

是非常新的CAS(和Laravel/PHP),我不知道如何从那里进行,并将感激一点帮助。

好的,我通过将我的homestead自签名证书添加到docker容器信任库来解决这个问题。由于Cas服务器运行在tomcat服务器上,我必须通过到处设置/etc/hosts来使用我的homestead本地ip的别名,这也导致了它的负载问题,但它们并不难修复。如果需要的话,我可以详细说明,但我认为我的问题太具体了,与许多人都不相关。