How to login to AUTH (Laravel) with data coming from a third party API?

0

I'm developing a news app in laravel 5 for a client, but it already has a working system, and wants me to use the existing database so that system users can sign in to the news app and has developed a jSON API that returns me

string(74) "{"Status":1,"Usuario":"John Doe Smith","Mensagem":"Login liberado!"}"

or

string(75) "{"Status":0,"Usuario":" John Doe Smith ","Mensagem":"Senha incorreta!"}"

How can I log in with AUTH from these two API responses?

    
asked by anonymous 13.05.2017 / 19:57

1 answer

0

In this case you will not use the default authentication drivers, create the routine that receives the name and password entry, call the API and with the result, being "Login Released" instantiate a User object and register it as authenticated:

 $api = ...retorno da API em json...
 $user = new User(["username" => $api.Usuario, "email" => $api.Email]);
 Auth::login($user);
 redirect('rota depois do login');

In the example above I'm assuming that you have the fields User and Email, which is interesting to receive as API return. The main line is the one that demonstrates the possibility of performing authentication in the Auth facade, guaranteeing the possibilities of using it in the application in a standardized way by the documentation.

    
23.05.2017 / 14:07