Did you first get the example_simple.php script working? If not, do that first. If you have I have often found that looking in the debug.log informs me as to what is going wrong and would suggest you look there. Also, I don’t think you mentioned which version of the CAS server you are running. If you are running an older version of the CAS server, you may not be running version 3.0 of the CAS protocol.
From: [email protected] [mailto:[email protected]] On Behalf Of Daniel Hui Sent: Friday, August 2, 2019 11:10 AM To: CAS Community <[email protected]> Subject: Re: [cas-user] Newbie question, about CAS proxy and phpCAS Thanks for the advice, I am trying those scripts, but they are not working, do I miss something? Here is my code, with some modifications for the original examples example_proxy_GET.php: <?php require_once('../vendor/autoload.php'); require_once('config.php'); $filename = 'debug.log'; phpCAS::setDebug($filename); phpCAS::setVerbose(true); phpCAS::proxy(CAS_VERSION_3_0, $cas_host, $cas_port, $cas_context); phpCAS::setNoCasServerValidation(); phpCAS::forceAuthentication(); //it shows me authentication fails at this line of code flush(); try { $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET); $service->setUrl("my_API_URL");//change it to my API URL to call the API $service->send(); if ($service->getResponseStatusCode() == 200) { echo '<div class="success">'; echo $service->getResponseBody(); echo '</div>'; } else { echo '<div class="error">'; echo 'The service responded with a ' . $service->getResponseStatusCode() . ' error.'; echo '</div>'; } } catch (CAS_ProxyTicketException $e) { if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE) { echo '<div class="error">'; echo "Your login has timed out. You need to log in again."; echo '</div>'; } else { throw $e; } } catch (CAS_ProxiedService_Exception $e) { echo "test"; throw $e; } ?> </body> </html> example_service.php:(if I just call this directly, it works) <?php require_once '../test/config.php'; require_once('../vendor/autoload.php'); $filename = 'debug.log'; echo "TEST">$filename; phpCAS::setDebug($filename); phpCAS::setVerbose(true); phpCAS::client(CAS_VERSION_3_0, $cas_host, $cas_port, $cas_context); //load from config phpCAS::setNoCasServerValidation(); phpCAS::forceAuthentication(); //phpCAS::allowProxyChain(new CAS_ProxyChain_Any); //I have disabled this because I do not need to chain this service to another service echo '<p>The user\'s login is <b>' . phpCAS::getUser() . '</b>.</p>'; // increment the number of requests of the session and print it if (!isset($_SESSION['n'])) { $_SESSION['n'] = 0; } echo '<p>request #' . (++$_SESSION['n']) . '</p>'; ?> Thanks for your kind help and quick reply On Friday, 2 August 2019 10:57:15 UTC+8, Doug C wrote: Daniel, I would recommend “getting your feet wet” first by working with the example_simple.php script. Make sure to get this one working with your CAS server first and then build from there by working with the example_service.php which could act like your CAS protected API service and example_proxy_GET.php which could act like the client wanting to access your API. Doug From: [email protected] <javascript:> [mailto:[email protected] <javascript:> ] On Behalf Of Daniel Hui Sent: Friday, August 2, 2019 10:50 AM To: CAS Community <[email protected] <javascript:> > Subject: Re: [cas-user] Newbie question, about CAS proxy and phpCAS Hi Doug, May I know which examples suit the use for me? One script for the API and another one for the Proxy. Thanks. On Friday, 2 August 2019 10:47:02 UTC+8, Doug C wrote: Daniel, Have you taken a lot at the phpCAS examples at https://github.com/apereo/phpCAS/tree/master/docs/examples? They are really detailed with a lot of comments explaining what is happening and even mentioning what things should be for testing and what should be removed when deploying in a production environment. Doug From: [email protected] <mailto:[email protected]> [mailto:[email protected]] On Behalf Of Daniel Hui Sent: Friday, August 2, 2019 10:01 AM To: CAS Community <[email protected] <mailto:[email protected]> > Subject: [cas-user] Newbie question, about CAS proxy and phpCAS Hey guys, I am building an API that requires CAS authentication, and the client which calls the API also needs the CAS authentication. After some Googling, I find out the proxy function suits my use and I want to implement it using phpCAS in my API and also build a simulate client to test my API for CAS authentication. But I cannot find any pratical example on the internet. May I get some help from you guys to show me some examples to implement this? I need some kind of clear logic and clear codes to help me understand this. I do not fully understand what is a CAS proxy, and what can it do. https://apereo.github.io/cas/5.0.x/installation/Configuring-Proxy-Authentication.html p.s.: I have CAS implementation experience before, which build a website that supports CAS. Thanks for the help -- - Website: https://apereo.github.io/cas - Gitter Chatroom: https://gitter.im/apereo/cas - List Guidelines: https://goo.gl/1VRrw7 - Contributions: https://goo.gl/mh7qDG --- You received this message because you are subscribed to the Google Groups "CAS Community" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]> . To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/17c31784-1dd3-43ac-8989-14df184e425f%40apereo.org <https://groups.google.com/a/apereo.org/d/msgid/cas-user/17c31784-1dd3-43ac-8989-14df184e425f%40apereo.org?utm_medium=email&utm_source=footer> . -- - Website: https://apereo.github.io/cas - Gitter Chatroom: https://gitter.im/apereo/cas - List Guidelines: https://goo.gl/1VRrw7 - Contributions: https://goo.gl/mh7qDG --- You received this message because you are subscribed to the Google Groups "CAS Community" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <javascript:> . To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/748f5d63-9018-48ce-a372-925eac316126%40apereo.org <https://groups.google.com/a/apereo.org/d/msgid/cas-user/748f5d63-9018-48ce-a372-925eac316126%40apereo.org?utm_medium=email&utm_source=footer> . -- - Website: https://apereo.github.io/cas - Gitter Chatroom: https://gitter.im/apereo/cas - List Guidelines: https://goo.gl/1VRrw7 - Contributions: https://goo.gl/mh7qDG --- You received this message because you are subscribed to the Google Groups "CAS Community" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]> . To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/f8d7b972-42a3-46fc-b4e9-e3f283b14e6c%40apereo.org <https://groups.google.com/a/apereo.org/d/msgid/cas-user/f8d7b972-42a3-46fc-b4e9-e3f283b14e6c%40apereo.org?utm_medium=email&utm_source=footer> . -- - Website: https://apereo.github.io/cas - Gitter Chatroom: https://gitter.im/apereo/cas - List Guidelines: https://goo.gl/1VRrw7 - Contributions: https://goo.gl/mh7qDG --- You received this message because you are subscribed to the Google Groups "CAS Community" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/005801d548e0%2458dbed60%240a93c820%24%40gmail.com.
