+ def get_auth_token(self):
+ """
+ This returns a local authentication token, which is just some
+ random data in "api_auth_token" which must be echoed to API
+ calls.
+
+ Currently only the URI '/magic' for magic-folder status; other
+ endpoints are invited to include this as well, as appropriate.
+ """
+ return self._auth_token
+
+ def _create_or_read_auth_token(self):
+ """
+ This returns the current auth-token data, possibly creating it and
+ writing 'private/api_auth_token' in the process.
+ """
+ fname = os.path.join(self.basedir, 'private', 'api_auth_token')
+ try:
+ with open(fname, 'rb') as f:
+ data = f.read()
+ except (OSError, IOError):
+ log.msg("Creating '%s'." % (fname,))
+ with open(fname, 'wb') as f:
+ data = urlsafe_b64encode(os.urandom(32))
+ f.write(data)
+ return data
+