Skip to content

Commit 657c11e

Browse files
maximthomasCopilotdependabot[bot]vharsekoOpen Identity Platform Community
authored
OpenAM UI JS SDK (#941)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Valery Kharseko <[email protected]> Co-authored-by: Open Identity Platform Community <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: vharseko <[email protected]>
1 parent 0d6d069 commit 657c11e

50 files changed

Lines changed: 9061 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
continue-on-error: true
6060
run: |
6161
mvn javadoc:aggregate -pl '-:openam-server,-:openam-server-only' \
62-
-pl '-:openam-ui,-:openam-ui-ria,-:openam-ui-api' \
62+
-pl '-:openam-ui,-:openam-ui-ria,-:openam-ui-api,-:openam-ui-js-sdk' \
6363
-pl '-:openam-server-auth-ui,-:openam-doc-ssoadm-ref,-:openam-liberty-schema' \
6464
-pl '-:openam-example-api-descriptor,-:openam-example-clientsdk-cli,-:openam-example-clientsdk-war' \
6565
-pl '-:bcpkix-shaded'

openam-server-only/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@
108108
<overWrite>false</overWrite>
109109
<outputDirectory>${project.build.directory}/api</outputDirectory>
110110
</artifactItem>
111+
<artifactItem>
112+
<groupId>org.openidentityplatform.openam</groupId>
113+
<artifactId>openam-ui-js-sdk</artifactId>
114+
<classifier>app</classifier>
115+
<type>zip</type>
116+
<overWrite>false</overWrite>
117+
<outputDirectory>${project.build.directory}/extui</outputDirectory>
118+
<includes>**/*</includes>
119+
</artifactItem>
111120
</artifactItems>
112121
</configuration>
113122
</execution>
@@ -265,6 +274,14 @@
265274
<targetPath>api</targetPath>
266275
<filtering>true</filtering>
267276
</webResource>
277+
<webResource>
278+
<directory>${project.build.directory}/extui/</directory>
279+
<includes>
280+
<include>**/**</include>
281+
</includes>
282+
<targetPath>extui</targetPath>
283+
<filtering>false</filtering>
284+
</webResource>
268285
<webResource>
269286
<directory>${basedir}/src/main/webapp</directory>
270287
<includes>
@@ -567,6 +584,13 @@
567584
<type>jar</type>
568585
</dependency>
569586

587+
<dependency>
588+
<groupId>org.openidentityplatform.openam</groupId>
589+
<artifactId>openam-ui-js-sdk</artifactId>
590+
<type>zip</type>
591+
<classifier>app</classifier>
592+
</dependency>
593+
570594
<dependency>
571595
<groupId>org.openidentityplatform.openam</groupId>
572596
<artifactId>openam-core</artifactId>

openam-server-only/src/main/resources/services/amCORS.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
serviceHierarchy="/DSAMEConfig/CORSService"
4141
i18nFileName="amCORS"
4242
resourceName="cors"
43-
i18nKey="cors-service-description">
43+
i18nKey="cors-service-description" revisionNumber="2">
4444
<Global>
4545
<AttributeSchema name="cors-enabled"
4646
type="single"
@@ -93,6 +93,7 @@
9393
<Value>Upgrade-Insecure-Requests</Value>
9494
<Value>Referer</Value>
9595
<Value>Cookie</Value>
96+
<Value>Accept-API-Version</Value>
9697
</DefaultValues>
9798
</AttributeSchema>
9899
<AttributeSchema name="exposed-headers"

openam-ui/openam-ui-js-sdk/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#VITE_OPENAM_SERVER=http://openam.example.org:8080
2+
#VITE_OPENAM_CONTEXT_PATH=/openam
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_OPENAM_SERVER=http://openam.example.org:8080
2+
VITE_OPENAM_CONTEXT_PATH=/openam
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
27+
*.zip
28+
29+
example/
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# OpenAM Alternative Frontend SDK
2+
3+
OpenAM is a robust access management solution, but integrating it with modern frontend applications can be complex and time-consuming. This SDK aims to simplify that process by providing pre-built React components and a flexible, modular setup, saving developers significant time while ensuring secure, seamless integration with OpenAM.
4+
5+
This project is intended to provide an alternative frontend SDK for interacting with Open Identity Platform's OpenAM authentication services. It is built using modern web technologies and aims to simplify the integration process for developers.
6+
7+
## Features
8+
- **Ease of Use**: Pre-configured React components ready for integration.
9+
- **Modular & Flexible**: Easily swap components and customize the SDK to suit your needs.
10+
- **TypeScript Support**: Enhance development experience with type safety and better code completion.
11+
- **Seamless Integration**: Easily integrate OpenAM with minimal configuration.
12+
13+
# Prerequisites
14+
- Node.js 22 LTS and newer
15+
- OpenAM 14 and newer
16+
17+
## Installation
18+
19+
Clone and build the source code
20+
21+
```bash
22+
git clone https://github.com/OpenIdentityPlatform/openam-js-sdk.git
23+
```
24+
25+
```bash
26+
cd openam-js-sdk
27+
npm install
28+
npm run build
29+
```
30+
31+
## Usage
32+
33+
### As an Application
34+
35+
Copy the contents of the `target/app` folder into your OpenAM WAR file (or the extracted WAR contents in your web container), e.g., into a directory like `extui`, so it could be accessible in your OpenAM context path, for example, http://openam.example.org:8080/openam/extui
36+
37+
You can also run the application in a standalone server. The only condition, the servers should be on the same subdomain, so OpenAM's cookies could be sent from the frontend application.
38+
39+
40+
## As an SDK library
41+
42+
To install the SDK, use npm or yarn:
43+
44+
```bash
45+
npm install <path to openam-js-sdk folder> #for example /home/user/projects/openam-js-sdk
46+
# or
47+
yarn add <path to openam-js-sdk folder>
48+
```
49+
## Usage
50+
Here's a basic example of how to use the SDK in a React application:
51+
52+
```tsx
53+
import React from 'react';
54+
import { OpenAMUI } from 'openam-js-sdk';
55+
56+
const App = () => {
57+
return (
58+
<OpenAMUI />
59+
);
60+
};
61+
```
62+
63+
## Customization
64+
65+
You can customize the SDK by providing your own UI components and styles.
66+
67+
To customize the application behaviour, customise the following settings:
68+
69+
```ts
70+
export interface Config {
71+
openamServer: string; //OpenAM server host, for example http://openam.example.org:8080
72+
openamContextPath: string; //OpenAM context path, for example /openam
73+
LoginForm: LoginForm; //LoginForm interface implementation
74+
UserForm: UserForm; //UserForm interface implementation
75+
ErrorForm: ErrorForm; //ErrorForm interface implementation
76+
CallbackElement: CallbackElement; //CallbackElement interface implementation
77+
ActionElements: ActionElements; //ActionElements interface implementation
78+
redirectOnSuccessfulLogin: boolean; //redirects user on successful login to the target URL, otherwise shows a profile.
79+
getOpenAmUrl: () => string; //returns a full OpenAM URL, for example http://openam.example.org:8080/openam
80+
}
81+
```
82+
83+
for example
84+
85+
```tsx
86+
// update the default configuration
87+
import React, { StrictMode } from 'react';
88+
import { createRoot } from 'react-dom/client';
89+
import { OpenAMUI, setConfig } from 'openam-js-sdk';
90+
91+
setConfig({
92+
openamServer: 'https://openam.example.org:443',
93+
openamContextPath: '/am',
94+
ErrorForm: ({ error, resetError }) => {
95+
return (
96+
<div>
97+
<h1>An error occurred</h1>
98+
<p>{error?.message}</p>
99+
<input
100+
type="button"
101+
value="Retry"
102+
onClick={() => resetError()}
103+
/>
104+
</div>
105+
);
106+
},
107+
});
108+
109+
createRoot(document.getElementById('root')!).render(
110+
<StrictMode>
111+
<OpenAMUI />
112+
</StrictMode>,
113+
);
114+
```
115+
116+
There are components you can override:
117+
118+
```tsx
119+
// renders a login form with callbacks
120+
export type LoginForm = React.FC<{
121+
authData: AuthData,
122+
setCallbackValue: (i: number, val: string) => void,
123+
doLogin: (action: string) => void
124+
}>
125+
126+
// renders a callback such as NameCallback, PasswordCallback and so on
127+
export type CallbackElement = React.FC<{
128+
callback: Callback
129+
setCallbackValue: (val: string) => void
130+
}>
131+
132+
// renders a user profile form
133+
export type UserForm = React.FC<{
134+
userData: UserData,
135+
setUserData: (userData: UserData) => void
136+
saveHandler: () => void
137+
savePasswordHandler: (password: string) => void
138+
}>
139+
140+
// renders an authentication error form
141+
export type ErrorForm = React.FC<{
142+
error: AuthError,
143+
resetError: () => void
144+
}>
145+
146+
// renders submit buttons; if there are no ConfirmationCallback in the callbacks array, renders the default button
147+
export type ActionElements = React.FC<{callbacks: Callback[]}>
148+
```
149+
150+
151+
## Contributing
152+
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Make sure to follow the coding standards and include tests for any new features.
153+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* The contents of this file are subject to the terms of the Common Development and
4+
* Distribution License (the License). You may not use this file except in compliance with the
5+
* License.
6+
*
7+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
8+
* specific language governing permission and limitations under the License.
9+
*
10+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
11+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
12+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
13+
* information: "Portions copyright [year] [name of copyright owner]".
14+
*
15+
* Copyright 2025 3A Systems LLC.
16+
-->
17+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
20+
<id>app</id>
21+
<baseDirectory>/</baseDirectory>
22+
<formats>
23+
<format>zip</format>
24+
</formats>
25+
<fileSets>
26+
<fileSet>
27+
<directory>target/app</directory>
28+
<outputDirectory>/</outputDirectory>
29+
</fileSet>
30+
</fileSets>
31+
</assembly>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
* The contents of this file are subject to the terms of the Common Development and
4+
* Distribution License (the License). You may not use this file except in compliance with the
5+
* License.
6+
*
7+
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
8+
* specific language governing permission and limitations under the License.
9+
*
10+
* When distributing Covered Software, include this CDDL Header Notice in each file and include
11+
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
12+
* Header, with the fields enclosed by brackets [] replaced by your own identifying
13+
* information: "Portions copyright [year] [name of copyright owner]".
14+
*
15+
* Copyright 2025 3A Systems LLC.
16+
-->
17+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
20+
<id>lib</id>
21+
<baseDirectory>/</baseDirectory>
22+
<formats>
23+
<format>zip</format>
24+
</formats>
25+
<fileSets>
26+
<fileSet>
27+
<directory>target/lib</directory>
28+
<outputDirectory>/</outputDirectory>
29+
</fileSet>
30+
</fileSets>
31+
</assembly>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
import tseslint from 'typescript-eslint'
6+
import { defineConfig, globalIgnores } from 'eslint/config'
7+
8+
export default defineConfig([
9+
globalIgnores(['dist']),
10+
{
11+
files: ['**/*.{ts,tsx}'],
12+
extends: [
13+
js.configs.recommended,
14+
tseslint.configs.recommended,
15+
reactHooks.configs['recommended-latest'],
16+
reactRefresh.configs.vite,
17+
],
18+
languageOptions: {
19+
ecmaVersion: 2020,
20+
globals: globals.browser,
21+
},
22+
},
23+
])

0 commit comments

Comments
 (0)