Snap programmatic login

snapcraft supports programmatic login via a file or an environment variable. I couldn’t find anything similar for snap.

Is there a way to programmatically login to the Snapstore with snap (bypass password/2FA prompt)?

I thought about running snap login on my local machine and pushing $HOME/.snap/auth.json where I need it but:

  1. I don’t know what is the TTL for this token
  2. This not convenient

Apparently it is possible to use snapcraft export-login to export the store credentials and then use an environment variable to download the snap via the snap CLI:

UBUNTU_STORE_AUTH_DATA_FILENAME=../secret.txt snap download SNAP

Then the snap can be installed with snap install *.snap. I haven’t tried yet.