Q:

How to generate access_token without username and password

I am trying to make an API with Passport. If a user tries to login or signs up with Socialite, find user than generate access_token then redirect to the frontend with access_token in URL parameters.
I tried to register and login than generate access_token with user email and the default password, which is not suitable for security.
try {
    $serviceUser = Socialite::driver($service)->stateless()->user();
} catch (\Exception $e) {
    return redirect(config('app.client_url').'/auth/social-callback?error=Unable to login using '.$service.'. Please try again'.'&origin=login');
}

$email = $serviceUser->getEmail();
$name = $serviceUser->getName();
$user = $this->getExistingUser($serviceUser, $email, $service);
$newUser = false;
if (!$user) {
    $newUser = true;
    $user = new User;
    $user->name = $name;
    $user->email = $email;
    $user->username = Str::random(10);
    if ($service === 'facebook') {
        $user->image = $serviceUser->avatar;
    }
    $user->verify = true;
    $user->save();
}
if ($this->needsToCreateSocial($user, $service)) {
    Social::create([
        'user_id' => $user->id,
        'social_id' => $serviceUser->getId(),
        'service' => $service
    ]);
}

$http = new Client;

$response = $http->post(config('app.url').'/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => '2',
        'client_secret' => 'oBKWxgF2fDvrxwA05ciapwy4JYKaHxzhGzr6D24X',
        'username' => $email,
        'password' => 'gebdandi',
        'scope' => '',
    ],
]);

$body = json_decode((string) $response->getBody(), true);

$accessToken = $body['access_token'];

return redirect(config('app.client_url').'/social-callback?token='.$accessToken.'&origin='.($newUser ? 'register' : 'login'));

I can't find any solution in the documentation.

A:

after reading all documentation i found solution in this documentation
i did like this
edit authserviceprovider like this
public function boot()
    {
        $this->registerPolicies();

        Passport::routes();
        Passport::personalAccessClientId(1);
        Passport::tokensExpireIn(now()->addDays(15));
        Passport::refreshTokensExpireIn(now()->addDays(30));
    }

added code in controller like this
$accessToken = $user->createToken('access_token')->accessToken;

thanks for laravel Team for provide good documentation 

