@insureco/bio 0.2.0 → 0.4.0

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.
@@ -0,0 +1,43 @@
1
+ // src/errors.ts
2
+ var BioError = class extends Error {
3
+ /** HTTP status code (if from an API response) */
4
+ statusCode;
5
+ /** Machine-readable error code (e.g. 'invalid_grant', 'token_expired') */
6
+ code;
7
+ /** Additional error details from the API */
8
+ details;
9
+ constructor(message, code, statusCode, details) {
10
+ super(message);
11
+ this.name = "BioError";
12
+ this.code = code;
13
+ this.statusCode = statusCode;
14
+ this.details = details;
15
+ }
16
+ };
17
+
18
+ // src/utils.ts
19
+ function retryDelay(attempt) {
20
+ const baseDelay = Math.min(1e3 * 2 ** attempt, 5e3);
21
+ return baseDelay * (0.5 + Math.random() * 0.5);
22
+ }
23
+ function sleep(ms) {
24
+ return new Promise((resolve) => setTimeout(resolve, ms));
25
+ }
26
+ async function parseJsonResponse(response) {
27
+ try {
28
+ return await response.json();
29
+ } catch {
30
+ throw new BioError(
31
+ `Bio-ID returned ${response.status} with non-JSON body`,
32
+ "parse_error",
33
+ response.status
34
+ );
35
+ }
36
+ }
37
+
38
+ export {
39
+ BioError,
40
+ retryDelay,
41
+ sleep,
42
+ parseJsonResponse
43
+ };
package/dist/index.d.mts CHANGED
@@ -1,259 +1,5 @@
1
- /** Configuration for BioAuth (OAuth flow client) */
2
- interface BioAuthConfig {
3
- /** OAuth client ID (env: BIO_CLIENT_ID) */
4
- clientId: string;
5
- /** OAuth client secret (env: BIO_CLIENT_SECRET) */
6
- clientSecret: string;
7
- /** Bio-ID issuer URL (env: BIO_ID_URL, default: https://bio.tawa.insureco.io) */
8
- issuer?: string;
9
- /** Number of retry attempts on transient failures (default: 2) */
10
- retries?: number;
11
- /** Request timeout in milliseconds (default: 10000) */
12
- timeoutMs?: number;
13
- }
14
- /** Configuration for BioAdmin (admin API client) */
15
- interface BioAdminConfig {
16
- /** Bio-ID base URL (env: BIO_ID_URL, default: https://bio.tawa.insureco.io) */
17
- baseUrl?: string;
18
- /** Internal API key for service-to-service auth (env: INTERNAL_API_KEY) */
19
- internalKey?: string;
20
- /** Async function returning a Bearer token (alternative to internalKey) */
21
- accessTokenFn?: () => Promise<string>;
22
- /** Number of retry attempts on transient failures (default: 2) */
23
- retries?: number;
24
- /** Request timeout in milliseconds (default: 10000) */
25
- timeoutMs?: number;
26
- }
27
- /** Options for building an authorization URL */
28
- interface AuthorizeOptions {
29
- /** Callback URL where Bio-ID redirects after authorization */
30
- redirectUri: string;
31
- /** OAuth scopes to request (default: ['openid', 'profile', 'email']) */
32
- scopes?: string[];
33
- /** CSRF state parameter (auto-generated if not provided) */
34
- state?: string;
35
- }
36
- /** Result from getAuthorizationUrl() */
37
- interface AuthorizeResult {
38
- /** Full authorization URL to redirect the user to */
39
- url: string;
40
- /** State parameter (for CSRF validation on callback) */
41
- state: string;
42
- /** PKCE code verifier (store securely, send during token exchange) */
43
- codeVerifier: string;
44
- /** PKCE code challenge (included in the URL) */
45
- codeChallenge: string;
46
- }
47
- /** Response from the /api/oauth/token endpoint */
48
- interface TokenResponse {
49
- access_token: string;
50
- token_type: 'Bearer';
51
- expires_in: number;
52
- refresh_token?: string;
53
- scope: string;
54
- id_token?: string;
55
- }
56
- /** Response from the /api/auth/introspect endpoint */
57
- interface IntrospectResult {
58
- active: boolean;
59
- user?: {
60
- id: string;
61
- email: string;
62
- name: string;
63
- org: string;
64
- roles: string[];
65
- };
66
- tokenType?: 'client_credentials';
67
- clientId?: string;
68
- scopes?: string[];
69
- orgId?: string;
70
- orgSlug?: string;
71
- organizationName?: string;
72
- }
73
- /** Decoded access token payload (user auth) */
74
- interface BioTokenPayload {
75
- iss: string;
76
- sub: string;
77
- aud: string;
78
- exp: number;
79
- iat: number;
80
- bioId: string;
81
- email: string;
82
- name: string;
83
- userType: string;
84
- roles: string[];
85
- permissions: string[];
86
- orgId?: string;
87
- orgSlug?: string;
88
- client_id: string;
89
- scope: string;
90
- enabled_modules?: string[];
91
- onboarding?: {
92
- platform: boolean;
93
- modules: Record<string, {
94
- completed: string[];
95
- due: string[];
96
- }>;
97
- };
98
- }
99
- /** Decoded client credentials token payload (service-to-service) */
100
- interface BioClientTokenPayload {
101
- iss: string;
102
- exp: number;
103
- iat: number;
104
- client_id: string;
105
- scope: string;
106
- token_type: 'client_credentials';
107
- orgId?: string;
108
- orgSlug?: string;
109
- }
110
- /** Options for local JWT verification (HS256) */
111
- interface VerifyOptions {
112
- /** Expected issuer (default: config issuer) */
113
- issuer?: string;
114
- /** Expected audience (client_id) */
115
- audience?: string;
116
- }
117
- /** Options for JWKS-based JWT verification (RS256) */
118
- interface JWKSVerifyOptions {
119
- /** JWKS endpoint URL (default: https://bio.tawa.insureco.io/.well-known/jwks.json) */
120
- jwksUri?: string;
121
- /** Expected issuer — defaults to accepting both bio.insureco.io and bio.tawa.insureco.io */
122
- issuer?: string;
123
- /** Expected audience (client_id) */
124
- audience?: string;
125
- }
126
- /** User profile from /api/oauth/userinfo or admin API */
127
- interface BioUser {
128
- sub: string;
129
- bioId: string;
130
- email: string;
131
- emailVerified: boolean;
132
- name: string;
133
- firstName?: string;
134
- lastName?: string;
135
- userType: string;
136
- roles: string[];
137
- permissions: string[];
138
- status: string;
139
- orgId?: string;
140
- orgSlug?: string;
141
- organizationId?: string;
142
- organizationName?: string;
143
- departmentId?: string;
144
- departmentName?: string;
145
- managerId?: string;
146
- enabledModules?: string[];
147
- jobTitle?: string;
148
- phoneHome?: string;
149
- phoneWork?: string;
150
- phoneCell?: string;
151
- phone?: string;
152
- addressHome?: BioAddress;
153
- addressWork?: BioAddress;
154
- messaging?: BioMessaging;
155
- preferences?: Record<string, unknown>;
156
- lastLoginAt?: number;
157
- }
158
- interface BioAddress {
159
- street?: string;
160
- city?: string;
161
- state?: string;
162
- zip?: string;
163
- country?: string;
164
- }
165
- interface BioMessaging {
166
- slack?: string;
167
- teams?: string;
168
- skype?: string;
169
- whatsapp?: string;
170
- }
171
- /** Filters for listing users */
172
- interface UserFilters {
173
- search?: string;
174
- status?: string;
175
- userType?: string;
176
- organizationId?: string;
177
- page?: number;
178
- limit?: number;
179
- }
180
- /** Data for updating a user */
181
- interface UpdateUserData {
182
- firstName?: string;
183
- lastName?: string;
184
- displayName?: string;
185
- roles?: string[];
186
- status?: string;
187
- userType?: string;
188
- departmentId?: string;
189
- jobTitle?: string;
190
- permissions?: string[];
191
- enabled_modules?: string[];
192
- }
193
- /** Department from admin API */
194
- interface BioDepartment {
195
- id: string;
196
- name: string;
197
- description?: string;
198
- organizationId: string;
199
- headId?: string;
200
- parentId?: string;
201
- memberCount?: number;
202
- }
203
- /** Data for creating a department */
204
- interface CreateDepartmentData {
205
- name: string;
206
- description?: string;
207
- headId?: string;
208
- parentId?: string;
209
- }
210
- /** Role from admin API */
211
- interface BioRole {
212
- id: string;
213
- name: string;
214
- description?: string;
215
- permissions: string[];
216
- isSystem?: boolean;
217
- }
218
- /** Data for creating a role */
219
- interface CreateRoleData {
220
- name: string;
221
- description?: string;
222
- permissions: string[];
223
- }
224
- /** OAuth client from admin API */
225
- interface BioOAuthClient {
226
- clientId: string;
227
- name: string;
228
- description?: string;
229
- redirectUris: string[];
230
- allowedScopes: string[];
231
- allowedGrantTypes: string[];
232
- isActive: boolean;
233
- orgId?: string;
234
- orgSlug?: string;
235
- accessTokenTtl?: number;
236
- refreshTokenTtl?: number;
237
- }
238
- /** Data for creating an OAuth client */
239
- interface CreateClientData {
240
- name: string;
241
- description?: string;
242
- redirectUris: string[];
243
- allowedScopes?: string[];
244
- allowedGrantTypes?: string[];
245
- }
246
- /** Admin API response wrapper */
247
- interface AdminResponse<T> {
248
- success: boolean;
249
- data?: T;
250
- error?: string;
251
- meta?: {
252
- total: number;
253
- page: number;
254
- limit: number;
255
- };
256
- }
1
+ import { B as BioAuthConfig, A as AuthorizeOptions, a as AuthorizeResult, T as TokenResponse, b as BioUser, I as IntrospectResult, c as BioAdminConfig, U as UserFilters, d as UpdateUserData, e as BioDepartment, C as CreateDepartmentData, f as BioRole, g as CreateRoleData, h as BioOAuthClient, i as CreateClientData, j as BioTokenPayload, V as VerifyOptions, J as JWKSVerifyOptions } from './types-Dkb-drHZ.mjs';
2
+ export { k as AdminResponse, l as BioAddress, m as BioClientTokenPayload, n as BioMessaging, o as BioUsersConfig, O as OrgMember, p as OrgMemberFilters, q as OrgMembersResult } from './types-Dkb-drHZ.mjs';
257
3
 
258
4
  /**
259
5
  * OAuth flow client for Bio-ID SSO.
@@ -408,4 +154,4 @@ declare function isTokenExpired(token: string, bufferSeconds?: number): boolean;
408
154
  */
409
155
  declare function verifyTokenJWKS(token: string, options?: JWKSVerifyOptions): Promise<BioTokenPayload>;
410
156
 
411
- export { type AdminResponse, type AuthorizeOptions, type AuthorizeResult, type BioAddress, BioAdmin, type BioAdminConfig, BioAuth, type BioAuthConfig, type BioClientTokenPayload, type BioDepartment, BioError, type BioMessaging, type BioOAuthClient, type BioRole, type BioTokenPayload, type BioUser, type CreateClientData, type CreateDepartmentData, type CreateRoleData, type IntrospectResult, type JWKSVerifyOptions, type TokenResponse, type UpdateUserData, type UserFilters, type VerifyOptions, decodeToken, generatePKCE, isTokenExpired, verifyToken, verifyTokenJWKS };
157
+ export { AuthorizeOptions, AuthorizeResult, BioAdmin, BioAdminConfig, BioAuth, BioAuthConfig, BioDepartment, BioError, BioOAuthClient, BioRole, BioTokenPayload, BioUser, CreateClientData, CreateDepartmentData, CreateRoleData, IntrospectResult, JWKSVerifyOptions, TokenResponse, UpdateUserData, UserFilters, VerifyOptions, decodeToken, generatePKCE, isTokenExpired, verifyToken, verifyTokenJWKS };
package/dist/index.d.ts CHANGED
@@ -1,259 +1,5 @@
1
- /** Configuration for BioAuth (OAuth flow client) */
2
- interface BioAuthConfig {
3
- /** OAuth client ID (env: BIO_CLIENT_ID) */
4
- clientId: string;
5
- /** OAuth client secret (env: BIO_CLIENT_SECRET) */
6
- clientSecret: string;
7
- /** Bio-ID issuer URL (env: BIO_ID_URL, default: https://bio.tawa.insureco.io) */
8
- issuer?: string;
9
- /** Number of retry attempts on transient failures (default: 2) */
10
- retries?: number;
11
- /** Request timeout in milliseconds (default: 10000) */
12
- timeoutMs?: number;
13
- }
14
- /** Configuration for BioAdmin (admin API client) */
15
- interface BioAdminConfig {
16
- /** Bio-ID base URL (env: BIO_ID_URL, default: https://bio.tawa.insureco.io) */
17
- baseUrl?: string;
18
- /** Internal API key for service-to-service auth (env: INTERNAL_API_KEY) */
19
- internalKey?: string;
20
- /** Async function returning a Bearer token (alternative to internalKey) */
21
- accessTokenFn?: () => Promise<string>;
22
- /** Number of retry attempts on transient failures (default: 2) */
23
- retries?: number;
24
- /** Request timeout in milliseconds (default: 10000) */
25
- timeoutMs?: number;
26
- }
27
- /** Options for building an authorization URL */
28
- interface AuthorizeOptions {
29
- /** Callback URL where Bio-ID redirects after authorization */
30
- redirectUri: string;
31
- /** OAuth scopes to request (default: ['openid', 'profile', 'email']) */
32
- scopes?: string[];
33
- /** CSRF state parameter (auto-generated if not provided) */
34
- state?: string;
35
- }
36
- /** Result from getAuthorizationUrl() */
37
- interface AuthorizeResult {
38
- /** Full authorization URL to redirect the user to */
39
- url: string;
40
- /** State parameter (for CSRF validation on callback) */
41
- state: string;
42
- /** PKCE code verifier (store securely, send during token exchange) */
43
- codeVerifier: string;
44
- /** PKCE code challenge (included in the URL) */
45
- codeChallenge: string;
46
- }
47
- /** Response from the /api/oauth/token endpoint */
48
- interface TokenResponse {
49
- access_token: string;
50
- token_type: 'Bearer';
51
- expires_in: number;
52
- refresh_token?: string;
53
- scope: string;
54
- id_token?: string;
55
- }
56
- /** Response from the /api/auth/introspect endpoint */
57
- interface IntrospectResult {
58
- active: boolean;
59
- user?: {
60
- id: string;
61
- email: string;
62
- name: string;
63
- org: string;
64
- roles: string[];
65
- };
66
- tokenType?: 'client_credentials';
67
- clientId?: string;
68
- scopes?: string[];
69
- orgId?: string;
70
- orgSlug?: string;
71
- organizationName?: string;
72
- }
73
- /** Decoded access token payload (user auth) */
74
- interface BioTokenPayload {
75
- iss: string;
76
- sub: string;
77
- aud: string;
78
- exp: number;
79
- iat: number;
80
- bioId: string;
81
- email: string;
82
- name: string;
83
- userType: string;
84
- roles: string[];
85
- permissions: string[];
86
- orgId?: string;
87
- orgSlug?: string;
88
- client_id: string;
89
- scope: string;
90
- enabled_modules?: string[];
91
- onboarding?: {
92
- platform: boolean;
93
- modules: Record<string, {
94
- completed: string[];
95
- due: string[];
96
- }>;
97
- };
98
- }
99
- /** Decoded client credentials token payload (service-to-service) */
100
- interface BioClientTokenPayload {
101
- iss: string;
102
- exp: number;
103
- iat: number;
104
- client_id: string;
105
- scope: string;
106
- token_type: 'client_credentials';
107
- orgId?: string;
108
- orgSlug?: string;
109
- }
110
- /** Options for local JWT verification (HS256) */
111
- interface VerifyOptions {
112
- /** Expected issuer (default: config issuer) */
113
- issuer?: string;
114
- /** Expected audience (client_id) */
115
- audience?: string;
116
- }
117
- /** Options for JWKS-based JWT verification (RS256) */
118
- interface JWKSVerifyOptions {
119
- /** JWKS endpoint URL (default: https://bio.tawa.insureco.io/.well-known/jwks.json) */
120
- jwksUri?: string;
121
- /** Expected issuer — defaults to accepting both bio.insureco.io and bio.tawa.insureco.io */
122
- issuer?: string;
123
- /** Expected audience (client_id) */
124
- audience?: string;
125
- }
126
- /** User profile from /api/oauth/userinfo or admin API */
127
- interface BioUser {
128
- sub: string;
129
- bioId: string;
130
- email: string;
131
- emailVerified: boolean;
132
- name: string;
133
- firstName?: string;
134
- lastName?: string;
135
- userType: string;
136
- roles: string[];
137
- permissions: string[];
138
- status: string;
139
- orgId?: string;
140
- orgSlug?: string;
141
- organizationId?: string;
142
- organizationName?: string;
143
- departmentId?: string;
144
- departmentName?: string;
145
- managerId?: string;
146
- enabledModules?: string[];
147
- jobTitle?: string;
148
- phoneHome?: string;
149
- phoneWork?: string;
150
- phoneCell?: string;
151
- phone?: string;
152
- addressHome?: BioAddress;
153
- addressWork?: BioAddress;
154
- messaging?: BioMessaging;
155
- preferences?: Record<string, unknown>;
156
- lastLoginAt?: number;
157
- }
158
- interface BioAddress {
159
- street?: string;
160
- city?: string;
161
- state?: string;
162
- zip?: string;
163
- country?: string;
164
- }
165
- interface BioMessaging {
166
- slack?: string;
167
- teams?: string;
168
- skype?: string;
169
- whatsapp?: string;
170
- }
171
- /** Filters for listing users */
172
- interface UserFilters {
173
- search?: string;
174
- status?: string;
175
- userType?: string;
176
- organizationId?: string;
177
- page?: number;
178
- limit?: number;
179
- }
180
- /** Data for updating a user */
181
- interface UpdateUserData {
182
- firstName?: string;
183
- lastName?: string;
184
- displayName?: string;
185
- roles?: string[];
186
- status?: string;
187
- userType?: string;
188
- departmentId?: string;
189
- jobTitle?: string;
190
- permissions?: string[];
191
- enabled_modules?: string[];
192
- }
193
- /** Department from admin API */
194
- interface BioDepartment {
195
- id: string;
196
- name: string;
197
- description?: string;
198
- organizationId: string;
199
- headId?: string;
200
- parentId?: string;
201
- memberCount?: number;
202
- }
203
- /** Data for creating a department */
204
- interface CreateDepartmentData {
205
- name: string;
206
- description?: string;
207
- headId?: string;
208
- parentId?: string;
209
- }
210
- /** Role from admin API */
211
- interface BioRole {
212
- id: string;
213
- name: string;
214
- description?: string;
215
- permissions: string[];
216
- isSystem?: boolean;
217
- }
218
- /** Data for creating a role */
219
- interface CreateRoleData {
220
- name: string;
221
- description?: string;
222
- permissions: string[];
223
- }
224
- /** OAuth client from admin API */
225
- interface BioOAuthClient {
226
- clientId: string;
227
- name: string;
228
- description?: string;
229
- redirectUris: string[];
230
- allowedScopes: string[];
231
- allowedGrantTypes: string[];
232
- isActive: boolean;
233
- orgId?: string;
234
- orgSlug?: string;
235
- accessTokenTtl?: number;
236
- refreshTokenTtl?: number;
237
- }
238
- /** Data for creating an OAuth client */
239
- interface CreateClientData {
240
- name: string;
241
- description?: string;
242
- redirectUris: string[];
243
- allowedScopes?: string[];
244
- allowedGrantTypes?: string[];
245
- }
246
- /** Admin API response wrapper */
247
- interface AdminResponse<T> {
248
- success: boolean;
249
- data?: T;
250
- error?: string;
251
- meta?: {
252
- total: number;
253
- page: number;
254
- limit: number;
255
- };
256
- }
1
+ import { B as BioAuthConfig, A as AuthorizeOptions, a as AuthorizeResult, T as TokenResponse, b as BioUser, I as IntrospectResult, c as BioAdminConfig, U as UserFilters, d as UpdateUserData, e as BioDepartment, C as CreateDepartmentData, f as BioRole, g as CreateRoleData, h as BioOAuthClient, i as CreateClientData, j as BioTokenPayload, V as VerifyOptions, J as JWKSVerifyOptions } from './types-Dkb-drHZ.js';
2
+ export { k as AdminResponse, l as BioAddress, m as BioClientTokenPayload, n as BioMessaging, o as BioUsersConfig, O as OrgMember, p as OrgMemberFilters, q as OrgMembersResult } from './types-Dkb-drHZ.js';
257
3
 
