FriendsOfFlarum / passport

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

Argument #2 ($identifier) must be of type string, null given #37

Closed xrh0905 closed 1 year ago

xrh0905 commented 1 year ago

Bug Report

Current Behavior After authorized in login.microsoftonline.com, thowing error and cannot continue.

Steps to Reproduce

  1. Click on Login with microsoft
  2. Authorize as microsoft asked.
  3. See error

Expected Behavior Sucessfully authorized.

Logs

[2023-05-20 14:32:48] flarum.ERROR: TypeError: Flarum\Forum\Auth\ResponseFactory::make(): Argument #2 ($identifier) must be of type string, null given, called in /opt/www/xmccbbs/vendor/fof/passport/src/Controllers/PassportController.php on line 105 and defined in /opt/www/xmccbbs/vendor/flarum/core/src/Forum/Auth/ResponseFactory.php:36
Stack trace:
#0 /opt/www/xmccbbs/vendor/fof/passport/src/Controllers/PassportController.php(105): Flarum\Forum\Auth\ResponseFactory->make()
#1 /opt/www/xmccbbs/vendor/flarum/core/src/Http/RouteHandlerFactory.php(41): FoF\Passport\Controllers\PassportController->handle()
#2 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ExecuteRoute.php(27): Flarum\Http\RouteHandlerFactory->Flarum\Http\{closure}()
#3 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ExecuteRoute->process()
#4 /opt/www/xmccbbs/vendor/fof/discussion-language/src/Middleware/AddLanguageFilter.php(49): Laminas\Stratigility\Next->handle()
#5 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): FoF\DiscussionLanguage\Middleware\AddLanguageFilter->process()
#6 /opt/www/xmccbbs/vendor/fof/oauth/src/Middleware/ErrorHandler.php(50): Laminas\Stratigility\Next->handle()
#7 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): FoF\OAuth\Middleware\ErrorHandler->process()
#8 /opt/www/xmccbbs/vendor/fof/terms/src/Middlewares/RegisterMiddleware.php(59): Laminas\Stratigility\Next->handle()
#9 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): FoF\Terms\Middlewares\RegisterMiddleware->process()
#10 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ContentTypeOptionsHeader.php(21): Laminas\Stratigility\Next->handle()
#11 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ContentTypeOptionsHeader->process()
#12 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ReferrerPolicyHeader.php(30): Laminas\Stratigility\Next->handle()
#13 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ReferrerPolicyHeader->process()
#14 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/FlarumPromotionHeader.php(30): Laminas\Stratigility\Next->handle()
#15 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\FlarumPromotionHeader->process()
#16 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ShareErrorsFromSession.php(57): Laminas\Stratigility\Next->handle()
#17 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ShareErrorsFromSession->process()
#18 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/CheckCsrfToken.php(36): Laminas\Stratigility\Next->handle()
#19 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\CheckCsrfToken->process()
#20 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ResolveRoute.php(69): Laminas\Stratigility\Next->handle()
#21 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ResolveRoute->process()
#22 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/SetLocale.php(51): Laminas\Stratigility\Next->handle()
#23 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\SetLocale->process()
#24 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/AuthenticateWithSession.php(31): Laminas\Stratigility\Next->handle()
#25 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\AuthenticateWithSession->process()
#26 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/RememberFromCookie.php(52): Laminas\Stratigility\Next->handle()
#27 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\RememberFromCookie->process()
#28 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/StartSession.php(61): Laminas\Stratigility\Next->handle()
#29 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\StartSession->process()
#30 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/CollectGarbage.php(46): Laminas\Stratigility\Next->handle()
#31 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\CollectGarbage->process()
#32 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ParseJsonBody.php(28): Laminas\Stratigility\Next->handle()
#33 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ParseJsonBody->process()
#34 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/HandleErrors.php(57): Laminas\Stratigility\Next->handle()
#35 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\HandleErrors->process()
#36 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/InjectActorReference.php(25): Laminas\Stratigility\Next->handle()
#37 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\InjectActorReference->process()
#38 /opt/www/xmccbbs/vendor/fof/merge-discussions/src/Middleware/Redirection.php(28): Laminas\Stratigility\Next->handle()
#39 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): FoF\MergeDiscussions\Middleware\Redirection->process()
#40 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle()
#41 /opt/www/xmccbbs/vendor/middlewares/request-handler/src/RequestHandler.php(84): Laminas\Stratigility\MiddlewarePipe->process()
#42 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Middlewares\RequestHandler->process()
#43 /opt/www/xmccbbs/vendor/middlewares/base-path-router/src/BasePathRouter.php(101): Laminas\Stratigility\Next->handle()
#44 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Middlewares\BasePathRouter->process()
#45 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Middleware/OriginalMessages.php(36): Laminas\Stratigility\Next->handle()
#46 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Laminas\Stratigility\Middleware\OriginalMessages->process()
#47 /opt/www/xmccbbs/vendor/middlewares/base-path/src/BasePath.php(73): Laminas\Stratigility\Next->handle()
#48 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Middlewares\BasePath->process()
#49 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Middleware/ProcessIp.php(24): Laminas\Stratigility\Next->handle()
#50 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/Next.php(49): Flarum\Http\Middleware\ProcessIp->process()
#51 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle()
#52 /opt/www/xmccbbs/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(64): Laminas\Stratigility\MiddlewarePipe->process()
#53 /opt/www/xmccbbs/vendor/laminas/laminas-httphandlerrunner/src/RequestHandlerRunner.php(73): Laminas\Stratigility\MiddlewarePipe->handle()
#54 /opt/www/xmccbbs/vendor/flarum/core/src/Http/Server.php(45): Laminas\HttpHandlerRunner\RequestHandlerRunner->run()
#55 /opt/www/xmccbbs/public/index.php(26): Flarum\Http\Server->listen()
#56 {main}

