Repository: lutris/lutris

Issue:
Cannot authenticate GOG with Facebook
**Describe the bug**

A clear and concise description of what the bug is.

This repository isn't for reporting game bugs or game related issues. Feel free to contact us on [Discord](https://discordapp.com/invite/Pnt5CuY), the [Forums](https://forums.lutris.net), or the IRC channel #lutris on freenode.org for that. We'll try and help as best we can.


**Expected behavior**

Authentication succeeds

**Current behavior**

Authentication keeps spinning with no outcome

**Steps to reproduce**

- Search for a GOG game in Lutris
- Install
- Choose Facebook when GOG auth box comes up
- Wait... And nothing happens 

**System information**

```
{
  "comment": "",
  "system": {
    "gpus": [
      {
        "DRIVER": "i915",
        "PCI_ID": "8086:0116",
        "PCI_SUBSYS_ID": "17AA:21CF",
        "PCI_CLASS": "30000",
        "PCI_SLOT_NAME": "0000:00:02.0",
        "MODALIAS": "pci:v00008086d00000116sv000017AAsd000021CFbc03sc00i00"
      }
    ],
    "env": {
      "GJS_DEBUG_TOPICS": "JS ERROR;JS LOG",
      "USER": "anne",
      "SSH_AGENT_PID": "1471",
      "XDG_SESSION_TYPE": "x11",
      "SHLVL": "0",
      "HOME": "/home/anne",
      "QT4_IM_MODULE": "ibus",
      "DESKTOP_SESSION": "ubuntu",
      "GIO_LAUNCHED_DESKTOP_FILE": "/home/anne/.local/share/applications/net.lutris.origin-1.desktop",
      "GTK_MODULES": "gail:atk-bridge",
      "GNOME_SHELL_SESSION_MODE": "ubuntu",
      "MANAGERPID": "1281",
      "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus",
      "GIO_LAUNCHED_DESKTOP_FILE_PID": "1990",
      "IM_CONFIG_PHASE": "1",
      "LOGNAME": "anne",
      "GTK_IM_MODULE": "ibus",
      "_": "/usr/bin/dbus-update-activation-environment",
      "JOURNAL_STREAM": "9:35391",
      "XDG_SESSION_CLASS": "user",
      "USERNAME": "anne",
      "GNOME_DESKTOP_SESSION_ID": "this-is-deprecated",
      "WINDOWPATH": "2",
      "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
      "SESSION_MANAGER": "local/anne-ThinkPad-T520:@/tmp/.ICE-unix/1559,unix/anne-ThinkPad-T520:/tmp/.ICE-unix/1559",
      "INVOCATION_ID": "078b401f17be48e9a3850b9ab224aa66",
      "XDG_RUNTIME_DIR": "/run/user/1000",
      "XDG_MENU_PREFIX": "gnome-",
      "DISPLAY": ":0",
      "LANG": "da_DK.UTF-8",
      "XDG_CURRENT_DESKTOP": "ubuntu:GNOME",
      "XAUTHORITY": "/run/user/1000/gdm/Xauthority",
      "XDG_SESSION_DESKTOP": "ubuntu",
      "XMODIFIERS": "@im=ibus",
      "SSH_AUTH_SOCK": "/run/user/1000/keyring/ssh",
      "SHELL": "/bin/bash",
      "QT_ACCESSIBILITY": "1",
      "GDMSESSION": "ubuntu",
      "GPG_AGENT_INFO": "/run/user/1000/gnupg/S.gpg-agent:0:1",
      "GJS_DEBUG_OUTPUT": "stderr",
      "QT_IM_MODULE": "ibus",
      "PWD": "/home/anne",
      "XDG_DATA_DIRS": "/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop",
      "CLUTTER_IM_MODULE": "ibus",
      "XDG_CONFIG_DIRS": "/etc/xdg/xdg-ubuntu:/etc/xdg"
    },
    "missing_libs": {
      "OPENGL": [
        [],
        []
      ],
      "VULKAN": [
        [],
        []
      ],
      "WINE": [
        [],
        []
      ],
      "GAMEMODE": [
        [
          "libgamemodeauto.so"
        ],
        [
          "libgamemodeauto.so"
        ]
      ]
    },
    "cpus": [
      {
        "processor": "0",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "42",
        "model name": "Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz",
        "stepping": "7",
        "microcode": "0x2f",
        "cpu MHz": "998.672",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "0",
        "cpu cores": "2",
        "apicid": "0",
        "initial apicid": "0",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "13",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit",
        "bogomips": "4585.42",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "36 bits physical, 48 bits virtual",
        "power management": ""
      },
      {
        "processor": "1",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "42",
        "model name": "Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz",
        "stepping": "7",
        "microcode": "0x2f",
        "cpu MHz": "960.782",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "0",
        "cpu cores": "2",
        "apicid": "1",
        "initial apicid": "1",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "13",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit",
        "bogomips": "4585.42",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "36 bits physical, 48 bits virtual",
        "power management": ""
      },
      {
        "processor": "2",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "42",
        "model name": "Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz",
        "stepping": "7",
        "microcode": "0x2f",
        "cpu MHz": "1039.331",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "1",
        "cpu cores": "2",
        "apicid": "2",
        "initial apicid": "2",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "13",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit",
        "bogomips": "4585.42",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "36 bits physical, 48 bits virtual",
        "power management": ""
      },
      {
        "processor": "3",
        "vendor_id": "GenuineIntel",
        "cpu family": "6",
        "model": "42",
        "model name": "Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz",
        "stepping": "7",
        "microcode": "0x2f",
        "cpu MHz": "1087.512",
        "cache size": "3072 KB",
        "physical id": "0",
        "siblings": "4",
        "core id": "1",
        "cpu cores": "2",
        "apicid": "3",
        "initial apicid": "3",
        "fpu": "yes",
        "fpu_exception": "yes",
        "cpuid level": "13",
        "wp": "yes",
        "flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm ida arat pln pts md_clear flush_l1d",
        "bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit",
        "bogomips": "4585.42",
        "clflush size": "64",
        "cache_alignment": "64",
        "address sizes": "36 bits physical, 48 bits virtual",
        "power management": ""
      }
    ],
    "drives": [
      {
        "name": "sda",
        "fstype": null,
        "label": null,
        "uuid": null,
        "fsavail": null,
        "fsuse%": null,
        "mountpoint": null,
        "children": [
          {
            "name": "sda1",
            "fstype": "vfat",
            "label": null,
            "uuid": "8482-E8CB",
            "fsavail": "511M",
            "fsuse%": "0%",
            "mountpoint": "/boot/efi"
          },
          {
            "name": "sda2",
            "fstype": null,
            "label": null,
            "uuid": null,
            "fsavail": null,
            "fsuse%": null,
            "mountpoint": null
          },
          {
            "name": "sda5",
            "fstype": "ext4",
            "label": null,
            "uuid": "aaea2613-8d52-4ee6-bec2-caf557cbfa5a",
            "fsavail": "32,1G",
            "fsuse%": "67%",
            "mountpoint": "/"
          }
        ]
      },
      {
        "name": "sr0",
        "fstype": null,
        "label": null,
        "uuid": null,
        "fsavail": null,
        "fsuse%": null,
        "mountpoint": null
      }
    ],
    "ram": {
      "MemTotal": "3801192",
      "MemFree": "134344",
      "MemAvailable": "735464",
      "Buffers": "33136",
      "Cached": "1084604",
      "SwapCached": "14548",
      "Active": "2155316",
      "Inactive": "1104212",
      "Active(anon)": "1691872",
      "Inactive(anon)": "807644",
      "Active(file)": "463444",
      "Inactive(file)": "296568",
      "Unevictable": "98000",
      "Mlocked": "16",
      "SwapTotal": "2097148",
      "SwapFree": "1919228",
      "Dirty": "1276",
      "Writeback": "0",
      "AnonPages": "2231828",
      "Mapped": "549120",
      "Shmem": "357824",
      "KReclaimable": "86340",
      "Slab": "218060",
      "SReclaimable": "86340",
      "SUnreclaim": "131720",
      "KernelStack": "17232",
      "PageTables": "28896",
      "NFS_Unstable": "0",
      "Bounce": "0",
      "WritebackTmp": "0",
      "CommitLimit": "3997744",
      "Committed_AS": "8386972",
      "VmallocTotal": "34359738367",
      "VmallocUsed": "31416",
      "VmallocChunk": "0",
      "Percpu": "5408",
      "HardwareCorrupted": "0",
      "AnonHugePages": "0",
      "ShmemHugePages": "0",
      "ShmemPmdMapped": "0",
      "FileHugePages": "0",
      "FilePmdMapped": "0",
      "CmaTotal": "0",
      "CmaFree": "0",
      "HugePages_Total": "0",
      "HugePages_Free": "0",
      "HugePages_Rsvd": "0",
      "HugePages_Surp": "0",
      "Hugepagesize": "2048",
      "Hugetlb": "0",
      "DirectMap4k": "239232",
      "DirectMap2M": "3725312"
    },
    "dist": [
      "Ubuntu",
      "20.04",
      "focal"
    ],
    "arch": "x86_64",
    "kernel": "5.4.0-26-generic",
    "glxinfo": {
      "opengl_core_profile_profile_mask": "core profile",
      "opengl_vendor": "Intel Open Source Technology Center",
      "opengl_context_flags": "(none)",
      "display": ":0",
      "opengl_renderer": "Mesa DRI Intel(R) HD Graphics 3000 (SNB GT2)",
      "opengl_core_profile_version": "3.3 (Core Profile) Mesa 20.0.4",
      "opengl_core_profile_context_flags": "(none)",
      "opengl_version": "3.0 Mesa 20.0.4",
      "screen": "0",
      "opengl_shading_language_version": "1.30",
      "opengl_es_profile_shading_language_version": "OpenGL ES GLSL ES 3.00",
      "opengl_core_profile_shading_language_version": "3.30",
      "opengl_es_profile_version": "OpenGL ES 3.0 Mesa 20.0.4",
      "name_of_display": ":0",
      "direct_rendering": "Yes"
    }
  }
}
```

