Working 1Password with browser integration

I got 1Password to work on Bazzite, but it should apply to any immutable distro.

I used the 1Password homebrew cask by the ublue team and the default Firefox flatpak.

This works because the ublue homebrew team have put in the needed shims to make it happen automatically, very recently, so thank you to them. And thanks to the people who have dug into this repeatedly so I could put this together.

I am posting here because I found 1Password with browser integration which ended with a sad “nearly but no”. Well great news, it’s now “yep!” No layering needed.

Note: 1Password is required by work, 1Password’s support of the fascist Arch theme means I won’t ever give them money, but I have to use it to continue to have a roof. So I’ll get the browser integration working so I can think about it less :slight_smile:

# run line-by-line, not a real script due to the work around for installing the 1password-gui-linux (which should be fixed in Bazzite at some point soon)

# How to install 1password via homebrew from the ublue repo
brew analytics off
brew update
brew tap ublue-os/tap
brew trust ublue-os/tap
brew install --cask 1password-gui-linux

# !this should be fixed SOONT, but if the above fails because it can't ask you for sudo passwords due to window manager errors, this is the workaround:
d=$(mktemp -d); printf '#!/bin/sh\nunset DISPLAY\nexec echo "YOURPASSWORDHERE"\n' > "$d/ap"; chmod +x "$d/ap"
SUDO_ASKPASS="$d/ap" brew install --cask 1password-gui-linux; rm -rf "$d"

# -> Following adapted from https://www.reddit.com/r/Bazzite/comments/1pwhnkf/how_to_integrate_systemlevel_1password_with/ and homebrew location from https://universal-blue.discourse.group/t/1password-with-browser-integration/10880/10

# Firefox mods (the homebrew thing should come with the fixes needed)
flatpak override --user --talk-name=org.freedesktop.Flatpak org.mozilla.firefox
# You can also add `org.freedesktop.Flatpak` to Session Bus -> Talks in Flatseal for a GUI experience!

# --- Prep the helper script ---
# Create the binary directory
mkdir -p ~/.var/app/org.mozilla.firefox/data/bin

# Create the wrapper script
cat << 'EOF' > ~/.var/app/org.mozilla.firefox/data/bin/1password-wrapper.sh
#!/bin/bash
flatpak-spawn --host /home/linuxbrew/.linuxbrew/bin/1Password-BrowserSupport "$@"
EOF

# Make it executable
chmod +x ~/.var/app/org.mozilla.firefox/data/bin/1password-wrapper.sh

# --- Tell Firefox to use the above script ---
# Create the native-messaging directory
mkdir -p ~/.var/app/org.mozilla.firefox/.mozilla/native-messaging-hosts

# Create the JSON manifest
cat << EOF > ~/.var/app/org.mozilla.firefox/.mozilla/native-messaging-hosts/com.1password.1password.json
{
  "name": "com.1password.1password",
  "description": "1Password BrowserSupport",
  "path": "$HOME/.var/app/org.mozilla.firefox/data/bin/1password-wrapper.sh",
  "type": "stdio",
  "allowed_extensions": [
    "{0a75d802-9aed-41e7-8daa-24c067386e82}",
    "{25fc87fa-4d31-4fee-b5c1-c32a7844c063}",
    "{d634138d-c276-4fc8-924b-40a0ea21d284}"
  ]
}
EOF