Skip to content
1 change: 1 addition & 0 deletions .envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export GRAPHQL_HOST='https://api.nes.herodevs.com';
export GRAPHQL_PATH='/graphql';
export EOL_REPORT_URL='https://eol-report-card.apps.herodevs.com/reports';
export ANALYTICS_URL='https://eol-api.herodevs.com/track';
export EOL_LOG_IN_URL='http://eol-report-card.apps.herodevs.com/eol/api/auth/cli-log-in';

# OAuth (for hd auth login)
export OAUTH_CONNECT_URL='';
Expand Down
28 changes: 20 additions & 8 deletions src/commands/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createInterface } from 'node:readline';
import { URL } from 'node:url';
import { Command } from '@oclif/core';
import { ensureUserSetup } from '../../api/user-setup.client.ts';
import { OAUTH_CALLBACK_ERROR_CODES } from '../../config/constants.ts';
import { EOL_LOG_IN_URL, OAUTH_CALLBACK_ERROR_CODES } from '../../config/constants.ts';
import { refreshIdentityFromStoredToken } from '../../service/analytics.svc.ts';
import { persistTokenResponse } from '../../service/auth.svc.ts';
import { getClientId, getRealmUrl } from '../../service/auth-config.svc.ts';
Expand Down Expand Up @@ -40,8 +40,7 @@ export default class AuthLogin extends Command {
`&code_challenge_method=S256` +
`&state=${state}`;

const code = await this.startServerAndAwaitCode(authUrl, state);
const token = await this.exchangeCodeForToken(code, codeVerifier);
const token = await this.startServerAndAwaitToken(authUrl, state, codeVerifier);

try {
await persistTokenResponse(token);
Expand All @@ -65,7 +64,11 @@ export default class AuthLogin extends Command {
this.log('\nLogin completed successfully.');
}

private startServerAndAwaitCode(authUrl: string, expectedState: string): Promise<string> {
private startServerAndAwaitToken(
authUrl: string,
expectedState: string,
codeVerifier: string,
): Promise<TokenResponse> {
return new Promise((resolve, reject) => {
this.server = http.createServer((req, res) => {
if (!req.url) {
Expand Down Expand Up @@ -138,10 +141,19 @@ export default class AuthLogin extends Command {
}

if (code) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Login successful. You can close this window.');
this.stopServer();
resolve(code);
this.exchangeCodeForToken(code, codeVerifier)
.then(async (token) => {
res
.writeHead(302, {
Location: `${EOL_LOG_IN_URL}`,
})
.end();
resolve(token);
})
.catch((error) => reject(error))
.finally(() => {
this.stopServer();
});
} else {
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end('No authorization code returned. Please try again.');
Expand Down
9 changes: 5 additions & 4 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const EOL_REPORT_URL = 'https://apps.herodevs.com/eol/reports';
export const GRAPHQL_HOST = 'https://gateway.prod.apps.herodevs.io';
export const GRAPHQL_PATH = '/graphql';
export const ANALYTICS_URL = 'https://apps.herodevs.com/api/eol/track';
export const EOL_REPORT_URL = process.env.EOL_REPORT_URL || 'https://apps.herodevs.com/eol/reports';
export const GRAPHQL_HOST = process.env.GRAPHQL_HOST || 'https://gateway.prod.apps.herodevs.io';
export const GRAPHQL_PATH = process.env.GRAPHQL_PATH || '/graphql';
export const ANALYTICS_URL = process.env.ANALYTICS_URL || 'https://apps.herodevs.com/api/eol/track';
export const EOL_LOG_IN_URL = process.env.EOL_LOG_IN_URL || 'https://apps.herodevs.com/eol/api/auth/cli-log-in';
export const CONCURRENT_PAGE_REQUESTS = 3;
export const PAGE_SIZE = 500;
export const GIT_OUTPUT_FORMAT = `"${['%h', '%an', '%ad'].join('|')}"`;
Expand Down
Loading