ltratt / pizauth

Command-line OAuth2 authentication daemon
https://tratt.net/laurie/src/pizauth/
Other
154 stars 4 forks source link

Instructions on running pizauth as a launch agent on osx #38

Open ldangelo opened 1 week ago

ldangelo commented 1 week ago

Took me a while to figure this out so I thought I would share here. I was trying to get pizauth to run as a user agent under osx. When I would run from the shell it worked fine, but when launched as an agent it did not. After looking at the output of 'pizauth info' I realized it was using different cache directories depending on how it was launched.

While running as a launch agent I needed to set two environment variables for it to work properly:

HOME=/Users/myuser XDG_DATA_HOME=$HOME/.local/share

Hope this saves someone a little time in the future.

Here is my pizauth.daemon.plist:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

EnvironmentVariables HOME /Users/ldangelo XDG_DATA_HOME /Users/ldangelo/.local/share KeepAlive Label pizauth.daemon ProcessType Standard ProgramArguments /usr/local/bin/pizauth server -c /Users/ldangelo/.config/pizauth.conf -d -vvvvv StandardErrorPath /tmp/pizauth.out
ltratt commented 1 week ago

Is $HOME not set by default on OS X? That would surprise me a bit! I can well imagine that $XDG_DATA_HOME isn't set, though. In theory -- assuming I got the code right! -- you should only need to set one of $HOME or $XDG_DATA_HOME. Do you have to set both or is one of them sufficient?

ldangelo commented 1 week ago

Full disclosure, I'm using nix-darwin to configure the agent. If I don't set $HOME I get an error saying it's not set.

ltratt commented 1 week ago

I must confess to ignorance of nix-darwin and its possible effects! I know earlier versions of pizauth worked "raw" on OS X, but things could have changed since then. If you use pizauth without nix-darwin, does it work as expected without fiddling with environment variables?

[I must admit that I don't know what a Unix process/system should do if $HOME isn't set. I'd always assumed it was set all the time...]

ldangelo commented 1 week ago

from the command line it works perfectly... It's when I try and launch it as an agent that it appears HOME is not set... Also, even with HOME set if I don't set XDG_DATA_HOME it uses a different cache directory than the command line. So pizauth status says it's not running...

-LeoD

ltratt commented 1 week ago

Aha, I think there are two separate things going on:

  1. On your machine / OS, there are situations where a daemon can be run without $HOME being set (and you're under an OS where $XDG_DATA_HOME isn't a thing).
  2. $XDG_DATA_HOME has different semantics than $HOME: it's not the user's home directory but a directory where people can plonk data into directly. [e.g. on my machine I might set $XDG_DATA_HOME to /home/ltratt/.cache.]

In retrospect, I think it would be better if pizauth told you to define $HOME and didn't mention $XDG_DATA_HOME as the latter is poorly understood (see below for why I got it wrong too!). Maybe pizauth can work out your $HOME directory even if the environment variable isn't set (e.g. reading /etc/passwd)? It would need someone to work out if that would help someone in your situation -- I'd happily accept a PR which improves the situation.

Having now read the XDG spec more carefully, pizauth should actually be using $XDG_RUNTIME_DIR. That's something I wasn't expecting, but is a useful outcome anyway!

ltratt commented 1 week ago

https://github.com/ltratt/pizauth/commit/c9ea6170c8c89375cef4855f10dbd31ffd12b408 changes where pizauth places its control socket. This should also, I hope, solve the problem of $HOME not being set (assuming that you have specified -c to tell pizauth where your config file is set). Please give this a shot, though note that you'll have to shutdown your existing pizauth server and run one based on this new commit.

ltratt commented 5 days ago

@ldangelo Does the new commit help things, in the sense that you no longer need to set $HOME or any $XDG variables?