Reputation: 387
I'm trying to use Passport using the oauth/authorize in order to allow web application to get the code and request token later, but I'm getting the error
Route [login] not defined
Below is my code.
Client code
// First route that user visits on consumer app
Route::get('/', function () {
// Build the query parameter string to pass auth information to our request
$query = http_build_query([
'client_id' => 3,
//'client_secret' => 'MtkEmBL0f0Bf4LcEPcOBUS0wLHvF5xqqchhCpaTH',
'redirect_uri' => 'http://client.app:8082/callback',
'response_type' => 'code',
'scope' => ''
]);
// Redirect the user to the OAuth authorization page
return redirect('http://server.app:8082/oauth/authorize?' . $query);
});
// Route that user is forwarded back to after approving on server
Route::get('/callback', function (Request $request) {
return 'test 2';
$http = new GuzzleHttp\Client;
$response = $http->post('http://server.app:8082/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 3, // from admin panel above
'client_secret' => 'MtkEmBL0f0Bf4LcEPcOBUS0wLHvF5xqqchhCpaTH', // from admin panel above
'redirect_uri' => 'http://client.app:8082/callback',
'code' => $request->code // Get code from the callback
]
]);
// echo the access token; normally we would save this in the DB
return json_decode((string) $response->getBody(), true)['access_token'];
});
Upvotes: 2
Views: 4549
Reputation: 387
I had the same issue, apparently, i wasn't passing the Accept header in the request
Accept:application/json
Upvotes: 1
Reputation: 11340
Maybe you have more than one error. Looks like you forgot to define common auth routes. Start from php artisan make:auth
or Auth::routes()
. OAuth routes doesn't have login
route, the error you've got says you didn't define login
route. It is defined in Auth::routes()
actually.
Upvotes: 2