LJ
Autenticação externa (Via CAS)
Pessoal, to precisando de ajuda para fazer uma aplicação baseada no template, só que ao invés de ter a tela de login , seria redirecionado para uma aplicação externa que faz o login (quando autentico nesta aplicação externa , já me retorna o email da pessoa).
Estou baseando neste exemplo:
Estou baseando neste exemplo:
- <?php
- // https://calnetweb.berkeley.edu/calnet-technologists/cas/casifying-your-web-application-or-web-server/cas-code-samples/cas
- $casService = 'https://servidor.com.br/cas-server';
- $thisService = 'https://localhost' . $_SERVER['PHP_SELF'];
- /*
- * Check to see if there is a ticket in the GET request.
- * CAS uses "ticket" for the service ticket. Bad choice of words, but
- * it is what CAS uses.
- *
- * If the ticket exists, validate it with CAS. If not, redirect the user
- * to CAS.
- *
- * Of course, you will want to hook this in with your application's
- * session management system, i.e., if the user already has a session,
- * you don't want to do either of these two things.
- *
- */
- if ($_SERVER["REQUEST_METHOD"] && $_GET["ticket"]) {
- if ($response = responseForTicket($_GET["ticket"])) {
- echo 'o email é '.$response;
- }
- else {
- echo "26-The response was not valid.".'<br>';
- }
- }
- else {
- header("Location: $casService/login?service=$thisService");
- }
- //* Returns the CAS response if the ticket is valid, and false if not.
- function responseForTicket($ticket) {
- global $casService, $thisService;
- $casGet = "$casService/serviceValidate?ticket=$ticket&service=" . urlencode($thisService);
- $response = file_get_contents($casGet);
- if (preg_match('/cas:authenticationSuccess/', $response)) {
- return $response;
- }
- else {
- return false;
- }
- }
- ?>