Screenshot 屏幕截图 2023-05-20 223457

Environment

Flarum core: 1.7.2
PHP version: 8.1.18
MySQL version: 10.5.19-MariaDB-0+deb11u2
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, apcu, bcmath, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, gmp, iconv, igbinary, imagick, imap, intl, ldap, exif, msgpack, mysqli, pdo_mysql, pdo_sqlite, Phar, posix, readline, redis, shmop, SimpleXML, smbclient, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, memcached, libsmbclient, Zend OPcache
+--------------------------------+---------+--------+
| Flarum Extensions              |         |        |
+--------------------------------+---------+--------+
| ID                             | Version | Commit |
+--------------------------------+---------+--------+
| flarum-flags                   | v1.7.0  |        |
| flarum-approval                | v1.7.0  |        |
| flarum-subscriptions           | v1.7.0  |        |
| flarum-tags                    | v1.7.1  |        |
| flarum-nicknames               | v1.7.0  |        |
| flarum-suspend                 | v1.7.0  |        |
| fof-follow-tags                | 1.1.7   |        |
| zerosonesfun-direct-links      | 3.1     |        |
| v17development-seo             | v1.8.0  |        |
| pipecraft-id-slug              | v1.1.0  |        |
| glowingblue-password-strength  | 3.1.0   |        |
| ganuonglachanh-sonic           | 0.1.8   |        |
| fof-username-request           | 1.1.2   |        |
| fof-user-directory             | 1.2.3   |        |
| fof-user-bio                   | 1.1.0   |        |
| fof-upload                     | 1.2.3   |        |
| fof-terms                      | 1.2.1   |        |
| fof-subscribed                 | 1.1.3   |        |
| fof-split                      | 1.1.0   |        |
| fof-spamblock                  | 1.1.0   |        |
| fof-sitemap                    | 2.1.0   |        |
| fof-realtimelogin              | 1.0.0   |        |
| fof-reactions                  | 1.1.5   |        |
| fof-profile-image-crop         | 1.1.0   |        |
| fof-prevent-necrobumping       | 1.1.1   |        |
| fof-pretty-mail                | 1.1.1   |        |
| fof-polls                      | 1.3.0   |        |
| fof-passport                   | 1.1.0   |        |
| fof-oauth                      | 1.3.0   |        |
| fof-nightmode                  | 1.5.1   |        |
| fof-merge-discussions          | 1.3.1   |        |
| fof-links                      | 1.1.4   |        |
| fof-linguist                   | 1.1.1   |        |
| fof-impersonate                | 1.1.1   |        |
| fof-geoip                      | 1.1.0   |        |
| fof-formatting                 | 1.0.2   |        |
| fof-drafts                     | 1.2.2   |        |
| fof-discussion-language        | 1.2.9   |        |
| fof-default-user-preferences   | 1.2.0   |        |
| fof-default-group              | 1.1.1   |        |
| fof-custom-footer              | 1.1.0   |        |
| fof-best-answer                | 1.2.5   |        |
| fof-bbcode-tabs                | 1.0.3   |        |
| fof-bbcode-details             | 1.1.1   |        |
| fof-analytics                  | 1.1.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-lang-chinese-simplified | v1.2.0  |        |
| flarum-emoji                   | v1.7.0  |        |
| flarum-bbcode                  | v1.7.0  |        |
| clarkwinkelmann-author-change  | 1.0.3   |        |
| askvortsov-pwa                 | v3.3.3  |        |
| antoinefr-bbcode-fa            | v1.0.0  |        |
+--------------------------------+---------+--------+
Base URL: https://bbs.xmcc.xrh0905.top
Installation path: /opt/www/xmccbbs
Queue driver: sync
Session driver: file
Scheduler status: Active
Mail driver: mail
Debug mode: off

