【问题标题】:CAS proxy with Laravel Homestead: callback url not authenticated带有 Laravel Homestead 的 CAS 代理:回调 url 未通过身份验证
【发布时间】:2015-07-29 23:55:55
【问题描述】:

我需要设置一个 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 很容易通过 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 回调 url 相同的消息(使用自签名证书),因为我可以使用 https 访问我的 laravel 应用程序。我在 CAS 文档中没有找到有关如何配置 CAS 的任何内容,因此回调不需要 https url,而且我确实在整个主题上找到了很少的帮助(根据这个 walkthrough,我失败了步骤 2(b),因为获取 PGT 是我的应用想要做的第一件事,但它不能因为回调未经过身份验证)。

对 CAS(和 Laravel/PHP)非常陌生,我不知道如何从那里着手,希望能得到一些帮助。

【问题讨论】:

标签: php laravel cas


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 2021-12-27
    相关资源
    最近更新 更多