**Screenshots**
![Skærmbillede fra 2020-04-25 10-22-04](https://user-images.githubusercontent.com/2781949/80275457-9b54a200-86e1-11ea-88d0-989195178a08.png)


If applicable, add screenshots to help explain your problem.



Discussion:
Could you please try again, but this time run `lutris -d` in the terminal and then upload the terminal output? That will help us track down what's happening.
It seems I cannot do that - when I do it, Lutris will startup and nothing else happens in terminal:

![Skærmbillede fra 2020-05-03 11-53-36](https://user-images.githubusercontent.com/2781949/80911151-e2234700-8d34-11ea-8771-ff418e300608.png)

If you run lutris on the command line and there is already an instance running, it will show the window for the existing instance and then exit. Try closing Lutris and then running `lutris -d`, then try to authenticate GOG with Facebook.
Here is the output from lutris -d - apparently it was not closed correctly when I tried the other times - thanks @xordspar0 
When clicking on the Login with Facebook-button nothing happens in terminal

```
anne@anne-ThinkPad-T520:~$ lutris -d
INFO     2020-05-04 15:10:14,142 [application.do_command_line:245]:Running Lutris 0.5.6
INFO     2020-05-04 15:10:14,143 [startup.check_driver:62]:Using Intel Open Source Technology Center
INFO     2020-05-04 15:10:14,143 [startup.check_driver:64]:Running Mesa driver 20.0.4 on Mesa DRI Intel(R) HD Graphics 3000 (SNB GT2) (0x116)
INFO     2020-05-04 15:10:14,144 [startup.check_driver:77]:GPU: 8086:0116 17AA:21CF using i915 drivers
INFO     2020-05-04 15:10:14,226 [startup.check_vulkan:134]:Vulkan is not available or your system isn't Vulkan capable
INFO     2020-05-04 15:10:14,227 [dxvk.get_dxvk_versions:22]:Updating DXVK versions
DEBUG    2020-05-04 15:10:14,545 [http.get:65]:GET https://lutris.net/api/runtime
INFO     2020-05-04 15:10:14,547 [lutriswindow.toggle_connection:642]:Connected to lutris.net as anne
DEBUG    2020-05-04 15:10:14,548 [http.get:65]:GET https://lutris.net/api/games/library/anne
DEBUG    2020-05-04 15:10:22,966 [interpreter.fetch_script:51]:Fetching installer https://lutris.net/api/installers/jazz-jackrabbit-2
DEBUG    2020-05-04 15:10:22,967 [http.get:65]:GET https://lutris.net/api/installers/jazz-jackrabbit-2
DEBUG    2020-05-04 15:10:27,260 [interpreter.check_runner_install:478]:Required runners: [<lutris.runners.wine.wine object at 0x7fa6480fedc0>]
INFO     2020-05-04 15:10:27,261 [runner.get_runner_version:290]:Getting runner information for wine
DEBUG    2020-05-04 15:10:27,261 [http.get:65]:GET https://lutris.net/api/runners/wine
DEBUG    2020-05-04 15:10:27,380 [interpreter.check_runner_install:494]:Default wine version is lutris-5.6-2
INFO     2020-05-04 15:10:27,394 [gog.get_gog_download_links:300]:You are not connected to GOG
DEBUG    2020-05-04 15:10:27,395 [gog.connect:286]:Connecting to GOG
```
Ok, thanks for being persistent and trying again.

Also, I just realized that anyone can work this issue, even without a GOG or Facebook account, since it happens before typing in any usernames or passwords. I can reproduce this. :smile: 
>  even without a GOG or Facebook account

Unfortunately, one will need a Facebook account to test this thoroughly. I have taken a look, and this is happening because when you click on "Continue with Facebook", the GOG page opens up a new browser window/tab for the Facebook login prompt. Lutris will have to handle this manually, and what is worse is if you use the "Forgot Account" and "Sign up" links from that prompt, it will yet again open another window/tab which Lutris will also need to handle manually.

I have not tested the Humble Bundle auth flow completely, but it seems to work fine because there is no new window/tab behavior there even for "Forgot Account" and "Sign up" links from its Facebook prompt. This issue appears to be something exclusive to the GOG auth flow.

Anyway, I already have some dirty proof-of-concept code for this issue, and so far, I have managed to get GOG account creation via Facebook to this point. This will need more polishing, but at least the root cause is now known. It will just be a matter of implementation.

![gog fb auth](https://user-images.githubusercontent.com/7114869/85306749-862da100-b4e1-11ea-8be5-2c601ecfda26.png)
I added some code to help resolve this issue in https://github.com/lutris/lutris/commit/9c14318b39059613e4ffd98d591d22750f6316a9
Settings for allowing Javascript popups and dev tools have been added and being able to debug this in an inspector makes it a lot easier!

The problem is that Gog opens a Facebook popup, but that popup doesn't actually open. Using the inspector, you can see the call to window.open returning `null` and then causing a reference error.

At this point, I'm not sure what else to do. I've enabled the setting that is supposed to make this work but it doesn't do anything.

@strycore Like I said, I already have some working code for this, but I am still sorting out some UI/UX issues which mostly involve some quirks in `Gtk.Dialog.run()`. While we are on the topic, do you prefer multiple dialogs to handle new windows/tabs, or do you prefer a single dialog with a notebook or something?
Multiple dialogs! Tabs are completely out of the question!

Resolving patch:
diff --git a/lutris/gui/dialogs/__init__.py b/lutris/gui/dialogs/__init__.py
--- a/lutris/gui/dialogs/__init__.py
+++ b/lutris/gui/dialogs/__init__.py
@@ -391,6 +391,7 @@ def __init__(self, service, parent=None):
         self.webview = WebKit2.WebView.new_with_context(self.context)
         self.webview.load_uri(service.login_url)
         self.webview.connect("load-changed", self.on_navigation)
+        self.webview.connect("create", self.on_webview_popup)
         self.vbox.pack_start(self.webview, True, True, 0)
 
         webkit_settings = self.webview.get_settings()
@@ -417,6 +418,51 @@ def on_navigation(self, widget, load_event):
                 self.destroy()
         return True
 
+    def on_webview_popup(self, widget, navigation_action):
+        """Handles web popups created by this dialog's webview"""
+        uri = navigation_action.get_request().get_uri()
+        view = WebKit2.WebView.new_with_related_view(widget)
+        view.load_uri(uri)
+        popup_dialog = WebPopupDialog(view, parent=self)
+        popup_dialog.set_modal(True)
+        popup_dialog.show()
+        return view
+
+
+class WebPopupDialog(Dialog):
+    """Dialog for handling web popups"""
+
+    def __init__(self, webview, parent=None):
+        self.parent = parent
+        super(WebPopupDialog, self).__init__(title=_('Loading...'), parent=parent)
+        self.webview = webview
+        self.webview.connect("ready-to-show", self.on_ready_webview)
+        self.webview.connect("notify::title", self.on_available_webview_title)
+        self.webview.connect("create", self.on_new_webview_popup)
+        self.webview.connect("close", self.on_webview_close)
+        self.vbox.pack_start(self.webview, True, True, 0)
+        self.set_border_width(0)
+        self.set_default_size(390, 500)
+
+    def on_ready_webview(self, webview):
+        self.show_all()
+
+    def on_available_webview_title(self, webview, gparamstring):
+        self.set_title(webview.get_title())
+
+    def on_new_webview_popup(self, webview, navigation_action):
+        """Handles web popups created by this dialog's webview"""
+        uri = navigation_action.get_request().get_uri()
+        view = WebKit2.WebView.new_with_related_view(webview)
+        view.load_uri(uri)
+        dialog = WebPopupDialog(view, parent=self)
+        dialog.set_modal(True)
+        dialog.show()
+        return view
+
+    def on_webview_close(self, webview):
+        self.destroy()
+
 
 class InstallerSourceDialog(Gtk.Dialog):
 


Test patch: