FriendsOfFlarum / passport

The Laravel passport compatible oauth extension for your Flarum forum.
https://discuss.flarum.org/d/5203
MIT License
29 stars 11 forks source link

Invalid response received from Authorization Server. Expected JSON. #36

Open Supernova3339 opened 1 year ago

Supernova3339 commented 1 year ago

Bug Report

Current Behavior Gets invalid JSON response and throws error

Steps to Reproduce

  1. Go to '/auth/passport'
  2. Click on 'authorize'
  3. See error

Expected Behavior

Response is successful and redirects with user authenticated

Screenshots Not needed to reproduce

Environment

Flarum core: 1.7.2
PHP version: 8.1.18
MySQL version: 5.7.41-cll-lve
Loaded extensions: Core, date, libxml, openssl, pcre, sqlite3, zlib, bz2, calendar, ctype, curl, hash, filter, ftp, gettext, json, iconv, SPL, pcntl, readline, Reflection, session, standard, mbstring, shmop, SimpleXML, tokenizer,xml, bcmath, dom, fileinfo, gd, geoip, imap, intl, exif, mysqli, mysqlnd, PDO, pdo_mysql, pdo_sqlite, pgsql, Phar,posix, soap, sockets, sodium, xmlreader, xmlwriter, xsl, zip, ionCube Loader, Zend OPcache
+----------------------+---------+--------+
| Flarum Extensions    |         |        |
+----------------------+---------+--------+
| ID                   | Version | Commit |
+----------------------+---------+--------+
| flarum-flags         | v1.7.0  |        |
| flarum-approval      | v1.7.0  |        |
| sycho-private-facade | v0.1.12 |        |
| fof-passport         | 1.1.0   |        |
| flarum-tags          | v1.7.1  |        |
| flarum-suspend       | v1.7.0  |        |
| flarum-subscriptions | v1.7.0  |        |
| flarum-sticky        | v1.7.0  |        |
| flarum-statistics    | v1.7.0  |        |
| flarum-mentions      | v1.7.0  |        |
| flarum-markdown      | v1.7.0  |        |
| flarum-lock          | v1.7.0  |        |
| flarum-likes         | v1.7.0  |        |
| flarum-lang-english  | v1.7.0  |        |
| flarum-emoji         | v1.7.0  |        |
| flarum-bbcode        | v1.7.0  |        |
| extiverse-mercury    | 0.2.0   |        |
| blomstra-fontawesome | 0.1.5   |        |
| bilgehanars-packman  | v1.1    |        |
+----------------------+---------+--------+
Base URL: https://ommitted
Installation path: /home/supersft/ommitted
Queue driver: sync
Session driver: file
Mail driver: mail
Debug mode: off

Possible solution(s)

Additional Context This issue is present on Flarum 1.8.0

clarkwinkelmann commented 1 year ago

Can you share the exact error message? Is there any entry in Flarum or Laravel log file or is it just shown on the page?

Any difference when trying again with debug enabled in config.php?

Are you able to perform a request to your Laravel app from the command line on the Flarum server? like curl <Laravel homepage URL>

nxmndr commented 9 months ago

Hi, similar problem here.

The exact error message is OP's title. Here is the stack trace if that helps : flarum.ERROR: UnexpectedValueException: Invalid response received from Authorization Server. Expected JSON. in /var/www/web/vendor/league/oauth2-client/src/Provider/AbstractProvider.php:885

Stack trace: ``` #0 /var/www/web/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(865): League\OAuth2\Client\Provider\AbstractProvider->fetchResourceOwnerDetails() #1 /var/www/web/vendor/fof/passport/src/Controllers/PassportController.php(96): League\OAuth2\Client\Provider\AbstractProvider->getResourceOwner() #2 /var/www/web/vendor/flarum/core/src/Http/RouteHandlerFactory.php(41): FoF\Passport\Controllers\PassportController->handle() #3 /var/www/web/vendor/flarum/core/src/Http/Middleware/ExecuteRoute.php(27): Flarum\Http\RouteHandlerFactory->Flarum\Http\{closure}() #4 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ExecuteRoute->process() #5 /var/www/web/vendor/flarum/core/src/Http/Middleware/ContentTypeOptionsHeader.php(21): Laminas\Stratigility\Next->handle() #6 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ContentTypeOptionsHeader->process() #7 /var/www/web/vendor/flarum/core/src/Http/Middleware/ReferrerPolicyHeader.php(30): Laminas\Stratigility\Next->handle() #8 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ReferrerPolicyHeader->process() #9 /var/www/web/vendor/flarum/core/src/Http/Middleware/FlarumPromotionHeader.php(30): Laminas\Stratigility\Next->handle() #10 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\FlarumPromotionHeader->process() #11 /var/www/web/vendor/flarum/core/src/Http/Middleware/ShareErrorsFromSession.php(57): Laminas\Stratigility\Next->handle() #12 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ShareErrorsFromSession->process() #13 /var/www/web/vendor/flarum/core/src/Http/Middleware/CheckCsrfToken.php(36): Laminas\Stratigility\Next->handle() #14 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\CheckCsrfToken->process() #15 /var/www/web/vendor/flarum/core/src/Http/Middleware/ResolveRoute.php(69): Laminas\Stratigility\Next->handle() #16 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ResolveRoute->process() #17 /var/www/web/vendor/flarum/core/src/Http/Middleware/SetLocale.php(51): Laminas\Stratigility\Next->handle() #18 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\SetLocale->process() #19 /var/www/web/vendor/flarum/core/src/Http/Middleware/AuthenticateWithSession.php(31): Laminas\Stratigility\Next->handle() #20 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\AuthenticateWithSession->process() #21 /var/www/web/vendor/flarum/core/src/Http/Middleware/RememberFromCookie.php(52): Laminas\Stratigility\Next->handle() #22 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\RememberFromCookie->process() #23 /var/www/web/vendor/flarum/core/src/Http/Middleware/StartSession.php(61): Laminas\Stratigility\Next->handle() #24 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\StartSession->process() #25 /var/www/web/vendor/flarum/core/src/Http/Middleware/CollectGarbage.php(46): Laminas\Stratigility\Next->handle() #26 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\CollectGarbage->process() #27 /var/www/web/vendor/flarum/core/src/Http/Middleware/ParseJsonBody.php(28): Laminas\Stratigility\Next->handle() #28 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ParseJsonBody->process() #29 /var/www/web/vendor/flarum/core/src/Http/Middleware/HandleErrors.php(57): Laminas\Stratigility\Next->handle() #30 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\HandleErrors->process() #31 /var/www/web/vendor/flarum/core/src/Http/Middleware/InjectActorReference.php(25): Laminas\Stratigility\Next->handle() #32 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\InjectActorReference->process() #33 /var/www/web/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle() #34 /var/www/web/vendor/middlewares/request-handler/src/RequestHandler.php(84): Laminas\Stratigility\MiddlewarePipe->process() #35 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Middlewares\RequestHandler->process() #36 /var/www/web/vendor/middlewares/base-path-router/src/BasePathRouter.php(99): Laminas\Stratigility\Next->handle() #37 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Middlewares\BasePathRouter->process() #38 /var/www/web/vendor/laminas/laminas-stratigility/src/Middleware/OriginalMessages.php(36): Laminas\Stratigility\Next->handle() #39 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\Middleware\OriginalMessages->process() #40 /var/www/web/vendor/middlewares/base-path/src/BasePath.php(73): Laminas\Stratigility\Next->handle() #41 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Middlewares\BasePath->process() #42 /var/www/web/vendor/flarum/core/src/Http/Middleware/ProcessIp.php(24): Laminas\Stratigility\Next->handle() #43 /var/www/web/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ProcessIp->process() #44 /var/www/web/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle() #45 /var/www/web/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(64): Laminas\Stratigility\MiddlewarePipe->process() #46 /var/www/web/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php(73): Laminas\Stratigility\MiddlewarePipe->handle() #47 /var/www/web/vendor/flarum/core/src/Http/Server.php(45): Laminas\HttpHandlerRunner\RequestHandlerRunner->run() #48 /var/www/web/public/index.php(26): Flarum\Http\Server->listen() #49 {main} ```

The process seems straightforward at first but it is unclear really. Does Passport require an auth scaffolding ? Initially it complained the "login" route didn't exist. I installed laravel/ui and now I see a small window where I can login, but the error appears after I try to login.

Enabling debug shows the stack trace in Ignition in said small login window.

They are both installed on the same server and can reach each other.

nxmndr commented 9 months ago

Do I have to install Flarum on the Passport side too ? So far I only see the user created in Passport, but they don't appear in the Flarum users. How do you handle user-specific permissions or other interactions ? Eg. how do I make a Passport-authenticated user mod or admin, or PM them ?

So many questions... I hoped OAuth2 handled these questions.