258
4
  /**
259
5
  * OAuth flow client for Bio-ID SSO.
@@ -408,4 +154,4 @@ declare function isTokenExpired(token: string, bufferSeconds?: number): boolean;
408
154
  */
409
155
  declare function verifyTokenJWKS(token: string, options?: JWKSVerifyOptions): Promise<BioTokenPayload>;
410
156
 
411
- export { type AdminResponse, type AuthorizeOptions, type AuthorizeResult, type BioAddress, BioAdmin, type BioAdminConfig, BioAuth, type BioAuthConfig, type BioClientTokenPayload, type BioDepartment, BioError, type BioMessaging, type BioOAuthClient, type BioRole, type BioTokenPayload, type BioUser, type CreateClientData, type CreateDepartmentData, type CreateRoleData, type IntrospectResult, type JWKSVerifyOptions, type TokenResponse, type UpdateUserData, type UserFilters, type VerifyOptions, decodeToken, generatePKCE, isTokenExpired, verifyToken, verifyTokenJWKS };
157
+ export { AuthorizeOptions, AuthorizeResult, BioAdmin, BioAdminConfig, BioAuth, BioAuthConfig, BioDepartment, BioError, BioOAuthClient, BioRole, BioTokenPayload, BioUser, CreateClientData, CreateDepartmentData, CreateRoleData, IntrospectResult, JWKSVerifyOptions, TokenResponse, UpdateUserData, UserFilters, VerifyOptions, decodeToken, generatePKCE, isTokenExpired, verifyToken, verifyTokenJWKS };
package/dist/index.js CHANGED
@@ -90,7 +90,7 @@ async function parseJsonResponse(response) {
90
90
  }
