Last active
October 15, 2016 13:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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