· 8 years ago · May 18, 2017, 05:48 PM
1public function authToken (Request $request) {
2 $username = $request->input('username');
3 $password = $request->input('password');
4
5 if (Auth::attempt(['email' => $username, 'password' => $password])) {
6 // Auth accepted > send to /oauth/token
7 $http = new \GuzzleHttp\Client();
8
9 $response = $http->post('http://localhost:8000/test', [
10 'form_params' => [
11 'grant_type' => 'password',
12 'client_id' => '2',
13 'client_secret' => 'pc4cjW6KEwufFAf31f1HRFFTtL2dOHPmTgDLKR',
14 'username' => $username,
15 'password' => $password,
16 'scope' => '',
17 ],
18 ]);
19
20 return json_decode((string) $response->getBody(), true);
21
22 } else {
23 return 'Email or Password is incorrect';
24 }
25}