LARAVEL5 integrated Jasig CAs Unified authentication system, laravel5jasig_php tutorial

Source: Internet
Author: User
Tags autoload

LARAVEL5 integrated Jasig CAs Unified authentication system, Laravel5jasig


Cas:cas (central authentication Service) is a good single sign-on framework for WEB applications, which I've just set up on Laravel5 to build a successful CAS. Early preparation: The Laravel5 works that can be run, the server side of CAs already exists.

Environment: Linux (Ubuntu)

One, download Phpcas source code.

Create library directory under Laravel5 project app directory, download Phpcas library,git clone HTTPS://github.com/jasig/phpcas.git , clone down is a Phpcas file directory.

Second, create provider

Create a directory CAs under the app and create a casauthprovider.php with the following content:

1 
 Php2 3 namespace CAs;4 5  UseIlluminate\contracts\auth\userprovider;6  UseIlluminate\contracts\hashing\hasher;7  Useilluminate\contracts\auth\authenticatable;8  UseIlluminate\auth\genericuser;9 Ten classCasauthproviderImplementsUserprovider { One  A     /** - * Retrieve a user by their unique identifier. -      * the * @param mixed $id - * @return \illuminate\auth\userinterface|null -      */ -      Public functionRetrievebyid ($id) { +         return $this-Casuser (); -     } +  A     /** at * Retrieve A user by the given credentials. -      * - * @param array $credentials - * @return \illuminate\auth\userinterface|null -      */ -      Public functionRetrievebycredentials (Array $credentials) { in         return $this-Casuser (); -     } to  +     /** - * Validate A user against the given credentials. the      * * * @param \illuminate\auth\userinterface $user $ * @param array $credentialsPanax Notoginseng * @return BOOL -      */ the      Public functionValidatecredentials (authenticatable$user,Array $credentials) { +         return true; A     } the  +     protected functionCasuser () { -         $cas _host= \config::get (' App.cas_host '); $         //dump ($cas _host); $         $cas _context= \config::get (' App.cas_context '); -         $cas _port= \config::get (' App.cas_port '); -\phpcas::Setdebug (); the\phpcas::client (Cas_version_2_0,$cas _host,$cas _port,$cas _context); -\phpcas::setnocasservervalidation ();Wuyi  the         if(\phpcas::isauthenticated ()) { -             $attributes=Array( Wu' id ' = = \phpcas::getuser (), -' name ' = = \phpcas::GetUser () About             ); $             return NewGenericuser ($attributes); -}Else { -             //\phpcas::setserverurl (\config::get (' App.url ')); -\phpcas::forceauthentication (); A         } +         return NULL; the     } -  $     /** the * Needed by Laravel 4.1.26 and above the      */ the      Public functionRetrievebytoken ($identifier,$token) { the         return New\Exception(' Not implemented '); -     } in  the     /** the * Needed by Laravel 4.1.26 and above About      */ the      Public functionUpdateremembertoken (authenticatable$user,$token) { the         return New\Exception(' Not implemented '); the     } +  - } the Bayi?>

Third, modify Config

Add the following three configuration items to the config/app.php:

' Cas_host ' = ' * * * *,//Authentication server
' Cas_context ' = ', '//still not figuring out what it is
' Cas_port ' =>000,//Authentication Service port
' url ' = ' http://localhost/',

Four, load the certification library

In app/providers/appserviceprovider.php, the authentication method is added in the Register function of class Appserviceprovider:

Auth::extend (' CAs ', function ($app) {
return new Casauthprovider;
});

Modified app/config/auth.php Certification driver: ' Driver ' + ' cas ',

To configure the add-in in Composer.json, add the following path to the Classmap in AutoLoad:

"AutoLoad": {
"Classmap": [
**************
"App/library",
"App/library/phpcas",
"App/cas"
]

}

Executed under the project root: Composer Dump-autoload

Five, realize

Create casauthcontroller.php under app/http/controllers/and add the login and Logout methods:

1   Public functionLogin () {2 3         $message _error= "";4         if(Auth::Check ()) {5             6}Else {7             if(Auth::attempt (Array())) {8                 //Redirect to link after login9             }Ten             //Redirect to un-logged in page One         } ADump (\phpcas::GetUser ()); -Dump (Auth::user ()); -     } the  -      Public functionlogout () { -  -         $cas _host= \config::get (' App.cas_host '); +         //dump ($cas _host); -         $cas _context= \config::get (' App.cas_context '); +         $cas _port= \config::get (' App.cas_port '); A\phpcas::Setdebug (); at\phpcas::client (Cas_version_2_0,$cas _host,$cas _port,$cas _context); -\phpcas::setnocasservervalidation (); -\phpcas::logoutwithredirectservice (\config::get (' App.url '))); -}

Add the routing rule in the routes.php is OK, the project default login and logout method refers to here, when login, will appear the server landing page.

There is a problem, that is, after the change, the original I set the page does not need to be able to browse, and now enter the time will jump out of the landing page, do not know why, I hope the master guidance, thank you!

Reference: https://sonnguyen.ws/how-to-integrate-phpcas-in-laravel/

http://www.bkjia.com/PHPjc/1109448.html www.bkjia.com true http://www.bkjia.com/PHPjc/1109448.html techarticle LARAVEL5 Integrated JASIG CAS Unified authentication System, Laravel5jasig Cas:cas (central authentication Service) is a good single sign-on framework for WEB applications, here I just ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.