• Extensions
  • PHP and WordPress Single Sign On (SSO) with optional JWT Addon

maicol07 Hey. I hardcoded the forum URL in LoginMiddleware and now it works. I know that's not a good solution but thought that you should be informed. Again thanks for this great plugin.

    tharuka So, you wrote the full URL instead of getting it from the config file?
    Thank you for letting me know it

      maicol07 instead of $request->getUri() in RedirectResponse I used my forum URL. Then it worked. I think the problem is that $request->getUri() passes the root URL to the RedirectResponse funtion in LoginMiddleware.

        tharuka the only issue in this way is that you'll always be redirect to Flarum root and not to the page you requested

          maicol07 No. Since I used this with Codeigniter 4. I can use redirect function to redirect to the URL I want and It works. I don't know about $flarum->redirect() method which provide in the library.

            tharuka I didn't mean that. The $flarum->redirect() method only redirects the user to Flarum root. What I say is within the extension. The middleware runs on every request to Flarum. So if the user clicks a link to a discussion in your Flarum (i.e. from google) then the login middleware runs. If user is signed in in your auth system then it will be logged in and page is refresh (Redirect to the same page). Writing the forum url overrides this refresh and redirects to Flarum root

              maicol07 Oh I see. That is a problem. Hope you will find a solution. Again thank you for your hard work.

              Is there any way I could use Google OAuth with this plugin? I tried setting up Google Social Login with a WP plugin but it doesn't seem to login into Flarum.

                Sanyu you must use a plugin for WP for this to work that uses the standard WP auth flow (basically, it must call the authenticate filter). Ask the plugin developer or choose another plugin

                  Hi @maicol07
                  Sorry to bother you a lot.
                  My folder structure is like this

                  www
                  ->sso
                  -->forum
                  ------>public
                  ------>vendor
                  -->vendor
                  -->index.php
                  -->flarum.php
                  -->delete.php
                  ->.......

                  index.php for login in inside the sso folder and forum folder is also at the same place
                  localhost/sso to load login page and localhost/sso/forum/public is the forum url.

                  I used these parameters as follows
                  FLARUM_HOST=http://localhost/sso/forum/public
                  API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                  ROOT_DOMAIN=localhost

                  Can you point out anything wrong with this configuration? I used the given example login forms with your php library. Still I can't figure out this problem. It always redirects me to localhost intsed of forum public url which I redirected using header("Location: http://localhost/sso/forum/public"); after logging in


                    maicol07 Yes. After getting redirected to localhost I can go to localhost/sso/forum/public folder and I'm logged in.

                      tharuka are you able to check if it gets redirected before the login middleware by echoing something?

                        maicol07 When I echo Done at LoginMiddleware I get an output like below

                        Done
                        ( ! ) Fatal error: Uncaught Laminas\HttpHandlerRunner\Exception\EmitterException: Output has been emitted previously; cannot emit response in C:\wamp64\www\sso\forum\vendor\laminas\laminas-httphandlerrunner\src\Exception\EmitterException.php on line 24
                        ( ! ) Laminas\HttpHandlerRunner\Exception\EmitterException: Output has been emitted previously; cannot emit response in C:\wamp64\www\sso\forum\vendor\laminas\laminas-httphandlerrunner\src\Exception\EmitterException.php on line 24
                        Call Stack

                        Time Memory Function Location

                        1 0.0001 363392 {main}( ) ...\index.php:0
                        2 0.0027 387304 Flarum\Http\Server->listen( ) ...\index.php:26
                        3 0.0822 3048680 Laminas\HttpHandlerRunner\RequestHandlerRunner->run( ) ...\Server.php:44
                        4 0.1072 3877880 Laminas\HttpHandlerRunner\Emitter\SapiEmitter->emit( ) ...\RequestHandlerRunner.php:98
                        5 0.1072 3877880 Laminas\HttpHandlerRunner\Emitter\SapiEmitter->assertNoPreviousOutput( ) ...\SapiEmitter.php:27

                        this line 24 is the echo line which I put. It is getting redirected at the LoginMiddleware. This only happens when a user logged in for the first time after logging out.

                          tharuka ok, what you need to see is the done. Check if the issue occurswhen login middleware redirects. Also try to dump this: echo (string) $request->getUrl();

                          Don't worry about the other errors, they are only related to the forced output you echo

                            maicol07 this dumps http://localhost/ as the echo output and after login in always it redirects to localhost root in login middleware in this return return new RedirectResponse($request->getUri()).

                            So sorry about wasting your valuable time.

                              What about the reverse, flarum on root and various separate wp installs on different subfolders?