Required option "access_token" not passed - Laravel 10

superdev

May 17th, 2023 08:51 AM

Hi, Having an issue with laravel passport, any ideas thanks in advance! It is a fresh install of passport, all oauth routes are unchanged.

bobbyiliev

May 18th, 2023 01:24 AM

Hey there 👋

This is quite interesting! I will spin up a new Laravel app now and try to reproduce this as well!

superdev

May 18th, 2023 06:15 PM

Hey Bobby, just checking in. Did you manage to reproduce this issue?

bobbyiliev

May 19th, 2023 03:45 AM

Hey!

Did you follow a specific tutorial?

I think that you have to convert the Converting Authorization Codes To Access Tokens in order for this to work as described here:

Converting Authorization Codes To Access Tokens

This /oauth/token route will return a JSON response containing access_token, refresh_token, and expires_in attributes.

You can use then the access_token for the authentication.

Or you can request a new token with:

use Illuminate\Support\Facades\Http;
 
$response = Http::asForm()->post('http://passport-app.test/oauth/token', [
    'grant_type' => 'password',
    'client_id' => 'client-id',
    'client_secret' => 'client-secret',
    'username' => '[email protected]',
    'password' => 'my-password',
    'scope' => '',
]);
 
return $response->json();

Let me know how it goes!

superdev

May 19th, 2023 05:39 AM

That's the problem. /oauth/token doesn't return an access token

bobbyiliev

May 19th, 2023 06:38 AM

This is very interesting! If you were to do php artisan route:list | grep 'token' do you see the correct controller handling the requests for that endpoint?

It should look like this:

  POST      oauth/token ................................. passport.token › Laravel\Passport › AccessTokenController@issueToken
superdev

May 19th, 2023 06:53 AM

That's one of the first things I've done. It's a normal install. routes are there. I can authenticate fine with Sanctum, but, as this is a planned-to-be OSS app, it's better to use Passport to allow for easier integration, you know?

bobbyiliev

May 19th, 2023 07:01 AM

I just tested this out with a fresh new Laravel 10 App deployed with the 1-Click image on DigitalOcean:

Laravel on DigitalOcean

And it seems to be working as expected.

Did you follow a specific article for the setup? Or did you just follow the documentation?

If you followed an article, can you share the link here so I can test it out as well?

superdev

May 19th, 2023 07:08 AM

Sure, yeah. I followed the article below: https://www.toptal.com/laravel/passport-tutorial-auth-user-access

I'll admit it's outdated, however I also used the 10.x docs. This means there is no Passport::routes. aliases and providers are set correctly in app/config.php.

superdev

May 19th, 2023 07:12 AM

I have encryption keys set already for reference.

bobbyiliev

May 19th, 2023 07:43 AM

Hi there,

Indeed, it looks outdated as it is referring to Laravel 7 and also the laravel/ui package.

Are you using the laravel/ui package as well?

Have you tried following the steps form the Laravel docs on a fresh new install?

superdev

May 19th, 2023 07:47 AM

I have and have the same issues. The reasoning of the laravel/ui package is due to the fact that Passport uses bootstrap for it's views.

bobbyiliev

May 19th, 2023 07:58 AM

Can you share the exact request that you are making? I can try to reproduce it on my end, as with a plain Laravel install + Passport I am unable to reproduce that problem.

superdev

May 19th, 2023 08:19 AM

using the FoF/Passport package I managed to fix the access_token issue ( somehow ) - it was a misconfiguration in config/auth.php

Now I'm getting the following: UnexpectedValueException: Invalid response received from Authorization Server. Expected JSON.

Is there a way to capture this? Please let me know.

bobbyiliev

May 20th, 2023 02:46 AM

Hey!

I've never used that package so not 100% sure what might be causing this :/ also not sure if the package is still actively maintained.

I can see that you've actually already raised an issue with them here which would have been my suggestion as well!