Skip to content

Commit

Permalink
Merge pull request #22 from sorah/mairu-local-port-env
Browse files Browse the repository at this point in the history
login: $MAIRU_LOCAL_PORT to specify local port
  • Loading branch information
sorah authored Jan 15, 2025
2 parents 16abfbe + 8e7c6c3 commit 82c8621
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0

- `mairu login` uses `$MAIRU_LOCAL_PORT` environment variable for a port number when listening to callback. Takes precedence over a server configuration.

## 0.4.0

- Support OAuth 2.0 Authorization Code Grant without client secret; It's safe because we always use PKCE, and expects your authorization server to enforce PKCE.
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub async fn do_oauth_code(
agent: &mut crate::agent::AgentConn,
server: crate::config::Server,
) -> Result<(), anyhow::Error> {
let (path, local_port, use_localhost) = if let Some(ref aws_sso) = server.aws_sso {
let (path, mut local_port, use_localhost) = if let Some(ref aws_sso) = server.aws_sso {
("/oauth/callback", aws_sso.local_port, false)
} else {
let (_oauth, code_grant) = server.try_oauth_code_grant()?;
Expand All @@ -67,6 +67,12 @@ pub async fn do_oauth_code(
)
};

if let Ok(x) = std::env::var("MAIRU_LOCAL_PORT") {
if let Ok(i) = x.parse() {
local_port = Some(i);
}
}

let (listener, url) =
match crate::oauth_code::bind_tcp_for_callback(path, local_port, use_localhost).await {
Ok(t) => t,
Expand Down

0 comments on commit 82c8621

Please sign in to comment.