From 92826f6fbb4f8632950aeef5ed4e437587497ef4 Mon Sep 17 00:00:00 2001
From: Jared Perreault <90656038+jaredperreault-okta@users.noreply.github.com>
Date: Thu, 17 Aug 2023 10:18:13 -0400
Subject: [PATCH] fix: prevents incorrectly removing idx message duplicates
(#1446)
OKTA-630044 fix: prevents incorrectly removing dup keys with different messages
---
CHANGELOG.md | 6 ++++++
README.md | 6 +++---
lib/idx/util.ts | 3 ++-
package.json | 2 +-
test/spec/idx/util.ts | 40 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a9b1d8cb..81d77f0a3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog
+## 7.4.1
+
+### Bug Fix
+
+- [#1446](https://github.com/okta/okta-auth-js/pull/1446) Fix: prevents incorrectly removing idx message duplicates
+
## 7.4.0
### Features
diff --git a/README.md b/README.md
index 647be2f7d..cad74e312 100644
--- a/README.md
+++ b/README.md
@@ -96,7 +96,7 @@ require('@okta/okta-auth-js/polyfill');
The built polyfill bundle is also available on our global CDN. Include the following script in your HTML file to load before any other scripts:
```html
-
+
```
> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
@@ -171,7 +171,7 @@ If you are using the JS on a web page from the browser, you can copy the `node_m
The built library bundle is also available on our global CDN. Include the following script in your HTML file to load before your application script:
```html
-
+
```
> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
@@ -812,7 +812,7 @@ const config = {
};
const authClient = new OktaAuth(config);
-const tokens = await authClient.token.getWithoutPrompt();
+const { tokens } = await authClient.token.getWithoutPrompt();
authClient.tokenManager.setTokens(tokens); // storageProvider.setItem
```
diff --git a/lib/idx/util.ts b/lib/idx/util.ts
index 7d3f1a34a..dfce6ccd1 100644
--- a/lib/idx/util.ts
+++ b/lib/idx/util.ts
@@ -73,13 +73,14 @@ export function getMessagesFromResponse(idxResponse: IdxResponse, options: RunOp
const seen = {};
messages = messages.reduce((filtered, message) => {
const key = message.i18n?.key;
- if (key && seen[key]) {
+ if (key && seen[key] && message.message === seen[key].message) {
return filtered;
}
seen[key] = message;
filtered = [...filtered, message] as never;
return filtered;
}, []);
+
return messages;
}
diff --git a/package.json b/package.json
index ebcf2a9d4..f4396dc10 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"private": true,
"name": "@okta/okta-auth-js",
"description": "The Okta Auth SDK",
- "version": "7.4.0",
+ "version": "7.4.1",
"homepage": "https://github.com/okta/okta-auth-js",
"license": "Apache-2.0",
"main": "build/cjs/exports/default.js",
diff --git a/test/spec/idx/util.ts b/test/spec/idx/util.ts
index 2b4fd0305..24c63eb17 100644
--- a/test/spec/idx/util.ts
+++ b/test/spec/idx/util.ts
@@ -120,6 +120,46 @@ describe('idx/util', () => {
}]);
});
+ it('removes duplicate messages', () => {
+ const expected = [
+ {
+ class: 'ERROR',
+ i18n: {
+ key: 'security.access_denied'
+ },
+ message: 'You do not have permission to perform the requested action.'
+ },
+ {
+ class: 'ERROR',
+ i18n: {
+ key: 'security.access_denied'
+ },
+ message: 'some random text'
+ }
+ ];
+
+ const rawIdxState = RawIdxResponseFactory.build({
+ messages: IdxMessagesFactory.build({
+ value: [
+ IdxErrorAccessDeniedFactory.build(),
+ IdxErrorAccessDeniedFactory.build(),
+ IdxErrorAccessDeniedFactory.build(),
+ IdxErrorAccessDeniedFactory.build({
+ message: 'some random text'
+ })
+ ]
+ })
+ });
+ const idxResponse = IdxResponseFactory.build({
+ rawIdxState
+ });
+ const res = getMessagesFromResponse(idxResponse, {});
+ expect(res).toEqual(expected);
+
+ const genericRemRes = getMessagesFromResponse(idxResponse, { useGenericRemediator: true });
+ expect(genericRemRes).toEqual(expected);
+ });
+
describe('form level messages', () => {
let idxResponse;
beforeEach(() => {