简体   繁体   中英

Laravel passport oauth/authorize error

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'];
});

oauth /授权请求错误

oauth /授权请求错误

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.

我遇到了同样的问题,显然,我没有在请求中传递Accept标头

Accept:application/json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM