From 73d06c96c53e07f307a24f026351deabb0ac546d Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Mon, 23 Dec 2024 16:33:39 -0800 Subject: [PATCH 01/12] =?UTF-8?q?test:=20=F0=9F=92=8D=20test=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 4 ++++ .../controllers/scopes/scope/authenticate/method/index.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index a3cdafabd8..fb36cd76c3 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -99,6 +99,10 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { // The `attributes` field exists on the Go side for its convenience but is // unnecessary here. Object.assign(data, data.attributes); + console.log('NormalizeData function ---------------------'); + console.log(data); + console.log(username); + console.log('---------------------------------------------'); // Add booleans indicated the scope type data.isGlobal = data?.scope?.type === 'global'; data.isOrg = data?.scope?.type === 'org'; diff --git a/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js b/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js index de28152b38..c8ab480f82 100644 --- a/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js +++ b/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js @@ -30,7 +30,12 @@ export default class ScopesScopeAuthenticateMethodIndexController extends Contro // TODO: delegate this call from the session service so that we don't have // to look up the authenticator directly const json = await oidc.startAuthentication(options); + console.log('startOIDC -----------------------------'); + console.log(json); + await this.openExternalOIDCFlow(json.attributes.auth_url); + console.log('open external done!'); + console.log('------------------------------------'); } /** @@ -75,6 +80,7 @@ export default class ScopesScopeAuthenticateMethodIndexController extends Contro authMethod, }); this.router.transitionTo('scopes.scope.authenticate.method.oidc'); + console.log('route transition called'); break; } } From b14a746044178a72a05930f2b0e7ab4ff9e58090 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 12:06:15 -0800 Subject: [PATCH 02/12] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20waitForP?= =?UTF-8?q?romise=20use?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 10 ++++------ addons/auth/addon/authenticators/oidc.js | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index fb36cd76c3..213fc81b84 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -60,12 +60,10 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { const tokenValidationURL = this.buildTokenValidationEndpointURL(tokenID); // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. - const response = await waitForPromise( - fetch(tokenValidationURL, { - method: 'get', - headers: { Authorization: `Bearer ${token}` }, - }), - ); + const response = await fetch(tokenValidationURL, { + method: 'get', + headers: { Authorization: `Bearer ${token}` }, + }); // 401 and 404 responses mean the token is invalid, whereas other types of // error responses do not tell us about the validity of the token. if (response.status === 401 || response.status === 404) return reject(); diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index dc1063d5e4..0363127b68 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -6,7 +6,7 @@ import BaseAuthenticator from './base'; import { inject as service } from '@ember/service'; import { reject } from 'rsvp'; -import { waitForPromise } from '@ember/test-waiters'; +// import { waitForPromise } from '@ember/test-waiters'; /** * The OIDC base authenticator encapsulates the multistep OIDC flow. @@ -49,7 +49,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { const body = JSON.stringify({ command: 'start' }); // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. - const response = await waitForPromise(fetch(url, { method: 'post', body })); + const response = await fetch(url, { method: 'post', body }); const json = await response.json(); if (response.status < 400) { // Store meta about the pending OIDC flow @@ -96,7 +96,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { }, }); // Fetch the endpoint and get the response JSON - const response = await waitForPromise(fetch(url, { method: 'post', body })); + const response = await fetch(url, { method: 'post', body }); if (response.status === 202) { // The token isn't ready yet, keep trying. return false; From 434cf852fe993ffaf484b843fb4a4404cb2482d5 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 12:29:39 -0800 Subject: [PATCH 03/12] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20all=20ot?= =?UTF-8?q?her=20waitforpromise=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 16 +++++++--------- addons/auth/addon/authenticators/password.js | 6 ++---- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index 213fc81b84..c9832550dc 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -5,7 +5,7 @@ import SimpleAuthBaseAuthenticator from 'ember-simple-auth/authenticators/base'; import { resolve, reject } from 'rsvp'; -import { waitForPromise } from '@ember/test-waiters'; +// import { waitForPromise } from '@ember/test-waiters'; /** * Encapsulates common authenticator functionality. @@ -119,14 +119,12 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { async invalidate(options) { const { token } = options; const deauthEndpointURL = this.buildDeauthEndpointURL(options); - await waitForPromise( - fetch(deauthEndpointURL, { - method: 'delete', - headers: { Authorization: `Bearer ${token}` }, - }).catch(() => { - /* no op */ - }), - ); + await fetch(deauthEndpointURL, { + method: 'delete', + headers: { Authorization: `Bearer ${token}` }, + }).catch(() => { + /* no op */ + }); return super.invalidate(...arguments); } } diff --git a/addons/auth/addon/authenticators/password.js b/addons/auth/addon/authenticators/password.js index c584185d04..3e799d2f43 100644 --- a/addons/auth/addon/authenticators/password.js +++ b/addons/auth/addon/authenticators/password.js @@ -5,7 +5,7 @@ import BaseAuthenticator from './base'; import { resolve, reject } from 'rsvp'; -import { waitForPromise } from '@ember/test-waiters'; +// import { waitForPromise } from '@ember/test-waiters'; /** * @@ -68,9 +68,7 @@ export default class PasswordAuthenticator extends BaseAuthenticator { const authEndpointURL = this.buildAuthEndpointURL(options); // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. - const response = await waitForPromise( - fetch(authEndpointURL, { method: 'post', body }), - ); + const response = await fetch(authEndpointURL, { method: 'post', body }); const json = await response.json(); return response.status < 400 ? resolve(this.normalizeData(json, login_name)) From 81a04db0a6dcf46709cc9b3189753ded63ebf228 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 13:07:05 -0800 Subject: [PATCH 04/12] =?UTF-8?q?test:=20=F0=9F=92=8D=20turn=20down=20poll?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js b/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js index 0c50090f5d..4b784d19d0 100644 --- a/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js +++ b/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js @@ -31,7 +31,7 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route { return oidc.attemptFetchToken({ scope, authMethod }); } - @runEvery(POLL_TIMEOUT_SECONDS * 1000) + @runEvery(POLL_TIMEOUT_SECONDS * 10000000) poller() { this.refresh(); } From 318b280a839e523d2cff71b5eeb8bb94d4ef2872 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 14:18:19 -0800 Subject: [PATCH 05/12] =?UTF-8?q?test:=20=F0=9F=92=8D=20use=20.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/oidc.js | 3 ++- ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index 0363127b68..dd2f25f2db 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -97,13 +97,14 @@ export default class OIDCAuthenticator extends BaseAuthenticator { }); // Fetch the endpoint and get the response JSON const response = await fetch(url, { method: 'post', body }); + const json = await response.json(); if (response.status === 202) { // The token isn't ready yet, keep trying. return false; } else if (response.status < 400) { // Response was successful, meaning a token was obtained. // Authenticate with the session service using the response JSON. - const json = await response.json(); + // const json = await response.json(); await this.session.authenticate('authenticator:oidc', json); return true; } else { diff --git a/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js b/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js index 4b784d19d0..0c50090f5d 100644 --- a/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js +++ b/ui/desktop/app/routes/scopes/scope/authenticate/method/oidc.js @@ -31,7 +31,7 @@ export default class ScopesScopeAuthenticateMethodOidcRoute extends Route { return oidc.attemptFetchToken({ scope, authMethod }); } - @runEvery(POLL_TIMEOUT_SECONDS * 10000000) + @runEvery(POLL_TIMEOUT_SECONDS * 1000) poller() { this.refresh(); } From 9cb892e1db3ee2c36db09bc4ee303b7166322ede Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 16:17:11 -0800 Subject: [PATCH 06/12] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20add=20waitForP?= =?UTF-8?q?romise=20back=20in=20&=20consume=20response=20body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 32 +++++++++++++------- addons/auth/addon/authenticators/oidc.js | 11 ++++--- addons/auth/addon/authenticators/password.js | 6 ++-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index c9832550dc..5f85cfc03e 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -5,7 +5,7 @@ import SimpleAuthBaseAuthenticator from 'ember-simple-auth/authenticators/base'; import { resolve, reject } from 'rsvp'; -// import { waitForPromise } from '@ember/test-waiters'; +import { waitForPromise } from '@ember/test-waiters'; /** * Encapsulates common authenticator functionality. @@ -60,10 +60,16 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { const tokenValidationURL = this.buildTokenValidationEndpointURL(tokenID); // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. - const response = await fetch(tokenValidationURL, { - method: 'get', - headers: { Authorization: `Bearer ${token}` }, - }); + const response = await waitForPromise( + fetch(tokenValidationURL, { + method: 'get', + headers: { Authorization: `Bearer ${token}` }, + }), + ); + console.log('TESTING VALIDATE TOKEN!!'); + // Note: Always consume response object in order to avoid memory leaks. + // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. + await response.json(); // 401 and 404 responses mean the token is invalid, whereas other types of // error responses do not tell us about the validity of the token. if (response.status === 401 || response.status === 404) return reject(); @@ -119,12 +125,16 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { async invalidate(options) { const { token } = options; const deauthEndpointURL = this.buildDeauthEndpointURL(options); - await fetch(deauthEndpointURL, { - method: 'delete', - headers: { Authorization: `Bearer ${token}` }, - }).catch(() => { - /* no op */ - }); + const response = await waitForPromise( + fetch(deauthEndpointURL, { + method: 'delete', + headers: { Authorization: `Bearer ${token}` }, + }).catch(() => { + /* no op */ + }), + ); + await response.json(); + console.log('TESTING LOGGING OUT (invalidate)'); return super.invalidate(...arguments); } } diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index dd2f25f2db..e3b083ba92 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -6,10 +6,10 @@ import BaseAuthenticator from './base'; import { inject as service } from '@ember/service'; import { reject } from 'rsvp'; -// import { waitForPromise } from '@ember/test-waiters'; +import { waitForPromise } from '@ember/test-waiters'; /** - * The OIDC base authenticator encapsulates the multistep OIDC flow. + * The OIDC base authenticator encapsulates the multi-step OIDC flow. * * 1. Start authentication flow: this step is actually a combination of two * sub steps: @@ -49,7 +49,10 @@ export default class OIDCAuthenticator extends BaseAuthenticator { const body = JSON.stringify({ command: 'start' }); // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. - const response = await fetch(url, { method: 'post', body }); + const response = await waitForPromise(fetch(url, { method: 'post', body })); + + // Note: Always consume response object in order to avoid memory leaks. + // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. const json = await response.json(); if (response.status < 400) { // Store meta about the pending OIDC flow @@ -96,7 +99,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { }, }); // Fetch the endpoint and get the response JSON - const response = await fetch(url, { method: 'post', body }); + const response = await waitForPromise(fetch(url, { method: 'post', body })); const json = await response.json(); if (response.status === 202) { // The token isn't ready yet, keep trying. diff --git a/addons/auth/addon/authenticators/password.js b/addons/auth/addon/authenticators/password.js index 3e799d2f43..c584185d04 100644 --- a/addons/auth/addon/authenticators/password.js +++ b/addons/auth/addon/authenticators/password.js @@ -5,7 +5,7 @@ import BaseAuthenticator from './base'; import { resolve, reject } from 'rsvp'; -// import { waitForPromise } from '@ember/test-waiters'; +import { waitForPromise } from '@ember/test-waiters'; /** * @@ -68,7 +68,9 @@ export default class PasswordAuthenticator extends BaseAuthenticator { const authEndpointURL = this.buildAuthEndpointURL(options); // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. - const response = await fetch(authEndpointURL, { method: 'post', body }); + const response = await waitForPromise( + fetch(authEndpointURL, { method: 'post', body }), + ); const json = await response.json(); return response.status < 400 ? resolve(this.normalizeData(json, login_name)) From 916ae0d4c3cef1bfeb2be9a6a49f88d65221072a Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 16:36:42 -0800 Subject: [PATCH 07/12] =?UTF-8?q?test:=20=F0=9F=92=8D=20some=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 10 ++++------ addons/auth/addon/authenticators/oidc.js | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index 5f85cfc03e..73312f7543 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -66,10 +66,8 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { headers: { Authorization: `Bearer ${token}` }, }), ); - console.log('TESTING VALIDATE TOKEN!!'); - // Note: Always consume response object in order to avoid memory leaks. - // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. - await response.json(); + console.log('TESTING VALIDATE TOKEN!!', response); + // 401 and 404 responses mean the token is invalid, whereas other types of // error responses do not tell us about the validity of the token. if (response.status === 401 || response.status === 404) return reject(); @@ -133,8 +131,8 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { /* no op */ }), ); - await response.json(); - console.log('TESTING LOGGING OUT (invalidate)'); + // await response.json(); + console.log('TESTING LOGGING OUT (invalidate)', response); return super.invalidate(...arguments); } } diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index e3b083ba92..6b41be94e9 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -100,7 +100,11 @@ export default class OIDCAuthenticator extends BaseAuthenticator { }); // Fetch the endpoint and get the response JSON const response = await waitForPromise(fetch(url, { method: 'post', body })); + + // Note: Always consume response object in order to avoid memory leaks. + // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. const json = await response.json(); + console.log('attempt fetch token response: ', response); if (response.status === 202) { // The token isn't ready yet, keep trying. return false; From 3716bd6f7bc47701b2cdd53ae2936cfc621fb84a Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 17:11:34 -0800 Subject: [PATCH 08/12] =?UTF-8?q?test:=20=F0=9F=92=8D=20more=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index 73312f7543..dddda83bda 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -66,6 +66,10 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { headers: { Authorization: `Bearer ${token}` }, }), ); + + // Note: Always consume response object in order to avoid memory leaks. + // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. + await response.json(); console.log('TESTING VALIDATE TOKEN!!', response); // 401 and 404 responses mean the token is invalid, whereas other types of @@ -132,7 +136,9 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { }), ); // await response.json(); - console.log('TESTING LOGGING OUT (invalidate)', response); + const contentType = response.headers.get('content-type'); + console.log('TESTING LOGGING OUT (invalidate)', response, contentType); + return super.invalidate(...arguments); } } From 27f3fd23b79fbe433f6b65fc5374fade96cd1838 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Thu, 26 Dec 2024 17:26:15 -0800 Subject: [PATCH 09/12] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20clean-up=20a?= =?UTF-8?q?=20bit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 10 +--------- addons/auth/addon/authenticators/oidc.js | 2 +- .../scopes/scope/authenticate/method/index.js | 6 ------ 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index dddda83bda..2fa65bc572 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -105,10 +105,6 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { // The `attributes` field exists on the Go side for its convenience but is // unnecessary here. Object.assign(data, data.attributes); - console.log('NormalizeData function ---------------------'); - console.log(data); - console.log(username); - console.log('---------------------------------------------'); // Add booleans indicated the scope type data.isGlobal = data?.scope?.type === 'global'; data.isOrg = data?.scope?.type === 'org'; @@ -127,7 +123,7 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { async invalidate(options) { const { token } = options; const deauthEndpointURL = this.buildDeauthEndpointURL(options); - const response = await waitForPromise( + await waitForPromise( fetch(deauthEndpointURL, { method: 'delete', headers: { Authorization: `Bearer ${token}` }, @@ -135,10 +131,6 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { /* no op */ }), ); - // await response.json(); - const contentType = response.headers.get('content-type'); - console.log('TESTING LOGGING OUT (invalidate)', response, contentType); - return super.invalidate(...arguments); } } diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index 6b41be94e9..72f9097c5b 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -104,7 +104,7 @@ export default class OIDCAuthenticator extends BaseAuthenticator { // Note: Always consume response object in order to avoid memory leaks. // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. const json = await response.json(); - console.log('attempt fetch token response: ', response); + if (response.status === 202) { // The token isn't ready yet, keep trying. return false; diff --git a/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js b/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js index c8ab480f82..de28152b38 100644 --- a/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js +++ b/ui/desktop/app/controllers/scopes/scope/authenticate/method/index.js @@ -30,12 +30,7 @@ export default class ScopesScopeAuthenticateMethodIndexController extends Contro // TODO: delegate this call from the session service so that we don't have // to look up the authenticator directly const json = await oidc.startAuthentication(options); - console.log('startOIDC -----------------------------'); - console.log(json); - await this.openExternalOIDCFlow(json.attributes.auth_url); - console.log('open external done!'); - console.log('------------------------------------'); } /** @@ -80,7 +75,6 @@ export default class ScopesScopeAuthenticateMethodIndexController extends Contro authMethod, }); this.router.transitionTo('scopes.scope.authenticate.method.oidc'); - console.log('route transition called'); break; } } From 5c0125e7d8a91fd7024ff6b30098bc02c84b83e4 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Fri, 27 Dec 2024 11:11:38 -0800 Subject: [PATCH 10/12] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20use=20head=20m?= =?UTF-8?q?ethod=20request=20&=20clean=20up=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 10 ++++++---- addons/auth/addon/authenticators/oidc.js | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index 2fa65bc572..1c2c239507 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -58,18 +58,20 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { */ async validateToken(token, tokenID) { const tokenValidationURL = this.buildTokenValidationEndpointURL(tokenID); + // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. const response = await waitForPromise( fetch(tokenValidationURL, { - method: 'get', + method: 'head', headers: { Authorization: `Bearer ${token}` }, }), ); - - // Note: Always consume response object in order to avoid memory leaks. + // Note: HEAD request is made here to avoid dealing with a response body // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. - await response.json(); + // We do not use the undici package but the link informs us that garbage + // collection is undefined when response body is not consumed. + console.log('TESTING VALIDATE TOKEN!!', response); // 401 and 404 responses mean the token is invalid, whereas other types of diff --git a/addons/auth/addon/authenticators/oidc.js b/addons/auth/addon/authenticators/oidc.js index 72f9097c5b..6b38c6c050 100644 --- a/addons/auth/addon/authenticators/oidc.js +++ b/addons/auth/addon/authenticators/oidc.js @@ -50,9 +50,6 @@ export default class OIDCAuthenticator extends BaseAuthenticator { // Note: waitForPromise is needed to provide the necessary integration with @ember/test-helpers // visit https://www.npmjs.com/package/@ember/test-waiters for more info. const response = await waitForPromise(fetch(url, { method: 'post', body })); - - // Note: Always consume response object in order to avoid memory leaks. - // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. const json = await response.json(); if (response.status < 400) { // Store meta about the pending OIDC flow @@ -101,8 +98,10 @@ export default class OIDCAuthenticator extends BaseAuthenticator { // Fetch the endpoint and get the response JSON const response = await waitForPromise(fetch(url, { method: 'post', body })); - // Note: Always consume response object in order to avoid memory leaks. + // Note: Always consume response body in order to avoid memory leaks // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. + // We do not use the undici package but the link informs us that garbage + // collection is undefined when response body is not consumed. const json = await response.json(); if (response.status === 202) { @@ -111,7 +110,6 @@ export default class OIDCAuthenticator extends BaseAuthenticator { } else if (response.status < 400) { // Response was successful, meaning a token was obtained. // Authenticate with the session service using the response JSON. - // const json = await response.json(); await this.session.authenticate('authenticator:oidc', json); return true; } else { From 434a9707695c15d1b88f241ae8fc62beaa394558 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Fri, 27 Dec 2024 11:33:24 -0800 Subject: [PATCH 11/12] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20use=20get=20me?= =?UTF-8?q?thod=20&=20consume=20response=20body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/addon/authenticators/base.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/auth/addon/authenticators/base.js b/addons/auth/addon/authenticators/base.js index 1c2c239507..a48aaaeaca 100644 --- a/addons/auth/addon/authenticators/base.js +++ b/addons/auth/addon/authenticators/base.js @@ -63,16 +63,15 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator { // visit https://www.npmjs.com/package/@ember/test-waiters for more info. const response = await waitForPromise( fetch(tokenValidationURL, { - method: 'head', + method: 'get', headers: { Authorization: `Bearer ${token}` }, }), ); - // Note: HEAD request is made here to avoid dealing with a response body + // Note: Always consume response body in order to avoid memory leaks // visit https://undici.nodejs.org/#/?id=garbage-collection for more info. // We do not use the undici package but the link informs us that garbage // collection is undefined when response body is not consumed. - - console.log('TESTING VALIDATE TOKEN!!', response); + await response.json(); // 401 and 404 responses mean the token is invalid, whereas other types of // error responses do not tell us about the validity of the token. From c269110c2e2673a8d449a8e79c58da6276031379 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez Date: Fri, 27 Dec 2024 11:55:27 -0800 Subject: [PATCH 12/12] =?UTF-8?q?test:=20=F0=9F=92=8D=20fix=20token=20vali?= =?UTF-8?q?dation=20test=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/auth/tests/unit/authenticators/base-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/auth/tests/unit/authenticators/base-test.js b/addons/auth/tests/unit/authenticators/base-test.js index 6bcf988f6c..3a7f2f38c6 100644 --- a/addons/auth/tests/unit/authenticators/base-test.js +++ b/addons/auth/tests/unit/authenticators/base-test.js @@ -52,7 +52,7 @@ module('Unit | Authenticator | base', function (hooks) { const authenticator = this.owner.lookup('authenticator:base'); server.get(authenticator.buildTokenValidationEndpointURL(id), () => { assert.ok(true, 'token validation was requested'); - return [200]; + return [200, {}, '{}']; }); await authenticator.restore(mockData); }); @@ -64,7 +64,7 @@ module('Unit | Authenticator | base', function (hooks) { const authenticator = this.owner.lookup('authenticator:base'); server.get(authenticator.buildTokenValidationEndpointURL(id), () => { assert.ok(true, 'token validation was requested'); - return [401]; + return [401, {}, '{}']; }); try { await authenticator.restore(mockData); @@ -80,7 +80,7 @@ module('Unit | Authenticator | base', function (hooks) { const authenticator = this.owner.lookup('authenticator:base'); server.get(authenticator.buildTokenValidationEndpointURL(id), () => { assert.ok(true, 'token validation was requested'); - return [404]; + return [404, {}, '{}']; }); try { await authenticator.restore(mockData);