Possible solution(s)

Additional Context Config:

OAuth Authorize Link
https://login.microsoftonline.com/common/oauth2/v2.0/authorize
OAuth Token Link
https://login.microsoftonline.com/common/oauth2/v2.0/token
OAuth Profile Link
https://graph.microsoft.com/oidc/userinfo
Scope
User.Read, profile, email, openid
Supernova3339 commented 1 year ago

there is a driver to login with microsoft already

xrh0905 commented 1 year ago

there is a driver to login with microsoft already

Hi. Thanks for the reply, but I couldn't find any driver to login with microsoft. There is a link to the https://github.com/imorland/flarum-ext-oauth-microsoft but it's empty.

Supernova3339 commented 1 year ago

there is a driver to login with microsoft already

Hi. Thanks for the reply, but I couldn't find any driver to login with microsoft. There is a link to the https://github.com/imorland/flarum-ext-oauth-microsoft but it's empty.

Must not be maintained anymore

clarkwinkelmann commented 1 year ago

I'm really not sure about your error, but wouldn't it make more sense to implement (or find an existing) Microsoft League OAuth driver and then integrate that driver in FoF OAuth extension, rather than trying to somehow make it work with Passport? Passport is already a custom OAuth driver for FoF OAuth.

While Passport might be compatible with a range of compliant oauth2 implementation, it's designed specifically for Laravel's Passport. Since you must be able to control the JSON payload that gets returned by the server during authorization I'm not sure how you would get Microsoft to answer using the default Laravel syntax.

Instead, a custom League OAuth driver could be used to implement the flow following Microsoft's documentation rather than trying to make 2 different opinionated implementations of oauth2 work together.

Supernova3339 commented 1 year ago

I'm really not sure about your error, but wouldn't it make more sense to implement (or find an existing) Microsoft League OAuth driver and then integrate that driver in FoF OAuth extension, rather than trying to somehow make it work with Passport? Passport is already a custom OAuth driver for FoF OAuth.

While Passport might be compatible with a range of compliant oauth2 implementation, it's designed specifically for Laravel's Passport. Since you must be able to control the JSON payload that gets returned by the server during authorization I'm not sure how you would get Microsoft to answer using the default Laravel syntax.

Instead, a custom League OAuth driver could be used to implement the flow following Microsoft's documentation rather than trying to make 2 different opinionated implementations of oauth2 work together.

Sorry to intrude, but do you have any ideas with my issue? It iś using fresh install of Laravel Passport

xrh0905 commented 1 year ago

I'm really not sure about your error, but wouldn't it make more sense to implement (or find an existing) Microsoft League OAuth driver and then integrate that driver in FoF OAuth extension, rather than trying to somehow make it work with Passport? Passport is already a custom OAuth driver for FoF OAuth.

While Passport might be compatible with a range of compliant oauth2 implementation, it's designed specifically for Laravel's Passport. Since you must be able to control the JSON payload that gets returned by the server during authorization I'm not sure how you would get Microsoft to answer using the default Laravel syntax.

Instead, a custom League OAuth driver could be used to implement the flow following Microsoft's documentation rather than trying to make 2 different opinionated implementations of oauth2 work together.

Thanks. I'll implent Oauth extension instead.