Skip to content

Instantly share code, notes, and snippets.

@leitom
Last active October 15, 2016 13:10
Show Gist options
  • Save leitom/759b55294b4db253ecf29bda1e0bb873 to your computer and use it in GitHub Desktop.
Save leitom/759b55294b4db253ecf29bda1e0bb873 to your computer and use it in GitHub Desktop.
Simple helper function for creating user with access token in laravel 5.3 with passport
<?php
use Laravel\Passport\ClientRepository;
train OauthHelper
{
public function getOauthUser($password = 'secret', array $attributes = [])
{
$user = factory(App\User::class)->create(
array_merge($attributes, ['password' => bcrypt($password),])
);
$client = app(ClientRepository::class)->createPasswordGrantClient(
$user->id, 'testing', 'http://localhost'
);
$response = $this->call('POST', '/oauth/token', [
'grant_type' => 'password',
'client_id' => $client->id,
'client_secret' => $client->secret,
'username' => $user->email,
'password' => $password,
]);
return [
$user,
json_decode($response->getContent(), true)['access_token']
];
}
}
// list($user, $token) = $this->getOauthUser();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment