Laravel 4 custom Auth

First of all, sorry for my English, I will try to do my best.

Im new for Laravel, im trying to implement user authentication through SOAP WS, I declare a new class that implements UserProviderInterface. I successfully execute the retrieveByCredentials and validateCredentials methods, but since I do not have access to the database or global user information, I cannot implement the retrieveByID method. Is there a way to make user Auth not based on user id?

I need:

- Login and validate user throught SOAP WS - Store User Info returned by WS. - Remember me functionality - Secure routes based on logged user and level of access - Logout 

Implemented Class:

  <?php namespace Spt\Common\Providers; use Illuminate\Auth\UserProviderInterface; use Illuminate\Auth\GenericUser; use Illuminate\Auth\UserInterface; class AuthUserProvider implements UserProviderInterface{ private $user; public function __construct(){ $this->user = null; } public function retrieveByID($identifier){ return $this->user; } public function retrieveByCredentials(array $credentials){ $client = new \SoapClient('webserviceurl'); $res = $client->Validar_Cliente($credentials); $res = $res->Validar_ClienteResult; if($res->infoError->bError === true){ return; } $res->id = $res->id_cliente; $user = new GenericUser((array) $res); return $user; } public function validateCredentials(UserInterface $user, array $credentials){ //Assumed that if WS returned a User is validated return true; } } 

I think UserProviderInterface its not a solution, but I googled and didn't find another way

Any idea?

+6
source share
1 answer

You are almost done, except that the private variable $user of AuthUserProvider does not withstand the current HTTP request. If you cannot "get by id" from your web service, I think the only way to save the entire user in the session is Laravel itself stores the user ID in the session and the fact that it only stores the identifier (and not the entire user) is one of the reasons the retrieveByID method is needed.
The following is for clarification only and unverified.

 class AuthUserProvider implements UserProviderInterface { public function retrieveByCredentials(array $credentials) { $client = new \SoapClient('webserviceurl'); $res = $client->Validar_Cliente($credentials); $res = $res->Validar_ClienteResult; if($res->infoError->bError === true) { return; } $res->id = $res->id_cliente; Session::put('entireuser', $res); $user = new GenericUser((array) $res); return $user; } public function retrieveByID($identifier) { $res = Session::get('entireuser'); return new GenericUser((array) $res); } // ... } 

If you can’t get the identifier from your web service, I think you can’t either retrieve it with the key, but you can’t implement the “remember me” functionality if you don’t save some of the user data in the second database (which at that moment may be used instead of the session above).

+2
source

All Articles