Answer the question
In order to leave comments, you need to log in
API authentication controller in laravel?
Hello. I am writing a laravel passport based authentication api for a mobile app. Users do not have a password. They log in with an SMS code. First, they enter a phone number -> an SMS code is sent to them -> and then there is a login request (with an SMS code in the request body) to the following controller method:
public function login(Request $request, User $user)
{
if ($request->get('phone_code') === $user->phone_code) {
Auth::login($user, true);
$token = $user->createToken($user->phone);
return response()->json(["user" => auth()->user(), 'token_type' => 'Bearer', 'token' => $token->accessToken], 200);
} else {
return response()->json(["message" => "Wrong code"], 403);
}
}
Answer the question
In order to leave comments, you need to log in
And what about the password? I use a passport, there is no password in the application either (and even a username/email'a). They are not related.
Do as in the docks, it is not tied to a password.
According to the documentation, the concept is to give both access_token and refresh_token on the authorization endpoint, and when the current access_token is no longer valid, take the previously received refresh_token, make a request for a refresh endpoint and receive a new access_token. According to what data the user received his very first access_token and refresh_token is purely a matter of the authorization architecture of this particular application.
https://laravel.com/docs/5.8/passport#refreshing-tokens
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question