This API returns an email, a handle, and an access token and a refresh token.
@pirmax This suggests the API uses OAuth. You usually use the returned OAuth token to then get further details about the token owner (user) via a profile or “me” endpoint. You should then use this data to connect that user to a user in your database, and start a session in your application for that user.
Given you seem to get a “did” as an identifier for the user on the external service, you can use that to map external users to your users.
With Socialite, the flow would look something like this:
public function handleProviderCallback()
{
$externalUser = Socialite::driver('[service]')->user();
// Look up user by external ID
$user = User::query()->where('external_id', '=', $user->getId())->first();
// If a user with that external ID wasn't found, show an error
if ($user === null) {
// TODO: Show error and prompt user to register instead
}
// If a user was found in your database, authenticate them
Auth::login($user);
// TODO: Redirect to whatever URL now that user has been authenticated
}
You now don’t need to create a custom user provider that’s going to be executing API requests on every HTTP request to your application, and increase your application’s response times.