Add authentication flow for write operations
Improve authentication handling; add tests