New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@forgerock/javascript-sdk

Package Overview
Dependencies
Maintainers
6
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@forgerock/javascript-sdk - npm Package Compare versions

Comparing version 0.7.0-beta to 0.9.0

LICENSE

8

package.json
{
"name": "@forgerock/javascript-sdk",
"version": "0.7.0-beta",
"version": "0.9.0",
"description": "ForgeRock JavaScript SDK",

@@ -44,3 +44,3 @@ "main": "./lib/",

"type": "git",
"url": "git+https://github.com/ForgeCloud/forgerock-javascript-sdk.git"
"url": "git+https://github.com/ForgeRock/forgerock-javascript-sdk.git"
},

@@ -50,5 +50,5 @@ "author": "ForgeRock",

"bugs": {
"url": "https://github.com/ForgeCloud/forgerock-javascript-sdk/issues"
"url": "https://github.com/ForgeRock/forgerock-javascript-sdk/issues"
},
"homepage": "https://github.com/ForgeCloud/forgerock-javascript-sdk#readme",
"homepage": "https://github.com/ForgeRock/forgerock-javascript-sdk#readme",
"devDependencies": {

@@ -55,0 +55,0 @@ "@types/chai": "^4.1.7",

@@ -11,45 +11,9 @@ # ForgeRock JavaScript SDK

## Usage
## Sample Usage
### Configuration
In most real-world scenarios, you will want to have full control over the UI. In these cases, you can use `FRAuth` to obtain typed callback instances from authentication trees and render the UI in whatever way makes sense for your application.
There are a few default settings to configure before invoking SDK components. When authenticating users with trees, you'll need to provide the server configuration and tree name. If also obtaining OAuth tokens, you'll provide the client ID, redirect URI, and desired scope.
In the following example, a simple React app iteratively calls `FRAuth.next()` until either an error occurs or a session token is obtained. The custom React component `<UsernamePassword />` is defined to handle an authentication step named "UsernamePassword".
```js
forgerock.Config.set({
clientId: 'my_client_id',
redirectUri: 'https://myapp.domain.com/callback',
scope: 'openid profile me.read',
serverConfig: { baseUrl: 'https://mytenant.forgeblocks.local/am/' },
tree: 'UsernamePassword',
});
```
The following UI examples assume this configuration has already been set and are intentionally very minimal to demonstrate key SDK usage.
### Basic Example
Using the `FRUser` component is the easiest way to authenticate users. This example combines it with the `ExpressLogin` UI to leverage the username/password authentication tree provided out-of-the-box with ForgeRock Express tenants. All required elements are rendered by the SDK, and you can customize the experience by defining CSS styles to override our defaults.
```js
async function signIn() {
const ui = new forgerock.ExpressLogin({ targetId: 'sdk-target' });
const user = await forgerock.FRUser.loginWithUI(ui);
window.sessionStorage.setItem('user', JSON.stringify(user));
window.location = 'authenticated.html';
}
async function signOut() {
await forgerock.FRUser.logout();
window.location = 'login.html';
}
```
### Custom UI Example
In most real-world scenarios, you will want to have full control over the UI. In these cases, you can use `FRAuth` to obtain typed callback instances from authentication trees and render the UI in whatever way makes sense for you.
In this example, a simple React app iteratively calls `FRAuth.next()` until either an error occurs or a session token is obtained. A custom React component named `UsernamePassword` is defined to handle the "UsernamePassword" stage in a ForgeRock Express flow.
```js
import { FRAuth, Config } from '@forgerock/javascript-sdk';

@@ -62,2 +26,3 @@ import React from 'react';

// Initialize application state
this.state = {

@@ -71,2 +36,12 @@ error: undefined,

componentDidMount() {
// Set configuration defaults
Config.set({
clientId: 'my_client_id',
redirectUri: 'https://myapp.domain.com/callback',
scope: 'openid profile me.read',
serverConfig: { baseUrl: 'https://mytenant.forgeblocks.local/am/' },
tree: 'UsernamePassword',
});
// Start the authentication flow
this.nextStep();

@@ -76,5 +51,7 @@ }

nextStep = async (step) => {
// Get the next step in this authentication tree
step = await FRAuth.next(step).catch(this.onError);
let ssoToken;
let error;
// Update application state based on the response
let ssoToken, error;
if (step.type === 'LoginSuccess') {

@@ -93,2 +70,3 @@ ssoToken = step.getSessionToken();

render() {
// Handle init/success/failure states
if (!this.state.step) {

@@ -102,2 +80,3 @@ return <p>Loading...</p>;

// Otherwise, select the correct component for this step
const stage = this.state.step.getStage();

@@ -116,2 +95,3 @@ return (

// Custom UI for rendering the "UsernamePassword" step
function UsernamePassword(props) {

@@ -209,12 +189,4 @@ const setUsername = (e) => {

## To Do
- Unit tests with coverage reporting
- Expand E2E tests
- Optimizations
- Customize typedocs comments
- Link to official developer docs
## License
[MIT](http://opensource.org/licenses/MIT)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc