authserver/testCAS/app/Http/Controllers/HomeController.php
author durandn
Wed, 27 May 2015 15:34:06 +0200
changeset 8 5a0cbbe0922a
parent 0 1afc9d2ab94d
child 9 3166a35f5f0d
permissions -rw-r--r--
CAS Authentication (normal and proxy) + local Homestead vm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php namespace TestCAS\Http\Controllers;
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
use Cas;
8
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
     4
use phpCAS;
0
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
class HomeController extends Controller {
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    /*
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    |--------------------------------------------------------------------------
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    | Home Controller
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    |--------------------------------------------------------------------------
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    |
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    | This controller renders your application's "dashboard" for users that
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    | are authenticated. Of course, you are free to change or remove the
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    | controller as you wish. It is just here to get your app started!
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
    |
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    */
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
    /**
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    * Create a new controller instance.
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    *
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    * @return void
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    */
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    public function __construct()
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    {
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        $this->middleware('auth.cas');
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    }
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    /**
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    * Show the application dashboard to the user.
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    *
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    * @return Response
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    */
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    public function index()
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    {
8
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    36
        $pt="Error getting PT";
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    37
        $pt=phpCAS::retrievePT(env("LDT_URL")."/api/ldt/1.0/projects/".env("TEST_PROJECT_ID")."/?format=json", $err_code, $err_msg);
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    38
        $ch=curl_init(env("LDT_URL")."/api/ldt/1.0/projects/".env("TEST_PROJECT_ID")."/?format=json&casticket=".$pt);
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    39
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    40
        $proxiedRequestResponse=curl_exec($ch);
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    41
        curl_close($ch);
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    42
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    43
        $loginUrl=env("LDT_URL")."/accounts/caslogin";
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    44
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    45
        return view('home')->with(
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    46
          array("pt" => $pt, "err_code" => $err_code, "err_msg" => $err_msg, "proxiedRequestResponse" => $proxiedRequestResponse, 'loginUrl' => $loginUrl)
5a0cbbe0922a CAS Authentication (normal and proxy) + local Homestead vm
durandn
parents: 0
diff changeset
    47
        );
0
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    }
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    /**
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    * logout
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    *
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    * @return Response
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
    */
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    public function logout()
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    {
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        cas::logout(['service'=>url('/')]);
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        return redirect()->route('index');
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
    }
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
1afc9d2ab94d first commit of cas auth env
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
}