Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/lucky-balloons-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@forgerock/javascript-sdk': patch
'@forgerock/ping-protect': patch
---

This aligns ping-protect and protect initialize callbacks to the new Journey Nodes
16 changes: 13 additions & 3 deletions e2e/autoscript-apps/src/authn-basic-self-service/autoscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* of the MIT license. See the LICENSE file for details.
*/
import * as forgerock from '@forgerock/javascript-sdk';
import { CallbackType } from '@forgerock/javascript-sdk';
import { deviceClient } from '@forgerock/javascript-sdk/device-client';
import { delay as rxDelay, map, mergeMap } from 'rxjs/operators';
import { from } from 'rxjs';
Expand Down Expand Up @@ -73,8 +74,17 @@ function autoscript() {
.pipe(
mergeMap((step) => {
console.log('Set values on auth tree callbacks');
step.getCallbackOfType('NameCallback').setName(un);
step.getCallbackOfType('PasswordCallback').setPassword(pw);
if (step.type !== 'Step') {
throw new Error('Expected FRStep but got ' + step.type);
}
const nameCallback = step.getCallbackOfType(
CallbackType.NameCallback,
) as forgerock.NameCallback;
const passwordCallback = step.getCallbackOfType(
CallbackType.PasswordCallback,
) as forgerock.PasswordCallback;
nameCallback.setName(un);
passwordCallback.setPassword(pw);
return forgerock.FRAuth.next(step);
}),
rxDelay(delay),
Expand Down Expand Up @@ -102,7 +112,7 @@ function autoscript() {
});

try {
const user = await forgerock.UserManager.getCurrentUser();
const user = (await forgerock.UserManager.getCurrentUser()) as { sub: string };

const query = { userId: user.sub, realm: 'alpha' };

Expand Down
2 changes: 1 addition & 1 deletion e2e/autoscript-suites/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as os from 'os';
import { PlaywrightTestConfig } from '@playwright/test';
import type { PlaywrightTestConfig } from '@playwright/test';
import { nxE2EPreset } from '@nx/playwright/preset';
import { workspaceRoot } from '@nx/devkit';
import { fileURLToPath } from 'url';
Expand Down
5 changes: 1 addition & 4 deletions e2e/autoscript-suites/src/suites/authn-protect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ test.describe('Test basic login flow with Ping Protect', () => {
expect(configObj.disableTags).toBe(false);
expect(configObj.disableHub).toBe(false);

expect(messageArray.includes('[SignalsSDK] Starting Signals SDK...')).toBe(true);
expect(messageArray.includes('[SignalsSDK] calculated device attributes.')).toBe(true);
expect(messageArray.includes('getPauseBehavioralData: true')).toBe(true);
expect(messageArray.includes('Basic login with Protect successful')).toBe(true);
expect(messageArray.includes('Test script complete')).toBe(true);
Expand All @@ -46,8 +44,7 @@ test.describe('Test basic login flow with Ping Protect', () => {
const { messageArray } = await setupAndGo(page, browserName, 'authn-protect/', {
pauseBehaviorData: 'false',
});
expect(messageArray.includes('[SignalsSDK] Starting Signals SDK...')).toBe(true);
expect(messageArray.includes('[SignalsSDK] calculated device attributes.')).toBe(true);

expect(messageArray.includes('getPauseBehavioralData: false')).toBe(true);
expect(messageArray.includes('Basic login with Protect successful')).toBe(true);
});
Expand Down
3 changes: 2 additions & 1 deletion e2e/token-vault-app/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"moduleResolution": "Bundler",
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force"
"moduleDetection": "force",
"types": ["vite/client"]
},
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
Expand Down
2 changes: 1 addition & 1 deletion e2e/token-vault-interceptor/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"lib": ["ESNext", "DOM", "WebWorker", "Webworker.Iterable"],
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"types": ["vite/client"]
},
"include": ["src/**/*.ts"],
Expand Down
2 changes: 1 addition & 1 deletion e2e/token-vault-suites/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlaywrightTestConfig } from '@playwright/test';
import type { PlaywrightTestConfig } from '@playwright/test';
import { nxE2EPreset } from '@nx/playwright/preset';
import { workspaceRoot } from '@nx/devkit';
import { fileURLToPath } from 'url';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@nx/vite": "20.3.3",
"@nx/web": "20.3.3",
"@nx/workspace": "20.3.3",
"@playwright/test": "^1.47.2",
"@playwright/test": "1.47.2",
"@swc-node/register": "1.9.2",
"@swc/core": "1.5.7",
"@swc/helpers": "0.5.12",
Expand Down Expand Up @@ -94,7 +94,7 @@
"npm-cli-login": "^1.0.0",
"nx": "20.3.3",
"pkg-pr-new": "^0.0.60",
"playwright": "^1.47.2",
"playwright": "1.47.2",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0",
"sass": "^1.71.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('PingOneProtectInitializeCallback', () => {
it('should exist', () => {
expect(PingOneProtectInitializeCallback).toBeDefined();
});
it('should test the getConfig method', () => {

it('should test the getConfig method with no "agent" parameters', () => {
const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
input: [
Expand Down Expand Up @@ -70,6 +71,10 @@ describe('PingOneProtectInitializeCallback', () => {
name: 'disableHub',
value: false,
},
{
name: 'universalDeviceIdentification',
value: false,
},
],
});
const mock = vi.spyOn(callback, 'getConfig');
Expand All @@ -88,6 +93,99 @@ describe('PingOneProtectInitializeCallback', () => {
disableHub: false,
});
});

it('should test the getConfig method with "agent" parameters', () => {
const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
input: [
{
name: 'IDToken1signals',
value: '',
},
{
name: 'IDToken1clientError',
value: '',
},
],
output: [
{
name: 'agentIdentification',
value: true,
},
{
name: 'agentTimeout',
value: 1,
},
{
name: 'agentPort',
value: 1,
},
{
name: 'envId',
value: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
},
{
name: 'consoleLogEnabled',
value: false,
},
{
name: 'deviceAttributesToIgnore',
value: [],
},
{
name: 'customHost',
value: '',
},
{
name: 'lazyMetadata',
value: false,
},
{
name: 'behavioralDataCollection',
value: true,
},
{
name: 'deviceKeyRsyncIntervals',
value: 14,
},
{
name: 'enableTrust',
value: false,
},
{
name: 'disableTags',
value: false,
},
{
name: 'disableHub',
value: false,
},
{
name: 'universalDeviceIdentification',
value: false,
},
],
});
const mock = vi.spyOn(callback, 'getConfig');
const config = callback.getConfig();
expect(mock).toHaveBeenCalled();
expect(config).toMatchObject({
agentIdentification: true,
agentTimeout: 1,
agentPort: 1,
envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
consoleLogEnabled: false,
deviceAttributesToIgnore: [],
customHost: '',
lazyMetadata: false,
behavioralDataCollection: true,
deviceKeyRsyncIntervals: 14,
enableTrust: false,
disableTags: false,
disableHub: false,
});
});

