Skip to content

Commit b4940c7

Browse files
committed
chore: import client types and update READMEs
1 parent 75e7891 commit b4940c7

7 files changed

Lines changed: 148 additions & 25 deletions

File tree

e2e/davinci-app/components/fido.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
FidoRegistrationCollector,
1010
FidoAuthenticationCollector,
1111
Updater,
12+
FidoClient,
1213
} from '@forgerock/davinci-client/types';
1314

1415
export default function fidoComponent(
@@ -17,7 +18,7 @@ export default function fidoComponent(
1718
updater: Updater<FidoRegistrationCollector | FidoAuthenticationCollector>,
1819
submitForm: () => Promise<void>,
1920
) {
20-
const fidoApi = fido();
21+
const fidoApi: FidoClient = fido();
2122
if (collector.type === 'FidoRegistrationCollector') {
2223
const button = document.createElement('button');
2324
button.type = 'button';

e2e/device-client-app/src/utils/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { deviceClient } from '@forgerock/device-client';
2+
import type { ConfigOptions, DeviceClient } from '@forgerock/device-client/types';
23
import {
34
CallbackType,
45
Config,
@@ -76,11 +77,8 @@ export const LoginAndGetClient = Effect.gen(function* () {
7677
const un = url.searchParams.get('un') || 'devicetestuser';
7778
const pw = url.searchParams.get('pw') || 'password';
7879

79-
const config = {
80+
const config: ConfigOptions = {
8081
realmPath,
81-
tree,
82-
clientId: 'WebOAuthClient',
83-
scope: 'profile email me.read openid',
8482
serverConfig: {
8583
baseUrl: amUrl,
8684
timeout: 3000,
@@ -120,7 +118,7 @@ export const LoginAndGetClient = Effect.gen(function* () {
120118
Effect.flatMap(() => getTokens),
121119
);
122120

123-
const client = deviceClient(config);
121+
const client: DeviceClient = deviceClient(config);
124122
return client;
125123
});
126124

e2e/oidc-app/src/utils/oidc-app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
GenericError,
1313
GetAuthorizationUrlOptions,
1414
OauthTokens,
15+
OidcClient,
1516
TokenExchangeErrorResponse,
1617
} from '@forgerock/oidc-client/types';
1718

@@ -49,7 +50,7 @@ export async function oidcApp({ config, urlParams }) {
4950
const state = urlParams.get('state');
5051
const piflow = urlParams.get('piflow');
5152

52-
const oidcClient = await oidc({ config });
53+
const oidcClient: OidcClient = await oidc({ config });
5354
if ('error' in oidcClient) {
5455
displayError(oidcClient);
5556
}

e2e/protect-app/src/protect-native.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import './style.css';
1111
import { protect } from '@forgerock/protect';
12+
import type { Protect } from '@forgerock/protect/types';
1213
import {
1314
CallbackType,
1415
Config,
@@ -23,7 +24,7 @@ import {
2324
UserManager,
2425
} from '@forgerock/javascript-sdk';
2526

26-
const protectAPI = protect({ envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447' });
27+
const protectAPI: Protect = protect({ envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447' });
2728
const FATAL = 'Fatal';
2829

2930
// Check URL for query parameters

packages/device-client/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ npm install @forgerock/device-client --save
3535
To configure the `deviceClient`, you need to provide a `ConfigOptions` object that includes the base URL for the server and the realm path.
3636

3737
```typescript
38-
import { deviceClient, type ConfigOptions } from '@forgerock/device-client';
38+
import { deviceClient } from '@forgerock/device-client';
39+
import type { ConfigOptions } from '@forgerock/device-client/types';
3940

4041
const config: ConfigOptions = {
4142
serverConfig: {

packages/journey-client/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ yarn add @forgerock/journey-client
3838
## Quick Start
3939

4040
```typescript
41-
import { journey } from '@forgerock/journey-client';
42-
import { callbackType } from '@forgerock/sdk-types';
41+
import { journey, callbackType } from '@forgerock/journey-client';
4342

4443
async function authenticateUser() {
4544
// Initialize the client with wellknown discovery

packages/oidc-client/README.md

Lines changed: 136 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,146 @@ A generic OpenID Connect (OIDC) client library for JavaScript and TypeScript, de
44

55
The oidc module follows the [OIDC](https://openid.net/specs/openid-connect-core-1_0.html) specification and provides a simple and easy-to-use API to interact with the OIDC server. It allows you to authenticate, retrieve the access token, revoke the token, and sign out from the OIDC server.
66

7+
## Installation
8+
9+
```bash
10+
pnpm add @forgerock/oidc-client
11+
# or
12+
npm install @forgerock/oidc-client
13+
# or
14+
yarn add @forgerock/oidc-client
15+
```
16+
17+
## Initialization
18+
719
```js
8-
// Initialize OIDC Client
20+
import { oidc } from '@forgerock/oidc-client';
21+
922
const oidcClient = await oidc({
10-
/* config */
23+
config: {
24+
serverConfig: { wellknown: 'https://example.com/.well-known/openid-configuration' },
25+
clientId: 'example-client-id',
26+
redirectUri: 'https://example-app/redirect-uri',
27+
scope: 'openid profile email',
28+
},
1129
});
30+
```
31+
32+
## API Reference
33+
34+
### authorize
35+
36+
Methods for creating and handling authorization flows.
37+
38+
#### `authorize.url(options?)`
39+
40+
Creates an authorization URL with the provided options or defaults from the configuration.
41+
42+
- **Parameters**: `GetAuthorizationUrlOptions` (optional)
43+
- **Returns**: `Promise<string | GenericError>` - The authorization URL or an error
44+
45+
```js
46+
const authUrl = await oidcClient.authorize.url();
47+
if ('error' in authUrl) {
48+
console.error('Authorization URL creation failed:', authUrl.error);
49+
}
50+
```
51+
52+
#### `authorize.background(options?)`
53+
54+
Initiates the authorization process in the background, returning the authorization code and state or an error. This method handles the authorization flow without requiring user interaction.
1255

13-
// Authorize API
14-
const authResponse = await oidcClient.authorize.background(); // Returns code and state if successful, error if not
15-
const authUrl = await oidcClient.authorize.url(); // Returns Auth URL or error
56+
- **Parameters**: `GetAuthorizationUrlOptions` (optional)
57+
- **Returns**: `Promise<AuthorizationSuccess | AuthorizationError>` - An object containing `code` and `state` on success, or error details on failure
58+
59+
```js
60+
const authResponse = await oidcClient.authorize.background();
61+
if ('error' in authResponse) {
62+
console.error('Authorization failed:', authResponse.error);
63+
}
64+
```
1665

17-
// Tokens API
18-
const newTokens = await oidcClient.token.exchange({
19-
/* code, state */
20-
}); // Returns new tokens or error
21-
const existingTokens = await oidcClient.token.get(); // Returns existing tokens or error
22-
const response = await oidcClient.token.revoke(); // Revokes an access token and returns the response or an error
66+
### token
2367

24-
// User API
25-
const user = await oidcClient.user.info(); // Returns user object or error
26-
const logoutResponse = await oidcClient.user.logout(); // Logs the user out and returns the response or an error
68+
Methods for managing OAuth tokens.
69+
70+
#### `token.exchange(code, state, options?)`
71+
72+
Exchanges an authorization code for tokens using the token endpoint from the wellknown configuration. The tokens are automatically stored in the configured storage.
73+
74+
- **Parameters**:
75+
- `code` (string) - The authorization code received from the authorization server
76+
- `state` (string) - The state parameter from the authorization URL creation
77+
- `options` (`Partial<StorageConfig>`, optional) - Storage configuration for persisting tokens
78+
- **Returns**: `Promise<OauthTokens | TokenExchangeErrorResponse | GenericError>` - The new tokens or an error
79+
80+
```js
81+
const tokens = await oidcClient.token.exchange(authCode, authState);
82+
if ('error' in tokens) {
83+
console.error('Token exchange failed:', tokens.error);
84+
}
85+
```
86+
87+
#### `token.get(options?)`
88+
89+
Retrieves the current OAuth tokens from storage. Optionally auto-renews tokens if they are expired or if `backgroundRenew` is enabled.
90+
91+
- **Parameters**: `GetTokensOptions` (optional)
92+
- `forceRenew` - Force token renewal even if not expired
93+
- `backgroundRenew` - Automatically renew expired tokens
94+
- `authorizeOptions` - Options for authorization during renewal
95+
- `storageOptions` - Storage configuration options
96+
- **Returns**: `Promise<OauthTokens | TokenExchangeErrorResponse | AuthorizationError | GenericError>` - The tokens or an error
97+
98+
```js
99+
const tokens = await oidcClient.token.get();
100+
if ('error' in tokens) {
101+
console.error('Token retrieval failed:', tokens.error);
102+
}
103+
```
104+
105+
#### `token.revoke()`
106+
107+
Revokes the access token using the revocation endpoint from the wellknown configuration. Requires an access token stored in the configured storage.
108+
109+
- **Parameters**: None
110+
- **Returns**: `Promise<GenericError | RevokeSuccessResult | RevokeErrorResult>` - Confirmation of revocation or an error
111+
112+
```js
113+
const response = await oidcClient.token.revoke();
114+
if ('error' in response) {
115+
console.error('Token revocation failed:', response.error);
116+
}
117+
```
118+
119+
### user
120+
121+
Methods for user information and session management.
122+
123+
#### `user.info()`
124+
125+
Retrieves user information using the userinfo endpoint from the wellknown configuration. Requires an access token stored in the configured storage.
126+
127+
- **Parameters**: None
128+
- **Returns**: `Promise<GenericError | UserInfoResponse>` - User information object or an error
129+
130+
```js
131+
const user = await oidcClient.user.info();
132+
if ('error' in user) {
133+
console.error('Failed to fetch user info:', user.error);
134+
}
135+
```
136+
137+
#### `user.logout()`
138+
139+
Logs out the user by revoking tokens and clearing the storage. Uses the end session endpoint from the wellknown configuration.
140+
141+
- **Parameters**: None
142+
- **Returns**: `Promise<GenericError | LogoutSuccessResult | LogoutErrorResult>` - Confirmation of logout or an error
143+
144+
```js
145+
const logoutResponse = await oidcClient.user.logout();
146+
if ('error' in logoutResponse) {
147+
console.error('Logout failed:', logoutResponse.error);
148+
}
27149
```

0 commit comments

Comments
 (0)