How do I log into the AUTH (Laravel) with data from a third-party API ?

Asked

Viewed 592 times

0

I am developing a news application in Laravel 5 for a client, but it already has a system in operation, and wants me to use the existing database so that system users can log in to the news app and 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 ?

1 answer

0

In this case you will not use the default authentication controllers, create the routine that receives the entry of name and password, call the API and with the result, being "Login released" please enter 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 above example I am assuming that you have the User and Email fields, which is interesting to receive as return from the API. The main line is the one that demonstrates the possibility to perform the authentication in the facade Auth, guaranteeing the possibilities of its use in the application of standardized form by the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.