it('should test the setClientError method', () => {
const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
Expand All @@ -102,6 +200,18 @@ describe('PingOneProtectInitializeCallback', () => {
},
],
output: [
{
name: 'agentIdentification',
value: false,
},
{
name: 'agentTimeout',
value: 0,
},
{
name: 'agentPort',
value: 0,
},
{
name: 'envId',
value: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
Expand Down Expand Up @@ -142,11 +252,15 @@ describe('PingOneProtectInitializeCallback', () => {
name: 'disableHub',
value: false,
},
{
name: 'universalDeviceIdentification',
value: false,
},
],
});
const mock = vi.spyOn(callback, 'setClientError');
callback.setClientError('error i just set');
callback.setClientError('Error I set');
expect(mock).toHaveBeenCalled();
expect(callback.getInputValue('IDToken1clientError')).toBe('error i just set');
expect(callback.getInputValue('IDToken1clientError')).toBe('Error I set');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,35 @@ class PingOneProtectInitializeCallback extends FRCallback {
* Get callback's initialization config settings
*/
public getConfig() {
const agentIdentification = this.getOutputByName<boolean | undefined>(
'agentIdentification',
undefined,
);
const agentTimeout = this.getOutputByName<number | undefined>('agentTimeout', undefined);
const agentPort = this.getOutputByName<number | undefined>('agentPort', undefined);

const config = {
// Required parameter
envId: this.getOutputByName<string>('envId', ''),

// Optional parameters
...(agentIdentification !== undefined ? { agentIdentification } : {}),
...(agentTimeout !== undefined ? { agentTimeout } : {}),
...(agentPort !== undefined ? { agentPort } : {}),
behavioralDataCollection: this.getOutputByName<boolean>('behavioralDataCollection', true),
disableTags: this.getOutputByName<boolean>('disableTags', false),
universalDeviceIdentification: this.getOutputByName<boolean>(
'universalDeviceIdentification',
false,
),

// Deprecated parameters
consoleLogEnabled: this.getOutputByName<boolean>('consoleLogEnabled', false),
deviceAttributesToIgnore: this.getOutputByName<string[]>('deviceAttributesToIgnore', []),
customHost: this.getOutputByName<string>('customHost', ''),
lazyMetadata: this.getOutputByName<boolean>('lazyMetadata', false),
behavioralDataCollection: this.getOutputByName<boolean>('behavioralDataCollection', true),
deviceKeyRsyncIntervals: this.getOutputByName<number>('deviceKeyRsyncIntervals', 14),
enableTrust: this.getOutputByName<boolean>('enableTrust', false),
disableTags: this.getOutputByName<boolean>('disableTags', false),
disableHub: this.getOutputByName<boolean>('disableHub', false),
};
return config;
Expand Down
24 changes: 3 additions & 21 deletions packages/ping-protect/src/lib/ping-protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,13 @@ export interface Identifiers {
[key: string]: string;
}

/**
* InitParams - Interface for the init method parameters
* envId: string - Required; the environment id from your PingOne tenant
* * - All other parameters are optional
*/
export interface InitParams {
envId: string; // environment id
consoleLogEnabled?: boolean; // true to enable SDK logs in the developer console. default is false
waitForWindowLoad?: boolean; // true to init the SDK on load event, instead of DOMContentLoaded event. default is true
hubUrl?: string; // iframe url for cross-storage device ID
disableHub?: boolean; // when true, the SDK store the deviceId to the localStorage only and won't use an iframe (hub). default is false
deviceAttributesToIgnore?: string[]; // metadata blacklist
lazyMetadata?: boolean; // true to calculate the metadata only on getData invocation, otherwise do it automatically on init. default is false
behavioralDataCollection?: boolean; // true to collect behavioral data. default is true
disableTags?: boolean; // true to skip tag collection. default is false,
externalIdentifiers?: Identifiers; // optional customer external identifiers that should be reflected on a device entity
deviceKeyRsyncIntervals?: number; // number of days used to window the next time the device attestation should use the device fallback key. default is 14 days
enableTrust?: boolean; // tie the device payload to a non-extractable crypto key stored on the browser for content authenticity verification
}
export type InitParams = Omit<ProtectInitializeConfig, '_type' | '_action'>;

// Add Signals SDK namespace to the window object
declare global {
interface Window {
_pingOneSignals: {
init: (initParams?: InitParams) => Promise<void>;
init: (initParams?: ProtectInitializeConfig) => Promise<void>;
getData: () => Promise<string>;
pauseBehavioralData: () => void;
resumeBehavioralData: () => void;
Expand Down Expand Up @@ -74,7 +56,7 @@ export abstract class PIProtect {
* @param {InitParams} options - The init parameters
* @returns {Promise<void>} - Returns a promise
*/
public static async start(options: InitParams): Promise<void> {
public static async start(options: ProtectInitializeConfig): Promise<void> {
try {
/*
* Load the Ping Signals SDK
Expand Down
17 changes: 14 additions & 3 deletions packages/ping-protect/src/lib/ping-protect.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@
export interface ProtectInitializeConfig {
_type: 'PingOneProtect';
_action: 'protect_initialize';
envId?: string;
envId: string;

// Optional parameters
agentIdentification?: boolean;
agentTimeout?: number;
agentPort?: number;
behavioralDataCollection?: boolean;
universalDeviceIdentification?: boolean;
disableTags?: boolean;

// Deprecated parameters
consoleLogEnabled?: boolean;
deviceAttributesToIgnore?: string[];
customHost?: string;
externalIdentifiers?: string;
hubUrl?: string;
lazyMetadata?: boolean;
behavioralDataCollection?: boolean;
deviceKeyRsyncIntervals?: number;
enableTrust?: boolean;
disableTags?: boolean;
disableHub?: boolean;
waitForWindowLoad?: boolean;
}

export interface ProtectEvaluationConfig {
Expand Down
Loading
Loading