@webex/plugin-authorization-node 3.8.1 → 3.9.0-multipleLLM.1
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/NODE-OAUTH-FLOW-GUIDE.md +257 -0
- package/README.md +69 -23
- package/dist/authorization.js +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# Webex Node.js OAuth Authorization Flow - Technical Guide
|
|
2
|
+
|
|
3
|
+
This document explains how the Webex SDK handles OAuth authorization in Node.js environments, covering server-side authentication flows and token management.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
[Node.js Webex Initialization](#1-nodejs-webex-initialization)
|
|
8
|
+
[Node.js OAuth Flow Types](#2-nodejs-oauth-flow-types)
|
|
9
|
+
[Authorization Code Exchange](#3-authorization-code-exchange)
|
|
10
|
+
[Server-Side Token Management](#4-server-side-token-management)
|
|
11
|
+
[Node.js Refresh Token Management](#5-nodejs-refresh-token-management)
|
|
12
|
+
[Node.js Ready and Authorization Events](#6-nodejs-ready-and-authorization-events)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 1. Node.js Webex Initialization
|
|
17
|
+
|
|
18
|
+
### 1.1 Basic Node.js Setup
|
|
19
|
+
|
|
20
|
+
Node.js applications initialize the Webex SDK with server-side OAuth parameters:
|
|
21
|
+
|
|
22
|
+
- **client_id**: Your registered application ID
|
|
23
|
+
- **client_secret**: Your application's client secret (required for server-side)
|
|
24
|
+
- **scope**: Requested permissions (e.g., 'spark:all spark:kms')
|
|
25
|
+
- **clientType**: 'confidential' (default for Node.js)
|
|
26
|
+
|
|
27
|
+
**Reference**: See `packages/@webex/plugin-authorization-node/README.md` for Node.js specific configuration
|
|
28
|
+
|
|
29
|
+
### 1.2 Node.js Environment Detection
|
|
30
|
+
|
|
31
|
+
The SDK automatically loads the Node.js authorization plugin:
|
|
32
|
+
|
|
33
|
+
- **Environment**: Detects Node.js runtime automatically
|
|
34
|
+
- **Plugin**: Loads `@webex/plugin-authorization-node`
|
|
35
|
+
- **Flow Type**: Defaults to Authorization Code Grant (confidential client)
|
|
36
|
+
|
|
37
|
+
**Reference**: Main authorization plugin in `packages/@webex/plugin-authorization/README.md`
|
|
38
|
+
|
|
39
|
+
### 1.3 Node.js vs Browser Differences
|
|
40
|
+
|
|
41
|
+
#### Node.js Environment Benefits
|
|
42
|
+
|
|
43
|
+
- **Security**: Client secret can be safely stored server-side
|
|
44
|
+
- **Token Management**: Enhanced server-side token handling
|
|
45
|
+
- **No URL Parsing**: No need to parse browser URLs for tokens
|
|
46
|
+
- **Server-to-Server**: Direct API authentication without user interaction
|
|
47
|
+
|
|
48
|
+
#### Node.js Limitations
|
|
49
|
+
|
|
50
|
+
- **No Browser Redirects**: Cannot redirect users to OAuth pages
|
|
51
|
+
- **Backend Only**: Requires separate frontend for user authentication flows
|
|
52
|
+
- **Server Infrastructure**: Needs server environment to run
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 2. Node.js OAuth Flow Types
|
|
57
|
+
|
|
58
|
+
### 2.1 Authorization Code Grant (Primary)
|
|
59
|
+
|
|
60
|
+
Node.js primarily uses Authorization Code Grant:
|
|
61
|
+
|
|
62
|
+
1. **Frontend initiates**: Browser redirects user to OAuth provider
|
|
63
|
+
2. **User authenticates**: At Webex identity broker
|
|
64
|
+
3. **Code received**: Authorization code sent to redirect URI
|
|
65
|
+
4. **Backend exchange**: Node.js exchanges code for tokens using client secret
|
|
66
|
+
|
|
67
|
+
### 2.2 JWT Authentication (Server-to-Server)
|
|
68
|
+
|
|
69
|
+
Node.js JWT authentication for guest/bot scenarios:
|
|
70
|
+
|
|
71
|
+
1. **Create JWT**: Server creates JWT with guest issuer credentials
|
|
72
|
+
2. **Exchange for token**: JWT exchanged for Webex access token
|
|
73
|
+
3. **API access**: Use access token for Webex API calls
|
|
74
|
+
|
|
75
|
+
**Reference**: JWT methods in Node.js authorization plugin
|
|
76
|
+
|
|
77
|
+
### 2.3 Client Credentials Flow
|
|
78
|
+
|
|
79
|
+
For server-to-server authentication without user context:
|
|
80
|
+
|
|
81
|
+
1. **Direct token request**: Using client_id and client_secret
|
|
82
|
+
2. **No user involvement**: Pure server-to-server authentication
|
|
83
|
+
3. **Limited scope**: Typically restricted to bot/integration scopes
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 3. Authorization Code Exchange
|
|
88
|
+
|
|
89
|
+
### 3.1 Node.js Code Reception
|
|
90
|
+
|
|
91
|
+
In Node.js environment, authorization code is received via:
|
|
92
|
+
|
|
93
|
+
1. **Redirect URI endpoint**: Your server handles the OAuth callback
|
|
94
|
+
2. **Code extraction**: Extract `code` parameter from query string
|
|
95
|
+
3. **State validation**: Verify state parameter for CSRF protection
|
|
96
|
+
4. **Error handling**: Check for OAuth error parameters
|
|
97
|
+
|
|
98
|
+
### 3.2 Node.js Token Exchange Process
|
|
99
|
+
|
|
100
|
+
Node.js performs secure token exchange:
|
|
101
|
+
|
|
102
|
+
1. **POST request** to OAuth token endpoint
|
|
103
|
+
2. **Parameters**:
|
|
104
|
+
- grant_type: "authorization_code"
|
|
105
|
+
- client_id: Your application ID
|
|
106
|
+
- client_secret: Your application secret
|
|
107
|
+
- code: Authorization code received
|
|
108
|
+
- redirect_uri: Must match registered URI
|
|
109
|
+
|
|
110
|
+
### 3.3 Node.js Token Response
|
|
111
|
+
|
|
112
|
+
Successful exchange returns:
|
|
113
|
+
|
|
114
|
+
- **access_token**: For API authorization
|
|
115
|
+
- **refresh_token**: For token renewal
|
|
116
|
+
- **expires_in**: Token lifetime in seconds
|
|
117
|
+
- **token_type**: Usually "Bearer"
|
|
118
|
+
- **scope**: Granted permissions
|
|
119
|
+
|
|
120
|
+
**Reference**: Token exchange implementation in Node.js authorization plugin
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 4. Server-Side Token Management
|
|
125
|
+
|
|
126
|
+
### 4.1 Node.js Token Storage
|
|
127
|
+
|
|
128
|
+
Node.js token storage considerations:
|
|
129
|
+
|
|
130
|
+
1. **Secure storage**: Database, encrypted files, or secure key stores
|
|
131
|
+
2. **User association**: Link tokens to specific user accounts
|
|
132
|
+
3. **Session management**: Associate tokens with user sessions
|
|
133
|
+
4. **Encryption**: Encrypt tokens at rest
|
|
134
|
+
|
|
135
|
+
### 4.2 Node.js Supertoken Structure
|
|
136
|
+
|
|
137
|
+
Node.js can create enhanced supertoken structures:
|
|
138
|
+
|
|
139
|
+
- **Standard OAuth tokens**: access_token, refresh_token
|
|
140
|
+
- **Metadata**: User information, scope details
|
|
141
|
+
- **Expiration tracking**: Calculated expiry times
|
|
142
|
+
- **Custom fields**: Application-specific data
|
|
143
|
+
|
|
144
|
+
### 4.3 Node.js Token Validation
|
|
145
|
+
|
|
146
|
+
Server-side token validation:
|
|
147
|
+
|
|
148
|
+
1. **Expiry checking**: Validate token hasn't expired
|
|
149
|
+
2. **Scope verification**: Ensure token has required permissions
|
|
150
|
+
3. **Refresh triggers**: Automatic refresh when near expiry
|
|
151
|
+
4. **Error handling**: Handle invalid or revoked tokens
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 5. Node.js Refresh Token Management
|
|
156
|
+
|
|
157
|
+
### 5.1 Node.js Token Expiration Monitoring
|
|
158
|
+
|
|
159
|
+
Node.js monitors token expiration through:
|
|
160
|
+
|
|
161
|
+
- **Scheduled checks**: Periodic token validity verification
|
|
162
|
+
- **API response monitoring**: Watch for 401 Unauthorized responses
|
|
163
|
+
- **Proactive refresh**: Refresh before expiration
|
|
164
|
+
- **Retry logic**: Automatic retry with refreshed tokens
|
|
165
|
+
|
|
166
|
+
### 5.2 Node.js Refresh Process
|
|
167
|
+
|
|
168
|
+
Server-side refresh token flow:
|
|
169
|
+
|
|
170
|
+
1. **POST request** to token endpoint
|
|
171
|
+
2. **Parameters**:
|
|
172
|
+
- grant_type: "refresh_token"
|
|
173
|
+
- refresh_token: Current refresh token
|
|
174
|
+
- client_id: Application identifier
|
|
175
|
+
- client_secret: Application secret
|
|
176
|
+
|
|
177
|
+
### 5.3 Node.js Refresh Response Handling
|
|
178
|
+
|
|
179
|
+
Handle refresh response:
|
|
180
|
+
|
|
181
|
+
1. **Update stored tokens**: Replace old tokens with new ones
|
|
182
|
+
2. **Update user sessions**: Refresh tokens in active sessions
|
|
183
|
+
3. **Handle refresh failure**: Re-authenticate user if refresh fails
|
|
184
|
+
4. **Concurrent requests**: Handle multiple simultaneous refresh attempts
|
|
185
|
+
|
|
186
|
+
### 5.4 Node.js JWT Refresh
|
|
187
|
+
|
|
188
|
+
For JWT-based authentication:
|
|
189
|
+
|
|
190
|
+
1. **JWT expiration monitoring**: Track JWT token expiry
|
|
191
|
+
2. **Automatic renewal**: Create new JWT when needed
|
|
192
|
+
3. **Re-exchange process**: Exchange new JWT for fresh access token
|
|
193
|
+
4. **Callback integration**: Use jwtRefreshCallback for automation
|
|
194
|
+
|
|
195
|
+
**Reference**: JWT refresh implementation in Node.js authorization plugin
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 6. Node.js Ready and Authorization Events
|
|
200
|
+
|
|
201
|
+
### 6.1 Node.js SDK Initialization
|
|
202
|
+
|
|
203
|
+
Node.js SDK initialization phases:
|
|
204
|
+
|
|
205
|
+
1. **Module loading**: Load required Node.js modules
|
|
206
|
+
2. **Plugin initialization**: Initialize Node.js authorization plugin
|
|
207
|
+
3. **Configuration validation**: Validate client credentials
|
|
208
|
+
4. **Service discovery**: Load Webex service endpoints
|
|
209
|
+
5. **Ready state**: SDK ready for API calls
|
|
210
|
+
|
|
211
|
+
### 6.2 Node.js Authorization Events
|
|
212
|
+
|
|
213
|
+
Node.js-specific events:
|
|
214
|
+
|
|
215
|
+
- **ready**: SDK initialized and ready for requests
|
|
216
|
+
- **unauthorized**: Token invalid or expired
|
|
217
|
+
- **token:refresh**: Token has been refreshed
|
|
218
|
+
- **auth:error**: Authentication error occurred
|
|
219
|
+
|
|
220
|
+
### 6.3 Node.js Authentication Status
|
|
221
|
+
|
|
222
|
+
Check Node.js authentication status:
|
|
223
|
+
|
|
224
|
+
- `webex.canAuthorize`: Boolean for authenticated request capability
|
|
225
|
+
- `webex.credentials.supertoken`: Current token information
|
|
226
|
+
- `webex.ready`: Boolean for SDK initialization complete
|
|
227
|
+
|
|
228
|
+
### 6.4 Node.js Error Handling
|
|
229
|
+
|
|
230
|
+
Node.js specific error scenarios:
|
|
231
|
+
|
|
232
|
+
1. **Invalid client credentials**: Wrong client_id or client_secret
|
|
233
|
+
2. **Network failures**: Connection issues to Webex APIs
|
|
234
|
+
3. **Token expiry**: Handle expired tokens gracefully
|
|
235
|
+
4. **Rate limiting**: Handle API rate limit responses
|
|
236
|
+
5. **Service unavailability**: Handle Webex service outages
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Node.js Code References
|
|
241
|
+
|
|
242
|
+
- **Main Node.js Plugin**: `packages/@webex/plugin-authorization-node/`
|
|
243
|
+
- **Node.js Plugin Docs**: `packages/@webex/plugin-authorization-node/README.md`
|
|
244
|
+
- **WebexCore**: `packages/@webex/webex-core/src/webex-core.js`
|
|
245
|
+
- **Common Authorization**: `packages/@webex/plugin-authorization/README.md`
|
|
246
|
+
|
|
247
|
+
## Maintainers
|
|
248
|
+
|
|
249
|
+
This package is maintained by [Cisco Webex for Developers](https://developer.webex.com/).
|
|
250
|
+
|
|
251
|
+
## Contribute
|
|
252
|
+
|
|
253
|
+
Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/webex-js-sdk/blob/master/CONTRIBUTING.md) for more details.
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
© 2016-2025 Cisco and/or its affiliates. All Rights Reserved.
|
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# @webex/plugin-authorization-node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
> Authorization plugin loaded when the Cisco Webex JS SDK is used in a non-browser environment.
|
|
6
|
-
|
|
7
|
-
- [Install](#install)
|
|
8
|
-
- [Usage](#usage)
|
|
9
|
-
- [Contribute](#contribute)
|
|
10
|
-
- [Maintainers](#maintainers)
|
|
11
|
-
- [License](#license)
|
|
3
|
+
This package provides authentication functionality for Node.js applications using the Webex SDK.
|
|
12
4
|
|
|
13
5
|
## Install
|
|
14
6
|
|
|
@@ -18,27 +10,81 @@ npm install --save @webex/plugin-authorization-node
|
|
|
18
10
|
|
|
19
11
|
## Usage
|
|
20
12
|
|
|
21
|
-
This is a plugin for the Cisco Webex JS SDK
|
|
13
|
+
This is a plugin for the Cisco Webex JS SDK. Please see our developer portal and the API docs for full details.
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
```js
|
|
16
|
+
const Webex = require('webex');
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const webex = Webex.init({
|
|
19
|
+
credentials: {
|
|
20
|
+
client_id: 'your-client-id',
|
|
21
|
+
client_secret: 'your-client-secret'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Exchange authorization code for access token
|
|
26
|
+
webex.authorization.requestAuthorizationCodeGrant({
|
|
27
|
+
code: 'authorization-code'
|
|
28
|
+
}).then(() => {
|
|
29
|
+
console.log('Authentication successful');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Use JWT for authentication
|
|
33
|
+
webex.authorization.requestAccessTokenFromJwt({
|
|
34
|
+
jwt: 'your-jwt-token'
|
|
35
|
+
}).then(() => {
|
|
36
|
+
console.log('JWT authentication successful');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Create JWT token
|
|
40
|
+
webex.authorization.createJwt({
|
|
41
|
+
issuer: 'guest-issuer-id',
|
|
42
|
+
secretId: 'base64-encoded-secret',
|
|
43
|
+
displayName: 'Guest User',
|
|
44
|
+
expiresIn: '12h'
|
|
45
|
+
}).then(({jwt}) => {
|
|
46
|
+
console.log('JWT created:', jwt);
|
|
47
|
+
});
|
|
27
48
|
```
|
|
28
49
|
|
|
29
|
-
##
|
|
50
|
+
## Methods
|
|
30
51
|
|
|
31
|
-
|
|
52
|
+
### requestAuthorizationCodeGrant(options)
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
Exchanges an authorization code for an access token.
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
webex.authorization-node.get(id)
|
|
37
|
-
.then((authorization-node) => {
|
|
38
|
-
console.log(authorization-node);
|
|
39
|
-
})
|
|
56
|
+
- `options.code` - The authorization code received from the provider
|
|
40
57
|
|
|
41
|
-
|
|
58
|
+
### requestAccessTokenFromJwt(options)
|
|
59
|
+
|
|
60
|
+
Requests access token using JWT.
|
|
61
|
+
|
|
62
|
+
- `options.jwt` - JWT token for authentication
|
|
63
|
+
|
|
64
|
+
### createJwt(options)
|
|
65
|
+
|
|
66
|
+
Creates a JWT token.
|
|
67
|
+
|
|
68
|
+
- `options.issuer` - Guest issuer ID
|
|
69
|
+
- `options.secretId` - Base64 encoded secret
|
|
70
|
+
- `options.displayName` - Display name (optional)
|
|
71
|
+
- `options.expiresIn` - Token expiration time
|
|
72
|
+
|
|
73
|
+
### logout(options)
|
|
74
|
+
|
|
75
|
+
Logs out the current user.
|
|
76
|
+
|
|
77
|
+
- `options.token` - Token to invalidate (optional)
|
|
78
|
+
|
|
79
|
+
## Properties
|
|
80
|
+
|
|
81
|
+
### isAuthorizing
|
|
82
|
+
|
|
83
|
+
Boolean indicating if authorization is in progress.
|
|
84
|
+
|
|
85
|
+
### isAuthenticating
|
|
86
|
+
|
|
87
|
+
Alias for isAuthorizing.
|
|
42
88
|
|
|
43
89
|
## Maintainers
|
|
44
90
|
|
|
@@ -50,4 +96,4 @@ Pull requests welcome. Please see [CONTRIBUTING.md](https://github.com/webex/web
|
|
|
50
96
|
|
|
51
97
|
## License
|
|
52
98
|
|
|
53
|
-
© 2016-
|
|
99
|
+
© 2016-2025 Cisco and/or its affiliates. All Rights Reserved.
|
package/dist/authorization.js
CHANGED
|
@@ -181,7 +181,7 @@ var Authorization = _webexCore.WebexPlugin.extend((_dec = (0, _common.whileInFli
|
|
|
181
181
|
return _promise.default.reject(e);
|
|
182
182
|
}
|
|
183
183
|
},
|
|
184
|
-
version: "3.
|
|
184
|
+
version: "3.9.0-multipleLLM.1"
|
|
185
185
|
}, ((0, _applyDecoratedDescriptor2.default)(_obj, "requestAuthorizationCodeGrant", [_dec, _common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "requestAuthorizationCodeGrant"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "requestAccessTokenFromJwt", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "requestAccessTokenFromJwt"), _obj)), _obj)));
|
|
186
186
|
var _default = exports.default = Authorization;
|
|
187
187
|
//# sourceMappingURL=authorization.js.map
|
package/package.json
CHANGED
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
26
26
|
"@webex/jest-config-legacy": "0.0.0",
|
|
27
27
|
"@webex/legacy-tools": "0.0.0",
|
|
28
|
-
"@webex/test-helper-appid": "3.
|
|
29
|
-
"@webex/test-helper-chai": "3.
|
|
30
|
-
"@webex/test-helper-mocha": "3.
|
|
31
|
-
"@webex/test-helper-mock-webex": "3.
|
|
32
|
-
"@webex/test-helper-test-users": "3.
|
|
28
|
+
"@webex/test-helper-appid": "3.9.0-multipleLLM.0",
|
|
29
|
+
"@webex/test-helper-chai": "3.9.0-multipleLLM.0",
|
|
30
|
+
"@webex/test-helper-mocha": "3.9.0-multipleLLM.0",
|
|
31
|
+
"@webex/test-helper-mock-webex": "3.9.0-multipleLLM.0",
|
|
32
|
+
"@webex/test-helper-test-users": "3.9.0-multipleLLM.0",
|
|
33
33
|
"eslint": "^8.24.0",
|
|
34
34
|
"prettier": "^2.7.1",
|
|
35
35
|
"sinon": "^9.2.4"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@webex/common": "3.
|
|
39
|
-
"@webex/internal-plugin-device": "3.
|
|
40
|
-
"@webex/webex-core": "3.
|
|
38
|
+
"@webex/common": "3.9.0-multipleLLM.0",
|
|
39
|
+
"@webex/internal-plugin-device": "3.9.0-multipleLLM.1",
|
|
40
|
+
"@webex/webex-core": "3.9.0-multipleLLM.1",
|
|
41
41
|
"jsonwebtoken": "^9.0.0",
|
|
42
42
|
"uuid": "^3.3.2"
|
|
43
43
|
},
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"test:style": "eslint ./src/**/*.*",
|
|
52
52
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
53
53
|
},
|
|
54
|
-
"version": "3.
|
|
54
|
+
"version": "3.9.0-multipleLLM.1"
|
|
55
55
|
}
|