ark-oauth-client-node 0.0.0-stage → 2.2.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/CHANGELOG.md +84 -0
- package/LICENSE +21 -0
- package/README.md +528 -2
- package/package.json +64 -4
- package/src/access.js +234 -0
- package/src/app-config.js +73 -0
- package/src/client.js +780 -0
- package/src/config.js +164 -0
- package/src/crypto.js +59 -0
- package/src/denied-page.js +83 -0
- package/src/discovery.js +101 -0
- package/src/errors.js +88 -0
- package/src/express.js +820 -0
- package/src/http.js +153 -0
- package/src/index.js +42 -0
- package/src/jwks.js +122 -0
- package/src/jwt.js +294 -0
- package/src/pkce.js +42 -0
- package/src/session.js +135 -0
- package/src/tokens.js +120 -0
- package/src/version.js +10 -0
- package/types/index.d.ts +672 -0
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ark-oauth-client-node",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.2.1",
|
|
4
|
+
"description": "The OAuth 2.1 / OpenID Connect client for Node.js applications, built for Ark.oAuth.Oidc. Authorization code + PKCE with state, nonce, iss and at_hash checks, JWKS rotation, silent refresh, client credentials, the device grant, PAR, introspection, revocation, dynamic client registration and RP-initiated logout \u2014 plus Express/Connect middleware for interactive sign-in, account switching on a shared browser, and protecting an API. No runtime dependencies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"oauth",
|
|
7
|
+
"oauth2",
|
|
8
|
+
"oidc",
|
|
9
|
+
"openid-connect",
|
|
10
|
+
"pkce",
|
|
11
|
+
"jwt",
|
|
12
|
+
"jwks",
|
|
13
|
+
"authentication",
|
|
14
|
+
"express",
|
|
15
|
+
"ark"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Immanuel R",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/ir-dev/ark-oauth-oidc.git",
|
|
22
|
+
"directory": "ark_oauth_client_nodejs"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/ir-dev/ark-oauth-oidc/tree/main/ark_oauth_client_nodejs#readme",
|
|
25
|
+
"bugs": "https://github.com/ir-dev/ark-oauth-oidc/issues",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./src/index.js",
|
|
28
|
+
"types": "./types/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./types/index.d.ts",
|
|
32
|
+
"default": "./src/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./express": {
|
|
35
|
+
"types": "./types/index.d.ts",
|
|
36
|
+
"default": "./src/express.js"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"src",
|
|
42
|
+
"types",
|
|
43
|
+
"README.md",
|
|
44
|
+
"CHANGELOG.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20.0.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"test": "node --test \"test/*.test.js\"",
|
|
55
|
+
"test:watch": "node --test --watch \"test/*.test.js\"",
|
|
56
|
+
"example:web": "node examples/web-app.js",
|
|
57
|
+
"example:api": "node examples/api-server.js",
|
|
58
|
+
"example:device": "node examples/device-flow.js",
|
|
59
|
+
"example:setup": "node examples/setup-check.js",
|
|
60
|
+
"example:switch": "node examples/account-switch.js"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/node": ">=20"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/access.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, hkdfSync, randomBytes } from 'node:crypto';
|
|
2
|
+
import { base64UrlDecode, base64UrlEncode } from './crypto.js';
|
|
3
|
+
import { ArkConfigError } from './errors.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Account switching on a shared browser, and the page that makes it recoverable.
|
|
7
|
+
*
|
|
8
|
+
* Single sign-on is browser-wide: once one person signs in anywhere, the provider's session answers
|
|
9
|
+
* the authorize request of every other client in that browser. A second person opens this
|
|
10
|
+
* application, is silently signed in as the first, and is told they have no access — for an account
|
|
11
|
+
* that is not even theirs. The sign-in link goes back to the same session and gives the same answer,
|
|
12
|
+
* so the loop only ends when somebody knows to clear cookies.
|
|
13
|
+
*
|
|
14
|
+
* Breaking it needs two things, and both live here: a dead end that is honest about whose session
|
|
15
|
+
* it is, and a challenge that says `prompt=login` — the one parameter a provider must honour by
|
|
16
|
+
* ignoring its session and drawing the sign-in form (OIDC Core §3.1.2.1).
|
|
17
|
+
*
|
|
18
|
+
* The same feature, under the same names, as `AccountSwitch` in the .NET client and
|
|
19
|
+
* `account_switch` in the Python one. Every part is off or unchanged by default.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** Why a user was sent to the access-denied page. */
|
|
23
|
+
export const ArkAccessDeniedReasons = Object.freeze({
|
|
24
|
+
/** The provider authenticated them, but they hold no authorization claims for this client. */
|
|
25
|
+
NO_APP_ACCESS: 'no_app_access',
|
|
26
|
+
/** They are signed in here, but a guard refused the page they asked for. */
|
|
27
|
+
FORBIDDEN: 'forbidden'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const ACCOUNT_SWITCH_DEFAULTS = Object.freeze({
|
|
31
|
+
/** Serve the three endpoints below, and send an HTML 403 to the page rather than a JSON body. */
|
|
32
|
+
enabled: true,
|
|
33
|
+
/**
|
|
34
|
+
* Refuse the sign-in when the provider issues no `ark_claims` for this client. Off, the wrong
|
|
35
|
+
* account is signed in and every guarded page answers 403. On, the callback is stopped before the
|
|
36
|
+
* session is written and the user is sent to `accessDeniedPath`, where they can switch.
|
|
37
|
+
*/
|
|
38
|
+
requireArkClaims: false,
|
|
39
|
+
/** Narrow that check: at least one of these claim values. Empty means any `ark_claims` will do. */
|
|
40
|
+
requiredClaims: Object.freeze([]),
|
|
41
|
+
accessDeniedPath: '/ark/no-access',
|
|
42
|
+
switchUserPath: '/ark/switch-user',
|
|
43
|
+
signOutPath: '/ark/sign-out',
|
|
44
|
+
/** Draw the built-in page. Turn off when `accessDeniedPath` is a route of your own. */
|
|
45
|
+
serveDefaultPage: true,
|
|
46
|
+
/** The application's name as users know it. Defaults to the client id. */
|
|
47
|
+
appDisplayName: null,
|
|
48
|
+
/** Name the signed-in account on the page — on a shared browser, somebody else's address. */
|
|
49
|
+
showSignedInAccount: true,
|
|
50
|
+
/** Offer "Sign out completely" beside "Sign in as a different user". */
|
|
51
|
+
allowFullSignOut: true,
|
|
52
|
+
/**
|
|
53
|
+
* Make switching a full RP-initiated logout. Off, only this application's session is dropped and
|
|
54
|
+
* the previous user's other tabs are left alone; on, they are signed out of everything — right for
|
|
55
|
+
* a kiosk, heavy-handed for a laptop.
|
|
56
|
+
*/
|
|
57
|
+
endProviderSessionOnSwitch: false,
|
|
58
|
+
/** Sent as `prompt` when switching. `login` is the one every provider honours. */
|
|
59
|
+
prompt: 'login',
|
|
60
|
+
/** "Back to safety", and the fallback for an absent or off-site return URL. */
|
|
61
|
+
homePath: '/',
|
|
62
|
+
supportUrl: null,
|
|
63
|
+
supportEmail: null
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const PATH_SETTINGS = ['accessDeniedPath', 'switchUserPath', 'signOutPath', 'homePath'];
|
|
67
|
+
|
|
68
|
+
/** Fills in the defaults and refuses what could only fail later, in front of a user. */
|
|
69
|
+
export function normalizeAccountSwitch(options = {}) {
|
|
70
|
+
const merged = { ...ACCOUNT_SWITCH_DEFAULTS };
|
|
71
|
+
for (const [key, value] of Object.entries(options ?? {})) {
|
|
72
|
+
if (Object.hasOwn(ACCOUNT_SWITCH_DEFAULTS, key) && value !== undefined) merged[key] = value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const key of PATH_SETTINGS) {
|
|
76
|
+
if (localOrDefault(merged[key], null) !== merged[key]) {
|
|
77
|
+
throw new ArkConfigError(`ark_oauth_client: accountSwitch.${key} must be a local path starting with '/', but is '${merged[key]}'.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Rendered into an href: anything but http(s) would be a script URL waiting to be clicked.
|
|
81
|
+
if (merged.supportUrl && !/^https?:\/\//i.test(merged.supportUrl)) {
|
|
82
|
+
throw new ArkConfigError(`ark_oauth_client: accountSwitch.supportUrl must be an http(s) URL, but is '${merged.supportUrl}'.`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
merged.requiredClaims = Object.freeze([...(merged.requiredClaims ?? [])].map(String));
|
|
86
|
+
return Object.freeze(merged);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The authorization-request options that make "sign in as a different user" work. Without
|
|
91
|
+
* `prompt=login` the provider answers from the session it already has, and the wrong person is
|
|
92
|
+
* signed in again. The result is what `req.ark.login()` and `createAuthorizationUrl()` accept.
|
|
93
|
+
*/
|
|
94
|
+
export const ArkChallengeProperties = Object.freeze({
|
|
95
|
+
switchUser(returnUrl = null, loginHint = null, prompt = 'login') {
|
|
96
|
+
return { returnTo: returnUrl || '/', prompt: prompt || 'login', ...(loginHint ? { loginHint } : {}) };
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/** The provider's account picker. A provider without one falls back to its sign-in form. */
|
|
100
|
+
selectAccount(returnUrl = null) {
|
|
101
|
+
return ArkChallengeProperties.switchUser(returnUrl, null, 'select_account');
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Keeps a return URL inside this application. Echoing an arbitrary one would make the login route
|
|
107
|
+
* and the access-denied page open redirects — a phishing link that keeps your domain in the address
|
|
108
|
+
* bar right up to the moment it hands the user to somebody else.
|
|
109
|
+
*/
|
|
110
|
+
export function localOrDefault(url, fallback = '/') {
|
|
111
|
+
const home = typeof fallback === 'string' && fallback.trim() ? fallback : fallback === null ? null : '/';
|
|
112
|
+
if (typeof url !== 'string' || !url.trim()) return home;
|
|
113
|
+
const candidate = url.trim();
|
|
114
|
+
if (!candidate.startsWith('/') || candidate.startsWith('//')) return home;
|
|
115
|
+
// Browsers read `\` as `/`, so `/\evil.example` is `//evil.example` — another host. They also
|
|
116
|
+
// strip tabs and newlines before parsing, so `/\t/evil.example` collapses to the same thing.
|
|
117
|
+
if (candidate.startsWith('/\\')) return home;
|
|
118
|
+
// eslint-disable-next-line no-control-regex
|
|
119
|
+
if (/[\u0000-\u001f\u007f]/.test(candidate)) return home;
|
|
120
|
+
return candidate;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* POST, from this origin. Neither account endpoint is a security boundary — the worst a forged
|
|
125
|
+
* request achieves is an unwanted sign-out — but a cross-site page should not be able to end a
|
|
126
|
+
* user's session, and requiring a same-origin POST costs nothing.
|
|
127
|
+
*/
|
|
128
|
+
export function checkSameOrigin(method, headers, origin) {
|
|
129
|
+
if (String(method).toUpperCase() !== 'POST') return { ok: false, status: 405, message: 'POST required.' };
|
|
130
|
+
|
|
131
|
+
const fetchSite = headers?.['sec-fetch-site'];
|
|
132
|
+
if (fetchSite) {
|
|
133
|
+
return fetchSite === 'same-origin' || fetchSite === 'none'
|
|
134
|
+
? { ok: true }
|
|
135
|
+
: { ok: false, status: 400, message: 'cross-site request rejected.' };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const from = headers?.origin;
|
|
139
|
+
if (!from) return { ok: true }; // not a browser form post
|
|
140
|
+
const same = from.replace(/\/+$/, '').toLowerCase() === String(origin).replace(/\/+$/, '').toLowerCase();
|
|
141
|
+
return same ? { ok: true } : { ok: false, status: 400, message: 'cross-site request rejected.' };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The entitlement decision, made once per sign-in at the callback — not "may this user open that
|
|
146
|
+
* page" but "may this user use this application at all". Refusing there means no session is ever
|
|
147
|
+
* written, so the person at the keyboard is not left holding somebody else's.
|
|
148
|
+
*
|
|
149
|
+
* `onEvaluateAccess` replaces the configured rule rather than being ANDed with it; a handler that
|
|
150
|
+
* wants both reads `allowedByConfiguration` and says so.
|
|
151
|
+
*/
|
|
152
|
+
export async function evaluateAccess(options, events, { claims = {}, arkClaims = [], tokens = null } = {}) {
|
|
153
|
+
const required = options.requiredClaims.map((c) => c.toLowerCase());
|
|
154
|
+
const allowedByConfiguration =
|
|
155
|
+
!options.requireArkClaims ||
|
|
156
|
+
(required.length ? arkClaims.some((c) => required.includes(String(c).toLowerCase())) : arkClaims.length > 0);
|
|
157
|
+
|
|
158
|
+
if (!events?.onEvaluateAccess) return allowedByConfiguration;
|
|
159
|
+
return Boolean(
|
|
160
|
+
await events.onEvaluateAccess({ claims: { ...claims }, arkClaims: [...arkClaims], allowedByConfiguration, tokens })
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** What is known about a denial, read off whatever identity there is. */
|
|
165
|
+
export function describeDenial(reason, claims, arkClaims, returnUrl) {
|
|
166
|
+
const first = (...names) => {
|
|
167
|
+
for (const name of names) if (claims?.[name]) return String(claims[name]);
|
|
168
|
+
return null;
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
reason,
|
|
172
|
+
subject: first('sub'),
|
|
173
|
+
email: first('email', 'preferred_username'),
|
|
174
|
+
name: first('name'),
|
|
175
|
+
arkClaims: [...(arkClaims ?? [])],
|
|
176
|
+
returnUrl: returnUrl ?? null,
|
|
177
|
+
/** Set from `onAccessDenied` when the handler has written the response itself. */
|
|
178
|
+
handled: false
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function deniedUrl(options, returnUrl) {
|
|
183
|
+
const path = options.accessDeniedPath;
|
|
184
|
+
if (!returnUrl) return path;
|
|
185
|
+
return `${path}${path.includes('?') ? '&' : '?'}returnUrl=${encodeURIComponent(returnUrl)}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ---------------------------------------------------------------------------
|
|
189
|
+
// The denial cookie
|
|
190
|
+
// ---------------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Carries the refused identity from the callback to the page. The denial happens before any session
|
|
194
|
+
* is written — that is the point — so a short-lived cookie names the account instead: AES-256-GCM
|
|
195
|
+
* under a key derived from the session secret for this one purpose, so the browser cannot read it,
|
|
196
|
+
* tampering is detected rather than parsed, and it cannot be replayed as anything else. The format
|
|
197
|
+
* and key derivation are the Python client's, byte for byte.
|
|
198
|
+
*/
|
|
199
|
+
export const DENIED_COOKIE = 'ark_denied';
|
|
200
|
+
export const DENIED_MAX_AGE_SECONDS = 300;
|
|
201
|
+
const PURPOSE = Buffer.from('Ark.oAuth.Client.AccessDenied.v1', 'utf8');
|
|
202
|
+
|
|
203
|
+
function deniedKey(secret) {
|
|
204
|
+
return Buffer.from(hkdfSync('sha256', Buffer.from(String(secret), 'utf8'), Buffer.alloc(0), PURPOSE, 32));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function protectState(secret, payload) {
|
|
208
|
+
const nonce = randomBytes(12);
|
|
209
|
+
const cipher = createCipheriv('aes-256-gcm', deniedKey(secret), nonce, { authTagLength: 16 });
|
|
210
|
+
cipher.setAAD(PURPOSE);
|
|
211
|
+
const body = Buffer.from(JSON.stringify({ ...payload, _iat: Math.floor(Date.now() / 1000) }), 'utf8');
|
|
212
|
+
return base64UrlEncode(Buffer.concat([nonce, cipher.update(body), cipher.final(), cipher.getAuthTag()]));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The payload, or null when the value is tampered, from another key, or older than `maxAgeSeconds`. */
|
|
216
|
+
export function unprotectState(secret, value, maxAgeSeconds = DENIED_MAX_AGE_SECONDS) {
|
|
217
|
+
let payload;
|
|
218
|
+
try {
|
|
219
|
+
const raw = base64UrlDecode(String(value));
|
|
220
|
+
if (raw.length < 12 + 16) return null;
|
|
221
|
+
const decipher = createDecipheriv('aes-256-gcm', deniedKey(secret), raw.subarray(0, 12), { authTagLength: 16 });
|
|
222
|
+
decipher.setAAD(PURPOSE);
|
|
223
|
+
decipher.setAuthTag(raw.subarray(raw.length - 16));
|
|
224
|
+
payload = JSON.parse(Buffer.concat([decipher.update(raw.subarray(12, raw.length - 16)), decipher.final()]).toString('utf8'));
|
|
225
|
+
} catch {
|
|
226
|
+
// Tampered, or sealed by a secret this instance no longer holds. The page falls back to the
|
|
227
|
+
// unnamed wording rather than failing.
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return null;
|
|
231
|
+
const { _iat: issued, ...rest } = payload;
|
|
232
|
+
if (maxAgeSeconds && (typeof issued !== 'number' || Date.now() / 1000 - issued > maxAgeSeconds)) return null;
|
|
233
|
+
return rest;
|
|
234
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `ark_oauth_client` configuration section, as the .NET client binds it.
|
|
3
|
+
*
|
|
4
|
+
* An Ark application usually already has this section in an `appsettings.json`. Rather than have a
|
|
5
|
+
* Node service restate it in its own spelling, `ArkAuthConfig.fromMapping` reads it as-is — C#
|
|
6
|
+
* (`ClientId`), camel (`clientId`) or snake (`client_id`) — and returns the options `arkExpress()`
|
|
7
|
+
* and `ArkOAuthClient` take.
|
|
8
|
+
*
|
|
9
|
+
* The legacy keys (`Issuer`, `RsaPublic`, `Tenants`, `RedirectUri`, …) are accepted and ignored.
|
|
10
|
+
* They describe the v1 flow, whose callback route and pasted public key are exactly what discovery
|
|
11
|
+
* replaced; carrying `RedirectUri` across would send users to the v1 callback. The redirect URI is
|
|
12
|
+
* derived per request from `CallbackPath`, as the .NET handler does.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Section key, folded (lower case, no underscores) → option name. */
|
|
16
|
+
const KEYS = new Map([
|
|
17
|
+
['authority', 'authority'],
|
|
18
|
+
['authserverurl', 'authServerUrl'],
|
|
19
|
+
['tenantid', 'tenantId'],
|
|
20
|
+
['clientid', 'clientId'],
|
|
21
|
+
['clientsecret', 'clientSecret'],
|
|
22
|
+
['scopes', 'scopes'],
|
|
23
|
+
['postlogoutredirecturi', 'postLogoutRedirectUri'],
|
|
24
|
+
['callbackpath', 'callbackPath'],
|
|
25
|
+
['loginpath', 'loginPath'],
|
|
26
|
+
['logoutpath', 'logoutPath'],
|
|
27
|
+
['autherrorpath', 'errorPath'],
|
|
28
|
+
['cookiename', 'cookieName'],
|
|
29
|
+
['roleclaimtype', 'roleClaim'],
|
|
30
|
+
['requirehttpsmetadata', 'requireHttps'],
|
|
31
|
+
['expiremins', 'sessionTtlSeconds'],
|
|
32
|
+
['accountswitch', 'accountSwitch']
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const fold = (key) => String(key).replace(/_/g, '').toLowerCase();
|
|
36
|
+
const camel = (key) => {
|
|
37
|
+
const s = String(key);
|
|
38
|
+
return s.includes('_') ? s.toLowerCase().replace(/_([a-z])/g, (_, c) => c.toUpperCase()) : s.charAt(0).toLowerCase() + s.slice(1);
|
|
39
|
+
};
|
|
40
|
+
const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
41
|
+
|
|
42
|
+
export const ArkAuthConfig = Object.freeze({
|
|
43
|
+
/**
|
|
44
|
+
* Binds the section. `{ ark_oauth_client: {...} }` and the inner object are both accepted, so a
|
|
45
|
+
* whole parsed `appsettings.json` can be handed over.
|
|
46
|
+
*
|
|
47
|
+
* @param {Record<string, any>} data
|
|
48
|
+
* @returns {Record<string, any>} options for arkExpress() / new ArkOAuthClient()
|
|
49
|
+
*/
|
|
50
|
+
fromMapping(data) {
|
|
51
|
+
let section = isPlainObject(data) ? data : {};
|
|
52
|
+
const nested = Object.entries(section).find(([key, value]) => fold(key) === 'arkoauthclient' && isPlainObject(value));
|
|
53
|
+
if (nested) section = nested[1];
|
|
54
|
+
|
|
55
|
+
const options = {};
|
|
56
|
+
for (const [key, value] of Object.entries(section)) {
|
|
57
|
+
const name = KEYS.get(fold(key));
|
|
58
|
+
if (!name || value === undefined || value === null || value === '') continue;
|
|
59
|
+
|
|
60
|
+
if (name === 'accountSwitch') {
|
|
61
|
+
if (isPlainObject(value)) options.accountSwitch = Object.fromEntries(Object.entries(value).map(([k, v]) => [camel(k), v]));
|
|
62
|
+
} else if (name === 'sessionTtlSeconds') {
|
|
63
|
+
const minutes = Number(value);
|
|
64
|
+
if (Number.isFinite(minutes) && minutes > 0) options.sessionTtlSeconds = Math.max(60, Math.round(minutes * 60));
|
|
65
|
+
} else if (name === 'scopes') {
|
|
66
|
+
options.scopes = Array.isArray(value) ? value.map(String) : String(value).split(/[\s,]+/).filter(Boolean);
|
|
67
|
+
} else {
|
|
68
|
+
options[name] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
});
|