@jacebenson/jsn 5.5.0 → 5.5.1-dev.157.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/auth.js +16 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.5.0",
3
+ "version": "5.5.1-dev.157.1",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/auth.js CHANGED
@@ -14,6 +14,10 @@ import { savePKCEState, loadPKCEState, removePKCEState, getOAuthClientID, genera
14
14
  import { parseBrowserSessionInput } from './auth/browser-session.js';
15
15
  import { normalizeAuthMethod, normalizeAuthSource, sourceMethod, probeFailure, classifyProbeError, classifyCredentialState } from './auth/credential-state.js';
16
16
 
17
+ // A profile in one of these credential states can make authenticated calls.
18
+ // `refreshable` refreshes at point of use; see isAuthenticated().
19
+ const AUTHENTICATED_STATES = new Set(['available', 'refreshable']);
20
+
17
21
  // Preserve the public auth module API while implementation stays separated.
18
22
  export { sanitizeKeyPart } from './auth/credential-store.js';
19
23
  export { parseBrowserSessionInput } from './auth/browser-session.js';
@@ -289,15 +293,25 @@ export class AuthManager {
289
293
  }
290
294
  }
291
295
 
296
+ /**
297
+ * Credential states that can produce a session count as authenticated.
298
+ *
299
+ * `refreshable` is an expired (or nearly expired) access token WITH a refresh
300
+ * token, which getCredentialsFor() refreshes at point of use — the refresh is
301
+ * already proved by the "expired OAuth refreshes at point of use" contract.
302
+ * Reporting those profiles as unauthenticated made `jsn auth status` disagree
303
+ * with every command that then ran fine, and made requireAuth() refuse a
304
+ * profile the next request would have refreshed.
305
+ */
292
306
  isAuthenticated() {
293
307
  const instance = this.identity.getEffectiveInstance();
294
308
  if (!instance) return false;
295
- return this.getAuthState(instance).state === 'available';
309
+ return AUTHENTICATED_STATES.has(this.getAuthState(instance).state);
296
310
  }
297
311
 
298
312
  isAuthenticatedFor(instance, options = {}) {
299
313
  if (!instance) return false;
300
- return this.getAuthState(instance, options).state === 'available';
314
+ return AUTHENTICATED_STATES.has(this.getAuthState(instance, options).state);
301
315
  }
302
316
 
303
317
  async getCredentials() {