91
91
 
92
92
  // src/auth.ts
93
- var DEFAULT_ISSUER = "https://bio.tawa.insureco.io";
93
+ var DEFAULT_ISSUER = "https://bio.tawa.pro";
94
94
  var DEFAULT_SCOPES = ["openid", "profile", "email"];
95
95
  var DEFAULT_TIMEOUT_MS = 1e4;
96
96
  var BioAuth = class _BioAuth {
@@ -160,6 +160,9 @@ var BioAuth = class _BioAuth {
160
160
  code_challenge: codeChallenge,
161
161
  code_challenge_method: "S256"
162
162
  });
163
+ if (opts.organization) {
164
+ params.set("organization", opts.organization);
165
+ }
163
166
  return {
164
167
  url: `${this.issuer}/oauth/authorize?${params.toString()}`,
165
168
  state,
@@ -381,7 +384,7 @@ function mapIntrospectResponse(raw) {
381
384
  }
382
385
 
383
386
  // src/admin.ts
384
- var DEFAULT_BASE_URL = "https://bio.tawa.insureco.io";
387
+ var DEFAULT_BASE_URL = "https://bio.tawa.pro";
385
388
  var DEFAULT_TIMEOUT_MS2 = 1e4;
386
389
  var BioAdmin = class _BioAdmin {
387
390
  baseUrl;
@@ -587,9 +590,10 @@ var import_node_crypto3 = __toESM(require("crypto"));
587
590
  var DEFAULT_ISSUERS = [
588
591
  "https://bio.insureco.io",
589
592
  "https://bio.tawa.insureco.io",
593
+ "https://bio.tawa.pro",
590
594
  "http://localhost:6100"
591
595
  ];
592
- var DEFAULT_JWKS_URI = "https://bio.tawa.insureco.io/.well-known/jwks.json";
596
+ var DEFAULT_JWKS_URI = "https://bio.tawa.pro/.well-known/jwks.json";
593
597
  var JWKS_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
594
598
  var jwksCache = /* @__PURE__ */ new Map();
595
599
  async function fetchJWKS(uri) {
@@ -706,7 +710,12 @@ async function verifyTokenJWKS(token, options) {
706
710
  throw new BioError("Malformed JWT: expected 3 parts", "invalid_token");
707
711
  }
708
712
  const [headerB64, payloadB64, signatureB64] = parts;
709
- const header = JSON.parse(base64UrlDecode(headerB64));
713
+ let header;
714
+ try {
715
+ header = JSON.parse(base64UrlDecode(headerB64));
716
+ } catch {
717
+ throw new BioError("Malformed JWT: invalid header encoding", "invalid_token");
718
+ }
710
719
  if (header.alg !== "RS256") {
711
720
  throw new BioError(
712
721
  `Expected RS256 token, got ${header.alg}. Use verifyToken() for HS256.`,