Skip to content

Commit fde9406

Browse files
committed
chore: migrate-old-mock-api
migrate old mock api to repo
1 parent 6b110df commit fde9406

23 files changed

+3102
-1
lines changed

e2e/am-mock-api/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["@nx/js/babel", { "useBuiltIns": "entry" }]]
3+
}

e2e/am-mock-api/.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"ignorePatterns": [
7+
"node_modules",
8+
"*.md",
9+
"LICENSE",
10+
".babelrc",
11+
".env*",
12+
".bin",
13+
"dist",
14+
".eslintignore"
15+
]
16+
},
17+
{
18+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
19+
"rules": {}
20+
},
21+
{
22+
"files": ["*.ts", "*.tsx"],
23+
"rules": {}
24+
},
25+
{
26+
"files": ["*.js", "*.jsx"],
27+
"rules": {}
28+
}
29+
]
30+
}

e2e/am-mock-api/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "am-mock-api",
3+
"version": "0.0.0",
4+
"private": true,
5+
"description": "",
6+
"keywords": [],
7+
"license": "ISC",
8+
"author": "",
9+
"type": "commonjs",
10+
"main": "./index.js",
11+
"dependencies": {
12+
"@types/express": "5.0.1",
13+
"body-parser": "^2.2.0",
14+
"cookie-parser": "^1.4.7",
15+
"cors": "^2.8.5",
16+
"express": "^4.21.2",
17+
"superagent": "^10.2.3",
18+
"uuid": "^13.0.0"
19+
}
20+
}

e2e/am-mock-api/project.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "am-mock-api",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "e2e/am-mock-api/src",
5+
"projectType": "application",
6+
"tags": ["scope:e2e"],
7+
"targets": {
8+
"build": {
9+
"executor": "@nx/js:tsc",
10+
"outputs": ["{projectRoot}/dist"],
11+
"options": {
12+
"outputPath": "e2e/am-mock-api/dist",
13+
"main": "e2e/am-mock-api/src/index.js",
14+
"clean": true,
15+
"tsConfig": "e2e/am-mock-api/tsconfig.app.json",
16+
"assets": ["e2e/am-mock-api/src/assets"]
17+
},
18+
"configurations": {
19+
"development": {
20+
"watch": true
21+
},
22+
"production": {
23+
"optimization": true,
24+
"extractLicenses": true,
25+
"inspect": false,
26+
"fileReplacements": [
27+
{
28+
"replace": "e2e/am-mock-api/src/environments/environment.ts",
29+
"with": "e2e/am-mock-api/src/environments/environment.prod.ts"
30+
}
31+
]
32+
}
33+
}
34+
},
35+
"serve": {
36+
"executor": "@nx/js:node",
37+
"outputs": ["{projectRoot}/dist"],
38+
"options": {
39+
"buildTarget": "mock-api:build"
40+
}
41+
},
42+
"lint": {
43+
"options": {
44+
"fix": true,
45+
"ignore-path": ".eslintignore",
46+
"args": ["**/*.ts"]
47+
}
48+
}
49+
}
50+
}

e2e/am-mock-api/src/app/.gitkeep

