diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-27 10:07:30 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-27 14:24:57 +0000 |
| commit | 2c48e37f8341e0d207dd3260c439a0729464b03d (patch) | |
| tree | e3188f6ff8b90e2b883335d95750fe69e16df361 /src/bin/ngit | |
| parent | 436b707b2bdecb995bbdb374a029714c9f4c5159 (diff) | |
feat: add --bunker-url to account login for non-interactive use
allows non-interactive bunker:// URL login without requiring --nsec,
by connecting to the remote signer and saving credentials to git config
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/sub_commands/login.rs | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index 3acfb66..29152ed 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs | |||
| @@ -11,7 +11,7 @@ use crate::{ | |||
| 11 | cli::{Cli, extract_signer_cli_arguments}, | 11 | cli::{Cli, extract_signer_cli_arguments}, |
| 12 | client::{Client, Connect}, | 12 | client::{Client, Connect}, |
| 13 | git::Repo, | 13 | git::Repo, |
| 14 | login::fresh::fresh_login_or_signup, | 14 | login::fresh::{fresh_login_or_signup, login_with_bunker_url}, |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | #[derive(clap::Args)] | 17 | #[derive(clap::Args)] |
| @@ -27,22 +27,31 @@ pub struct SubCommandArgs { | |||
| 27 | /// signer relay for nostrconnect (can be used multiple times) | 27 | /// signer relay for nostrconnect (can be used multiple times) |
| 28 | #[arg(long = "signer-relay")] | 28 | #[arg(long = "signer-relay")] |
| 29 | signer_relays: Vec<String>, | 29 | signer_relays: Vec<String>, |
| 30 | |||
| 31 | /// bunker:// URL from signer app for non-interactive remote signer login | ||
| 32 | #[arg(long = "bunker-url")] | ||
| 33 | bunker_url: Option<String>, | ||
| 30 | } | 34 | } |
| 31 | 35 | ||
| 32 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | 36 | pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { |
| 33 | // Early validation: check if we have required parameters in non-interactive | 37 | // Early validation: check if we have required parameters in non-interactive |
| 34 | // mode | 38 | // mode |
| 35 | let signer_info = extract_signer_cli_arguments(args)?; | 39 | let signer_info = extract_signer_cli_arguments(args)?; |
| 36 | if Interactor::is_non_interactive() && signer_info.is_none() { | 40 | if Interactor::is_non_interactive() |
| 41 | && signer_info.is_none() | ||
| 42 | && command_args.bunker_url.is_none() | ||
| 43 | { | ||
| 37 | use ngit::cli_interactor::cli_error; | 44 | use ngit::cli_interactor::cli_error; |
| 38 | return Err(cli_error( | 45 | return Err(cli_error( |
| 39 | "requires --nsec or --interactive", | 46 | "requires --nsec, --bunker-url, or --interactive", |
| 40 | &[ | 47 | &[ |
| 41 | ("--nsec <key>", "provide secret key (nsec or hex)"), | 48 | ("--nsec <key>", "provide secret key (nsec or hex)"), |
| 42 | ("--interactive", "for nostr connect or bunker login"), | 49 | ("--bunker-url <url>", "bunker:// URL from signer app"), |
| 50 | ("--interactive", "for interactive nostr connect login"), | ||
| 43 | ], | 51 | ], |
| 44 | &[ | 52 | &[ |
| 45 | "ngit account login --nsec <your-nsec>", | 53 | "ngit account login --nsec <your-nsec>", |
| 54 | "ngit account login --bunker-url <bunker-url>", | ||
| 46 | "ngit account create", | 55 | "ngit account create", |
| 47 | ], | 56 | ], |
| 48 | )); | 57 | )); |
| @@ -61,14 +70,25 @@ pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { | |||
| 61 | 70 | ||
| 62 | let (logged_out, log_in_locally_only) = logout(git_repo.as_ref(), command_args.local).await?; | 71 | let (logged_out, log_in_locally_only) = logout(git_repo.as_ref(), command_args.local).await?; |
| 63 | if logged_out || log_in_locally_only { | 72 | if logged_out || log_in_locally_only { |
| 64 | fresh_login_or_signup( | 73 | if let Some(bunker_url) = &command_args.bunker_url { |
| 65 | &git_repo.as_ref(), | 74 | login_with_bunker_url( |
| 66 | client.as_ref(), | 75 | &git_repo.as_ref(), |
| 67 | signer_info, | 76 | client.as_ref(), |
| 68 | log_in_locally_only || command_args.local, | 77 | bunker_url, |
| 69 | &command_args.signer_relays, | 78 | log_in_locally_only || command_args.local, |
| 70 | ) | 79 | &command_args.signer_relays, |
| 71 | .await?; | 80 | ) |
| 81 | .await?; | ||
| 82 | } else { | ||
| 83 | fresh_login_or_signup( | ||
| 84 | &git_repo.as_ref(), | ||
| 85 | client.as_ref(), | ||
| 86 | signer_info, | ||
| 87 | log_in_locally_only || command_args.local, | ||
| 88 | &command_args.signer_relays, | ||
| 89 | ) | ||
| 90 | .await?; | ||
| 91 | } | ||
| 72 | } | 92 | } |
| 73 | 93 | ||
| 74 | // If not offline, disconnect the client | 94 | // If not offline, disconnect the client |