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

Blank page after returned to redirect url with error in console #23

Closed 0xACCE55 closed 2 years ago

0xACCE55 commented 2 years ago

Bug Report

Current Behavior After completing the OAuth flow and the 'code' param is returned when redirected to the redirect url, i.e /auth/passport?code=

A blank page is returned with the below error in the console

passport?code={code was here}:1 Uncaught TypeError: Cannot read property 'app' of null
    at passport?code={code was here}:1
(anonymous) @ passport?code={code was here}:1

Which is referring to this part of the code <script>window.close(); window.opener.app.authenticationComplete({"email":"{email was here}","token":"{token was here}","provided":["email"]});</script>

Environment

Flarum core 1.0.4
PHP version: 7.4.16
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, pcntl, readline, Reflection, SPL, session, standard, bz2, calendar, ctype, curl, dom, mbstring, fileinfo, ftp, gd,
 gettext, iconv, intl, json, exif, mysqlnd, PDO, Phar, SimpleXML, sockets, sodium, sqlite3, tokenizer, xml, xmlwriter, xsl, mysqli, pdo_mysql, pdo_sqlite, xmlreader, xmlrpc, imagick, zip,
mysql, Zend OPcache
+----------------------+---------+--------+
| Flarum Extensions    |         |        |
+----------------------+---------+--------+
| ID                   | Version | Commit |
+----------------------+---------+--------+
| flarum-flags         | v1.0.0  |        |
| fof-passport         | 1.0.0   |        |
| flarum-tags          | v1.0.3  |        |
| flarum-suspend       | v1.0.0  |        |
| flarum-subscriptions | v1.0.0  |        |
| flarum-sticky        | v1.0.0  |        |
| flarum-statistics    | v1.0.0  |        |
| flarum-mentions      | v1.0.0  |        |
| flarum-markdown      | v1.0.1  |        |
| flarum-lock          | v1.0.0  |        |
| flarum-likes         | v1.0.0  |        |
| flarum-lang-english  | v1.0.0  |        |
| flarum-emoji         | v1.0.0  |        |
| flarum-bbcode        | v1.0.0  |        |
| flarum-approval      | v1.0.0  |        |
+----------------------+---------+--------+
0xACCE55 commented 2 years ago

I was being a potato and going directly to the /auth/passport URL in the browser. Ima close this one off.

thgh commented 2 weeks ago

I wish opening /auth/passport would be supported. I don't want the user to have to click login...

It's possible with this tweak:

# Replace '<script>window.close(); window.opener.app.authenticationComplete(%s);</script>',
# With '<script>if (window.opener){window.close(); window.opener.app.authenticationComplete(%s);}else{location.href="/"}</script>',
# In /flarum/app/vendor/flarum/core/src/Forum/Auth/ResponseFactory.php
RUN sed -i 's/<script>window.close(); window.opener.app.authenticationComplete(%s);<\/script>/<script>if (window.opener){window.close(); window.opener.app.authenticationComplete(%s);}else{location.href="\/"}</g' /flarum/app/vendor/flarum/core/src/Forum/Auth/ResponseFactory.php