Whitespace-only changes.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @forgerock/javascript-sdk
3+
*
4+
* app.auth.js
5+
*
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
7+
* This software may be modified and distributed under the terms
8+
* of the MIT license. See the LICENSE file for details.
9+
*/
10+
11+
import request from 'superagent';
12+
import { AM_URL, REALM_PATH } from './env.config.js';
13+
14+
export let session;
15+
16+
export async function authorizeApp({ un, pw }) {
17+
try {
18+
const response = await request
19+
.post(`${AM_URL}/json/realms/${REALM_PATH}/authenticate`)
20+
.set('Content-Type', 'application/json')
21+
.set('Accept-API-Version', 'resource=2.0, protocol=1.0')
22+
.set('X-OpenAM-Username', un)
23+
.set('X-OpenAM-Password', pw)
24+
.send({});
25+
26+
session = response.body;
27+
28+
console.log(`REST app identity token: ${session.tokenId}`);
29+
30+
return session;
31+
} catch (error) {
32+
console.warn('\n###################################################');
33+
console.warn('WARNING: REST app user for Step Up/Txn Auth missing');
34+
console.warn('###################################################\n');
35+
}
36+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* @forgerock/javascript-sdk
3+
*
4+
* constants.js
5+
*
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
7+
* This software may be modified and distributed under the terms
8+
* of the MIT license. See the LICENSE file for details.
9+
*/
10+
11+
export const authPaths = {
12+
tokenExchange: [
13+
'/am/auth/tokenExchange',
14+
'/am/oauth2/realms/root/access_token',
15+
'/am/oauth2/realms/root/realms/middleware/access_token',
16+
'/am/oauth2/realms/root/realms/middleware-modern/access_token',
17+
'/am/oauth2/realms/root/realms/tokens-expiring-soon/access_token',
18+
'/am/oauth2/realms/root/realms/tokens-expired/access_token',
19+
],
20+
authenticate: [
21+
'/am/auth/authenticate',
22+
'/am/json/realms/root/authenticate',
23+
'/am/json/realms/root/realms/middleware/authenticate',
24+
'/am/json/realms/root/realms/tokens-expiring-soon/authenticate',
25+
'/am/json/realms/root/realms/tokens-expired/authenticate',
26+
],
27+
htmlAuthenticate: ['/am/'],
28+
authorize: [
29+
'/am/auth/authorize',
30+
'/am/oauth2/realms/root/authorize',
31+
'/am/oauth2/realms/root/realms/middleware/authorize',
32+
'/am/oauth2/realms/root/realms/middleware-modern/authorize',
33+
'/am/oauth2/realms/root/realms/tokens-expiring-soon/authorize',
34+
'/am/oauth2/realms/root/realms/tokens-expired/authorize',
35+
],
36+
endSession: [
37+
'/am/auth/endSession',
38+
'/am/oauth2/realms/root/connect/endSession',
39+
'/am/oauth2/realms/root/connect/idpEndSession',
40+
'/am/oauth2/realms/root/realms/middleware/connect/endSession',
41+
'/am/oauth2/realms/root/realms/tokens-expiring-soon/connect/endSession',
42+
'/am/oauth2/realms/root/realms/tokens-expired/connect/endSession',
43+
],
44+
userInfo: [
45+
'/am/auth/userInfo',
46+
'/am/oauth2/realms/root/userinfo',
47+
'/am/oauth2/realms/root/realms/middleware/userinfo',
48+
'/am/oauth2/realms/root/realms/tokens-expiring-soon/userinfo',
49+
'/am/oauth2/realms/root/realms/tokens-expired/userinfo',
50+
],
51+
revoke: [
52+
'/am/auth/revoke',
53+
'/am/oauth2/realms/root/token/revoke',
54+
'/am/oauth2/realms/root/realms/middleware/token/revoke',
55+
'/am/oauth2/realms/root/realms/tokens-expiring-soon/token/revoke',
56+
'/am/oauth2/realms/root/realms/tokens-expired/token/revoke',
57+
],
58+
sessions: [
59+
'/am/auth/sessions',
60+
'/am/json/realms/root/sessions',
61+
'/am/json/realms/root/realms/middleware/sessions',
62+
'/am/json/realms/root/realms/tokens-expiring-soon/sessions',
63+
'/am/json/realms/root/realms/tokens-expired/sessions',
64+
],
65+
accounts: ['/o/oauth2/v2/auth', '/SAMLFailure', '/SAMLTest'],
66+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* @forgerock/javascript-sdk
3+
*
4+
* env.config.js
5+
*
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
7+
* This software may be modified and distributed under the terms
8+
* of the MIT license. See the LICENSE file for details.
9+
*/
10+
11+
import { env } from 'process';
12+
13+
/**
14+
* Configure your environment defaults below.
15+
*/
16+
const oauth = {
17+
client: 'WebOAuthClient',
18+
scope: 'openid profile me.read',
19+
};
20+
const origins = {
21+
// Ensure all domains are added to the security cert creation
22+
app: process.env.NODE_ENV === 'LIVE' ? 'https://sdkapp.petrov.ca' : 'http://localhost',
23+
forgeops: 'https://default.forgeops.petrov.ca',
24+
mock: 'http://localhost',
25+
resource: 'http://localhost',
26+
};
27+
const paths = {
28+
am: '/am',
29+
};
30+
const ports = {
31+
app: '8443',
32+
forgeops: '443',
33+
mock: '9443',
34+
resource: '9443',
35+
};
36+
const realm = 'root';
37+
const testUsers = [
38+
{
39+
// Already exists in forgeops...
40+
pw: 'password',
41+
un: 'sdkuser',
42+
},
43+
];
44+
45+
/**
46+
* The below will be composed of the above values.
47+
* Do not edit unless you know what you're doing.
48+
*/
49+
let amUrl;
50+
let amPort;
51+
52+
if (env.LIVE) {
53+
amUrl = origins.forgeops;
54+
amPort = ports.forgeops;
55+
} else {
56+
amUrl = origins.mock;
57+
amPort = ports.mock;
58+
}
59+
60+
export const APP_PORT = ports.app;
61+
export const AM_PORT = amPort;
62+
export const MOCK_PORT = process.env.PORT || ports.mock;
63+
64+
export const AM_URL = `${amUrl}:${amPort}${paths.am}`;
65+
export const BASE_URL = `${origins.app}:${ports.app}`;
66+
export const CLIENT_ID = oauth.client;
67+
export const FORGEOPS = origins.forgeops;
68+
export const REALM_PATH = realm;
69+
export const RESOURCE_URL = `${origins.resource}:${ports.resource}`;
70+
export const SCOPE = oauth.scope;
71+
export const USERS = testUsers;

0 commit comments

Comments
 (0)