Skip to content

enhance(cli): add --user/--pass flags to logseq login for non-interactive auth - #12910

Open
SSamDav wants to merge 5 commits into
logseq:masterfrom
SSamDav:feat/cli-login-user-pass
Open

enhance(cli): add --user/--pass flags to logseq login for non-interactive auth#12910
SSamDav wants to merge 5 commits into
logseq:masterfrom
SSamDav:feat/cli-login-user-pass

Conversation

@SSamDav

@SSamDav SSamDav commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Add --user and --pass flags to logseq login so the CLI can authenticate non-interactively without opening a browser.

Closes logseq/db-test#1017

Motivation

In headless environments (CI, servers, scripts) logseq login currently always opens a browser window to complete the OAuth PKCE flow. This blocks any automated workflow. The Cognito app client already has USER_PASSWORD_AUTH enabled (it is used by the frontend's login-with-username-password-e2e helper), so we can use the same InitiateAuth API to skip the browser entirely.

Usage

# Non-interactive — no browser opened
logseq login --user user@example.com --pass mypassword

# Interactive (unchanged behaviour)
logseq login

Both flags must be supplied together; providing only one is a validation error.

Changes

File Change
deps/common/src/logseq/common/cognito_config.cljs Expose COGNITO-IDP-ENDPOINT constant
src/main/logseq/cli/auth.cljs Add cognito-initiate-auth!, login-with-password!; branch in login!
src/main/logseq/cli/command/auth.cljs Add --user/-u and --pass/-p to the login spec; validate the pair; thread credentials into the action map
src/main/logseq/cli/commands.cljs Pass options to auth-command/build-action
src/test/logseq/cli/auth_test.cljs Unit tests: password path happy path, error path, routing to password vs browser flow
src/test/logseq/cli/command/auth_test.cljs Command-layer tests: flag validation, credential threading into login!

Notes

  • The id-token, access-token, refresh-token, expires-at, sub, email written to auth.json are identical to what the browser flow produces — no downstream changes needed.
  • The CLI app client is a public client (no client secret), so no SECRET_HASH is required.
  • ALLOW_USER_PASSWORD_AUTH is already enabled on the Cognito app client (confirmed by the existing frontend usage).

…tive auth

Add USER_PASSWORD_AUTH support to `logseq login` so it can authenticate
without opening a browser. When --user and --pass are both provided the CLI
calls the Cognito InitiateAuth API directly and writes auth.json exactly as
the browser PKCE flow does. When neither flag is given the existing browser
flow runs unchanged.

- deps/common/cognito_config.cljs: expose COGNITO-IDP-ENDPOINT
- cli/auth.cljs: add cognito-initiate-auth!, login-with-password!, branch in login!
- cli/command/auth.cljs: add --user/-u and --pass/-p spec; validate pair; thread into action
- cli/commands.cljs: pass options to auth-command/build-action
- tests: unit tests for password path, routing, flag validation, credential threading

Closes logseq/db-test#1017
@CLAassistant

CLAassistant commented Jul 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tiensonqin
tiensonqin requested review from RCmerci and Copilot and removed request for RCmerci July 15, 2026 11:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a non-interactive authentication path to the Logseq CLI by introducing --user/-u and --pass/-p flags for logseq login, allowing headless environments to authenticate via Cognito InitiateAuth (USER_PASSWORD_AUTH) without opening a browser.

Changes:

  • Add --user/--pass options to the login command, validate they are provided as a pair, and thread credentials into login!.
  • Implement a password-based login flow in CLI auth that exchanges username/password for Cognito tokens and persists them to auth.json.
  • Add unit tests for command-layer validation/routing and auth-layer password flow behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
deps/common/src/logseq/common/cognito_config.cljs Exposes a shared Cognito IDP endpoint constant for CLI usage.
src/main/logseq/cli/auth.cljs Adds Cognito InitiateAuth password login flow and routes login! based on provided credentials.
src/main/logseq/cli/command/auth.cljs Adds --user/-u and --pass/-p, validates the pair, and passes credentials into cli-auth/login!.
src/main/logseq/cli/commands.cljs Threads parsed options into auth command action building.
src/test/logseq/cli/auth_test.cljs Adds auth-layer tests for password flow persistence, rejection, and routing.
src/test/logseq/cli/command/auth_test.cljs Adds command-layer tests for flag validation and credential threading into login!.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/logseq/cli/auth.cljs Outdated
SSamDav added 2 commits July 16, 2026 09:52
transport/request already throws on non-2xx responses, so the if (= 200 status)
branch and the error-case throw were never reached. Simplify to extract
AuthenticationResult directly from the successful response body.

Also remove the cognito-idp-endpoint private wrapper that only forwarded
to the config constant.
Parse the error :body from the failed InitiateAuth response and use its
message/Message field for the rejection, so users see the actual Cognito
reason (e.g. "Incorrect username or password.") instead of the raw HTTP body.

Add a test covering message extraction from the error body.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/main/logseq/cli/command/auth.cljs Outdated
Comment thread src/main/logseq/cli/auth.cljs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cli): logseq login --user/--pass for non-interactive authentication

3 participants