Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loopback server port for login #565

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/commands/login.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,29 @@ async function doLogin(argv) {
logger.stderr(err);
}
};
const authCodeParams = oAuth.getOAuthParams({
clientId: argv.clientId,
noRedirect: argv.noRedirect,
});
const dashboardOAuthURL = await startOAuthRequest(authCodeParams);
logger.stdout(`To login, open a browser to:\n${dashboardOAuthURL}`);

const promptLoginUrl = async () => {
const authCodeParams = oAuth.getOAuthParams({
clientId: argv.clientId,
noRedirect: argv.noRedirect,
});
const dashboardOAuthURL = await startOAuthRequest(authCodeParams);
logger.stdout(`To login, open a browser to:\n${dashboardOAuthURL}`);
return dashboardOAuthURL;
};

if (!argv.noRedirect) {
oAuth.server.on("ready", async () => {
const dashboardOAuthURL = await promptLoginUrl();
open(dashboardOAuthURL);
logger.stdout("Waiting for authentication in browser to complete...");
});
oAuth.server.on("auth_code_received", async () => {
await loginWithToken();
});
await oAuth.start();
logger.stdout("Waiting for authentication in browser to complete...");
} else {
await promptLoginUrl();
try {
const userCode = await input({
message: "Authorization Code:",
Expand Down
2 changes: 2 additions & 0 deletions test/commands/login.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ describe("login", function () {

// We start the loopback server
expect(oauthClient.start.called).to.be.true;
expect(oauthClient.start.calledBefore(oauthClient.getOAuthParams)).to.be
.true;
// We open auth url in the browser and prompt user
expect(container.resolve("open").calledWith("http://dashboard-url.com"));
expect(logger.stdout).to.have.been.calledWith(
Expand Down
Loading