@edirect/oidc-client 11.0.48 → 11.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -24
- package/dist/README.md +29 -122
- package/dist/package.json +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ import OidcClient from '@edirect/oidc-client';
|
|
|
28
28
|
|
|
29
29
|
const client = await OidcClient({
|
|
30
30
|
grantType: 'password',
|
|
31
|
-
baseUrl: process.env.OIDC_PROVIDER_URL,
|
|
32
|
-
oidcPath: process.env.OIDC_PROVIDER_PATH,
|
|
31
|
+
baseUrl: process.env.OIDC_PROVIDER_URL, // e.g., 'https://keycloak.example.com'
|
|
32
|
+
oidcPath: process.env.OIDC_PROVIDER_PATH, // e.g., '/realms/my-realm'
|
|
33
33
|
clientId: process.env.OIDC_CLIENT_ID,
|
|
34
34
|
clientSecret: process.env.OIDC_CLIENT_SECRET,
|
|
35
35
|
});
|
|
@@ -92,21 +92,21 @@ const tokenSet = await client.getAccessToken({ code: authorizationCode });
|
|
|
92
92
|
|
|
93
93
|
Factory function that initializes the OIDC client for the specified grant type.
|
|
94
94
|
|
|
95
|
-
| Parameter
|
|
96
|
-
|
|
97
|
-
| `grantType`
|
|
98
|
-
| `baseUrl`
|
|
99
|
-
| `oidcPath`
|
|
100
|
-
| `clientId`
|
|
101
|
-
| `clientSecret` | `string`
|
|
102
|
-
| `redirectUri`
|
|
95
|
+
| Parameter | Type | Description |
|
|
96
|
+
| -------------- | --------------------------------------------- | ------------------------------------------ |
|
|
97
|
+
| `grantType` | `'password' \| 'client_credentials' \| 'sso'` | OAuth2 grant type |
|
|
98
|
+
| `baseUrl` | `string` | OIDC provider base URL |
|
|
99
|
+
| `oidcPath` | `string` | OIDC realm path (e.g., `/realms/my-realm`) |
|
|
100
|
+
| `clientId` | `string` | Client ID registered in the OIDC provider |
|
|
101
|
+
| `clientSecret` | `string` | Client secret |
|
|
102
|
+
| `redirectUri` | `string` | Callback URL (for `sso` grant) |
|
|
103
103
|
|
|
104
104
|
### Client Methods
|
|
105
105
|
|
|
106
|
-
| Method
|
|
107
|
-
|
|
108
|
-
| `getAccessToken`
|
|
109
|
-
| `getRefreshToken` | `(tokenSet) => Promise<TokenSet>`
|
|
106
|
+
| Method | Signature | Description |
|
|
107
|
+
| ----------------- | ----------------------------------- | ------------------------------------------------------------ |
|
|
108
|
+
| `getAccessToken` | `(loginData?) => Promise<TokenSet>` | Acquire an access token |
|
|
109
|
+
| `getRefreshToken` | `(tokenSet) => Promise<TokenSet>` | Refresh an existing token set (not for `client_credentials`) |
|
|
110
110
|
|
|
111
111
|
### `TokenSet`
|
|
112
112
|
|
|
@@ -115,7 +115,7 @@ interface TokenSet {
|
|
|
115
115
|
access_token: string;
|
|
116
116
|
token_type: string;
|
|
117
117
|
expires_in: number;
|
|
118
|
-
refresh_token?: string;
|
|
118
|
+
refresh_token?: string; // not present for client_credentials
|
|
119
119
|
refresh_expires_in?: number;
|
|
120
120
|
id_token?: string;
|
|
121
121
|
session_state?: string;
|
|
@@ -125,12 +125,12 @@ interface TokenSet {
|
|
|
125
125
|
|
|
126
126
|
## Environment Variables
|
|
127
127
|
|
|
128
|
-
| Variable
|
|
129
|
-
|
|
130
|
-
| `OIDC_PROVIDER_URL`
|
|
131
|
-
| `OIDC_PROVIDER_PATH` | OIDC realm path (e.g., `/realms/my-realm`)
|
|
132
|
-
| `OIDC_CLIENT_ID`
|
|
133
|
-
| `OIDC_CLIENT_SECRET` | Client secret
|
|
134
|
-
| `OIDC_USERNAME`
|
|
135
|
-
| `OIDC_PASSWORD`
|
|
136
|
-
| `OIDC_CALLBACK_URL`
|
|
128
|
+
| Variable | Description |
|
|
129
|
+
| -------------------- | ------------------------------------------------------------- |
|
|
130
|
+
| `OIDC_PROVIDER_URL` | OIDC provider base URL (e.g., `https://keycloak.example.com`) |
|
|
131
|
+
| `OIDC_PROVIDER_PATH` | OIDC realm path (e.g., `/realms/my-realm`) |
|
|
132
|
+
| `OIDC_CLIENT_ID` | Client ID |
|
|
133
|
+
| `OIDC_CLIENT_SECRET` | Client secret |
|
|
134
|
+
| `OIDC_USERNAME` | Username (for `password` grant) |
|
|
135
|
+
| `OIDC_PASSWORD` | Password (for `password` grant) |
|
|
136
|
+
| `OIDC_CALLBACK_URL` | Redirect URI (for `sso` grant) |
|
package/dist/README.md
CHANGED
|
@@ -1,136 +1,43 @@
|
|
|
1
1
|
# @edirect/oidc-client
|
|
2
2
|
|
|
3
|
-
OpenID Connect client for
|
|
3
|
+
OpenID Connect client for Edirect applications. Provides a simple interface for authenticating with OIDC providers, supporting multiple grant types and token management.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
- Token set parsing utilities
|
|
7
|
+
- Supports password, client_credentials, and other grant types
|
|
8
|
+
- Handles access and refresh tokens
|
|
9
|
+
- Integrates with Edirect config modules
|
|
11
10
|
|
|
12
11
|
## Installation
|
|
13
12
|
|
|
14
|
-
```
|
|
15
|
-
pnpm add @edirect/oidc-client
|
|
16
|
-
# or
|
|
13
|
+
```bash
|
|
17
14
|
npm install @edirect/oidc-client
|
|
18
15
|
```
|
|
19
16
|
|
|
20
17
|
## Usage
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(
|
|
45
|
-
|
|
46
|
-
// Refresh token (not available for client_credentials)
|
|
47
|
-
const refreshed = await client.getRefreshToken(tokenSet);
|
|
19
|
+
```js
|
|
20
|
+
(async () => {
|
|
21
|
+
const OidcClient = require('@edirect/oidc-client');
|
|
22
|
+
const oidcClient = await OidcClient({
|
|
23
|
+
grantType: 'password' | 'client_credentials' | 'authorization_code',
|
|
24
|
+
baseUrl: process.env.OIDC_PROVIDER_URL,
|
|
25
|
+
oidcPath: process.env.OIDC_PROVIDER_PATH,
|
|
26
|
+
clientId: process.env.OIDC_CLIENT_ID,
|
|
27
|
+
clientSecret: process.env.OIDC_CLIENT_SECRET,
|
|
28
|
+
redirectUri: process.env.OIDC_CALLBACK_URL,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const loginData = {
|
|
32
|
+
username: process.env.OIDC_USERNAME,
|
|
33
|
+
password: process.env.OIDC_PASSWORD,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const accessTokenSet = await oidcClient.getAccessToken(loginData);
|
|
37
|
+
console.log('\n', { accessTokenSet }, '\n');
|
|
38
|
+
|
|
39
|
+
// not applicable to client_credentials grant type
|
|
40
|
+
const refreshTokenSet = await oidcClient.getRefreshToken(accessTokenSet);
|
|
41
|
+
console.log('\n', { refreshTokenSet }, '\n');
|
|
42
|
+
})();
|
|
48
43
|
```
|
|
49
|
-
|
|
50
|
-
### Client Credentials Grant (service-to-service)
|
|
51
|
-
|
|
52
|
-
Used for machine-to-machine authentication:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import OidcClient from '@edirect/oidc-client';
|
|
56
|
-
|
|
57
|
-
const client = await OidcClient({
|
|
58
|
-
grantType: 'client_credentials',
|
|
59
|
-
baseUrl: process.env.OIDC_PROVIDER_URL,
|
|
60
|
-
oidcPath: process.env.OIDC_PROVIDER_PATH,
|
|
61
|
-
clientId: process.env.OIDC_CLIENT_ID,
|
|
62
|
-
clientSecret: process.env.OIDC_CLIENT_SECRET,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// No login data required for client_credentials
|
|
66
|
-
const tokenSet = await client.getAccessToken();
|
|
67
|
-
console.log(tokenSet.access_token);
|
|
68
|
-
|
|
69
|
-
// Note: getRefreshToken is not applicable to client_credentials
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### SSO Grant
|
|
73
|
-
|
|
74
|
-
Used for SSO-based authentication flows:
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
const client = await OidcClient({
|
|
78
|
-
grantType: 'sso',
|
|
79
|
-
baseUrl: process.env.OIDC_PROVIDER_URL,
|
|
80
|
-
oidcPath: process.env.OIDC_PROVIDER_PATH,
|
|
81
|
-
clientId: process.env.OIDC_CLIENT_ID,
|
|
82
|
-
clientSecret: process.env.OIDC_CLIENT_SECRET,
|
|
83
|
-
redirectUri: process.env.OIDC_CALLBACK_URL,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const tokenSet = await client.getAccessToken({ code: authorizationCode });
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## API
|
|
90
|
-
|
|
91
|
-
### `OidcClient(params: Connect): Promise<OidcConnect>`
|
|
92
|
-
|
|
93
|
-
Factory function that initializes the OIDC client for the specified grant type.
|
|
94
|
-
|
|
95
|
-
| Parameter | Type | Description |
|
|
96
|
-
|-----------|------|-------------|
|
|
97
|
-
| `grantType` | `'password' \| 'client_credentials' \| 'sso'` | OAuth2 grant type |
|
|
98
|
-
| `baseUrl` | `string` | OIDC provider base URL |
|
|
99
|
-
| `oidcPath` | `string` | OIDC realm path (e.g., `/realms/my-realm`) |
|
|
100
|
-
| `clientId` | `string` | Client ID registered in the OIDC provider |
|
|
101
|
-
| `clientSecret` | `string` | Client secret |
|
|
102
|
-
| `redirectUri` | `string` | Callback URL (for `sso` grant) |
|
|
103
|
-
|
|
104
|
-
### Client Methods
|
|
105
|
-
|
|
106
|
-
| Method | Signature | Description |
|
|
107
|
-
|--------|-----------|-------------|
|
|
108
|
-
| `getAccessToken` | `(loginData?) => Promise<TokenSet>` | Acquire an access token |
|
|
109
|
-
| `getRefreshToken` | `(tokenSet) => Promise<TokenSet>` | Refresh an existing token set (not for `client_credentials`) |
|
|
110
|
-
|
|
111
|
-
### `TokenSet`
|
|
112
|
-
|
|
113
|
-
```ts
|
|
114
|
-
interface TokenSet {
|
|
115
|
-
access_token: string;
|
|
116
|
-
token_type: string;
|
|
117
|
-
expires_in: number;
|
|
118
|
-
refresh_token?: string; // not present for client_credentials
|
|
119
|
-
refresh_expires_in?: number;
|
|
120
|
-
id_token?: string;
|
|
121
|
-
session_state?: string;
|
|
122
|
-
scope?: string;
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Environment Variables
|
|
127
|
-
|
|
128
|
-
| Variable | Description |
|
|
129
|
-
|----------|-------------|
|
|
130
|
-
| `OIDC_PROVIDER_URL` | OIDC provider base URL (e.g., `https://keycloak.example.com`) |
|
|
131
|
-
| `OIDC_PROVIDER_PATH` | OIDC realm path (e.g., `/realms/my-realm`) |
|
|
132
|
-
| `OIDC_CLIENT_ID` | Client ID |
|
|
133
|
-
| `OIDC_CLIENT_SECRET` | Client secret |
|
|
134
|
-
| `OIDC_USERNAME` | Username (for `password` grant) |
|
|
135
|
-
| `OIDC_PASSWORD` | Password (for `password` grant) |
|
|
136
|
-
| `OIDC_CALLBACK_URL` | Redirect URI (for `sso` grant) |
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/oidc-client",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.46",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"openid-client": "^6.8.
|
|
19
|
+
"openid-client": "^6.8.1",
|
|
20
20
|
"tslib": "^2.8.1"
|
|
21
21
|
},
|
|
22
22
|
"type": "commonjs"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/oidc-client",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.50",
|
|
4
4
|
"packageScope": "@edirect",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -42,4 +42,4 @@
|
|
|
42
42
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
43
43
|
"build": "pnpm run build:cjs && pnpm run build:esm"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|