diff --git a/e2e/autoscript-apps/src/authn-oauth/autoscript.ts b/e2e/autoscript-apps/src/authn-oauth/autoscript.ts index 1b4752185..3d82976e6 100644 --- a/e2e/autoscript-apps/src/authn-oauth/autoscript.ts +++ b/e2e/autoscript-apps/src/authn-oauth/autoscript.ts @@ -88,6 +88,7 @@ function autoscript() { } else { throw new Error('Session_Error'); } + console.log(tokens.rawResponse); return tokens; }), rxDelay(delay), diff --git a/e2e/autoscript-suites/src/suites/authn-oauth.lc.test.ts b/e2e/autoscript-suites/src/suites/authn-oauth.lc.test.ts index 14006141a..087643bda 100644 --- a/e2e/autoscript-suites/src/suites/authn-oauth.lc.test.ts +++ b/e2e/autoscript-suites/src/suites/authn-oauth.lc.test.ts @@ -15,14 +15,28 @@ test.describe('Test OAuth login flow', () => { test(`should login successfully and then log out with`, async ({ page, browserName }) => { const { messageArray, networkArray } = await setupAndGo(page, browserName, 'authn-oauth/'); + let rawResponse = ''; + // Test assertions // Test log messages - expect(messageArray.includes('OAuth login successful')).toBe(true); - expect(messageArray.includes('Logout successful')).toBe(true); - expect(messageArray.includes('Calling authorize endpoint')).toBe(true); - expect(messageArray.includes('Calling access token exchange endpoint')).toBe(true); - expect(messageArray.includes('Get user info from OAuth endpoint')).toBe(true); - expect(messageArray.includes('New OAuth tokens retrieved')).toBe(true); + expect(messageArray.includes('OAuth login successful'), 'oauth success').toBe(true); + expect(messageArray.includes('Logout successful'), 'logout success').toBe(true); + expect(messageArray.includes('Calling authorize endpoint'), 'call /authorize').toBe(true); + expect( + messageArray.includes('Calling access token exchange endpoint'), + 'call /access_token', + ).toBe(true); + expect(messageArray.includes('Get user info from OAuth endpoint'), 'call /userinfo').toBe(true); + expect(messageArray.includes('New OAuth tokens retrieved'), 'tokens received').toBe(true); + + // Test rawResponse on token object + messageArray.forEach((message) => { + if (message.includes('access_token')) { + rawResponse = message; + } + }); + + expect(rawResponse.includes('access_token')).toBe(true); // Test network requests // Make sure revoke request is made twice, one for force renew and one for logout diff --git a/e2e/autoscript-suites/src/suites/authz-txn-basic-json.test.ts b/e2e/autoscript-suites/src/suites/authz-txn-basic-json.test.ts index 003be7790..aed8820b6 100644 --- a/e2e/autoscript-suites/src/suites/authz-txn-basic-json.test.ts +++ b/e2e/autoscript-suites/src/suites/authz-txn-basic-json.test.ts @@ -16,9 +16,21 @@ test.describe('Test Transaction Authorization flow using JSON response', () => { const { messageArray } = await setupAndGo(page, browserName, 'authz-txn-basic-json/'); // Test assertions - expect(messageArray.includes('IG resource requires additional authorization')).toBe(true); - expect(messageArray.includes('Request to IG resource successfully responded')).toBe(true); - expect(messageArray.includes('Starting authentication with composite advice')).toBe(true); - expect(messageArray.includes('Continuing authentication with composite advice')).toBe(true); + expect( + messageArray.includes('IG resource requires additional authorization'), + 'add. auth required', + ).toBe(true); + expect( + messageArray.includes('Request to IG resource successfully responded'), + 'successful response', + ).toBe(true); + expect( + messageArray.includes('Starting authentication with composite advice'), + 'start auth with advice', + ).toBe(true); + expect( + messageArray.includes('Continuing authentication with composite advice'), + 'continue with advice', + ).toBe(true); }); }); diff --git a/packages/javascript-sdk/src/oauth2-client/index.ts b/packages/javascript-sdk/src/oauth2-client/index.ts index a95e882d0..db767a65a 100644 --- a/packages/javascript-sdk/src/oauth2-client/index.ts +++ b/packages/javascript-sdk/src/oauth2-client/index.ts @@ -160,6 +160,7 @@ abstract class OAuth2Client { }; const response = await this.request('accessToken', undefined, false, init, options); + const responseClone = response.clone(); const responseBody = await this.getBody(response); if (response.status !== 200) { @@ -185,6 +186,7 @@ abstract class OAuth2Client { idToken: responseObject.id_token, refreshToken: responseObject.refresh_token, tokenExpiry: tokenExpiry, + rawResponse: await responseClone.text(), }; } diff --git a/packages/javascript-sdk/src/oauth2-client/interfaces.ts b/packages/javascript-sdk/src/oauth2-client/interfaces.ts index 6a48bd7de..d6fd4d913 100644 --- a/packages/javascript-sdk/src/oauth2-client/interfaces.ts +++ b/packages/javascript-sdk/src/oauth2-client/interfaces.ts @@ -18,6 +18,7 @@ import type { ResponseType } from './enums'; interface OAuth2Tokens { accessToken: string; idToken?: string; + rawResponse: unknown; refreshToken?: string; tokenExpiry?: number; } diff --git a/packages/javascript-sdk/src/shared/interfaces.ts b/packages/javascript-sdk/src/shared/interfaces.ts index d8a5e8139..df519642a 100644 --- a/packages/javascript-sdk/src/shared/interfaces.ts +++ b/packages/javascript-sdk/src/shared/interfaces.ts @@ -15,6 +15,7 @@ interface StringDict { interface Tokens { accessToken: string; idToken?: string; + rawResponse: unknown; refreshToken?: string; tokenExpiry?: number; } diff --git a/packages/javascript-sdk/src/token-manager/index.ts b/packages/javascript-sdk/src/token-manager/index.ts index 59c3c6feb..4c1b915a9 100644 --- a/packages/javascript-sdk/src/token-manager/index.ts +++ b/packages/javascript-sdk/src/token-manager/index.ts @@ -74,8 +74,8 @@ abstract class TokenManager { const tokens = await TokenStorage.get(); /** - * If tokens are stored, no option for `forceRenew` or `query` object with `code`, and do not expire within the configured threshold, - * immediately return the stored tokens + * If tokens are stored, no option for `forceRenew` or `query` object with `code`, + * and do not expire within the configured threshold, immediately return the stored tokens */ if ( tokens && @@ -87,8 +87,9 @@ abstract class TokenManager { } /** - * If we are still here because of forceRenew or we have an authorization code, or the tokens expire within the configured threshold, - * revoke and delete existing tokens to prepare for the new ones + * If we are still here because of forceRenew or we have an authorization code, + * or the tokens expire within the configured threshold, revoke and delete existing + * tokens to prepare for the new ones */ if (tokens) { try {