authtara-sdk 1.1.0 → 1.1.2
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/dist/index.d.mts +38 -8
- package/dist/index.d.ts +38 -8
- package/dist/index.js +28 -13
- package/dist/index.mjs +28 -13
- package/dist/react.js +2 -0
- package/dist/react.mjs +2 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -101,10 +101,11 @@ interface ExchangeResult {
|
|
|
101
101
|
* - exchangeCode: Menukar authorization code dengan JWT token (server-to-server)
|
|
102
102
|
*/
|
|
103
103
|
declare class AuthModule {
|
|
104
|
+
private readonly appId;
|
|
104
105
|
private readonly apiKey;
|
|
105
106
|
private readonly httpClient;
|
|
106
107
|
private readonly issuer;
|
|
107
|
-
constructor(apiKey: string, httpClient: HttpClient, issuer?: string);
|
|
108
|
+
constructor(appId: string, apiKey: string, httpClient: HttpClient, issuer?: string);
|
|
108
109
|
/**
|
|
109
110
|
* Verifikasi SSO JWT token secara offline
|
|
110
111
|
*
|
|
@@ -126,23 +127,46 @@ declare class AuthModule {
|
|
|
126
127
|
*/
|
|
127
128
|
verifySession(token: string): Promise<SessionVerifyResult>;
|
|
128
129
|
/**
|
|
129
|
-
* Exchange
|
|
130
|
+
* Exchange Authorization Code untuk JWT Token (OAuth 2.0)
|
|
130
131
|
*
|
|
131
|
-
*
|
|
132
|
-
* menjadi JWT token yang bisa diverifikasi.
|
|
132
|
+
* **Server-side only!** Jangan panggil function ini di browser karena mengandung appSecret.
|
|
133
133
|
*
|
|
134
134
|
* @param code - Authorization code dari callback URL
|
|
135
|
-
* @
|
|
135
|
+
* @param redirectUri - Redirect URI yang sama dengan saat request authorization code
|
|
136
|
+
* @returns Promise dengan JWT token dan user context
|
|
136
137
|
*
|
|
137
138
|
* @example
|
|
138
139
|
* ```typescript
|
|
139
140
|
* // Di endpoint /api/sso/callback
|
|
140
141
|
* const code = searchParams.get('code');
|
|
141
|
-
* const result = await ds.auth.exchangeCode(code);
|
|
142
|
-
* // Simpan result.
|
|
142
|
+
* const result = await ds.auth.exchangeCode(code, 'http://localhost:4000/api/sso/callback');
|
|
143
|
+
* // Simpan result.access_token ke session
|
|
143
144
|
* ```
|
|
144
145
|
*/
|
|
145
|
-
exchangeCode(code: string): Promise<
|
|
146
|
+
exchangeCode(code: string, redirectUri: string): Promise<TokenResponse>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* OAuth 2.0 Token Response
|
|
150
|
+
*/
|
|
151
|
+
interface TokenResponse {
|
|
152
|
+
access_token: string;
|
|
153
|
+
token_type: 'Bearer';
|
|
154
|
+
expires_in: number;
|
|
155
|
+
user: {
|
|
156
|
+
id: string;
|
|
157
|
+
email: string;
|
|
158
|
+
name: string | null;
|
|
159
|
+
};
|
|
160
|
+
tenant: {
|
|
161
|
+
id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
subdomain: string;
|
|
164
|
+
role: string;
|
|
165
|
+
};
|
|
166
|
+
subscription: {
|
|
167
|
+
plan: string;
|
|
168
|
+
status: string;
|
|
169
|
+
};
|
|
146
170
|
}
|
|
147
171
|
|
|
148
172
|
/**
|
|
@@ -393,6 +417,12 @@ declare class ConfigurationError extends AuthtaraError {
|
|
|
393
417
|
* Konfigurasi untuk Authtara SDK
|
|
394
418
|
*/
|
|
395
419
|
interface AuthtaraConfig {
|
|
420
|
+
/**
|
|
421
|
+
* App ID dari Dashboard Developer
|
|
422
|
+
*
|
|
423
|
+
* Didapatkan saat aplikasi dibuat
|
|
424
|
+
*/
|
|
425
|
+
appId: string;
|
|
396
426
|
/**
|
|
397
427
|
* App Secret dari Dashboard Developer
|
|
398
428
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -101,10 +101,11 @@ interface ExchangeResult {
|
|
|
101
101
|
* - exchangeCode: Menukar authorization code dengan JWT token (server-to-server)
|
|
102
102
|
*/
|
|
103
103
|
declare class AuthModule {
|
|
104
|
+
private readonly appId;
|
|
104
105
|
private readonly apiKey;
|
|
105
106
|
private readonly httpClient;
|
|
106
107
|
private readonly issuer;
|
|
107
|
-
constructor(apiKey: string, httpClient: HttpClient, issuer?: string);
|
|
108
|
+
constructor(appId: string, apiKey: string, httpClient: HttpClient, issuer?: string);
|
|
108
109
|
/**
|
|
109
110
|
* Verifikasi SSO JWT token secara offline
|
|
110
111
|
*
|
|
@@ -126,23 +127,46 @@ declare class AuthModule {
|
|
|
126
127
|
*/
|
|
127
128
|
verifySession(token: string): Promise<SessionVerifyResult>;
|
|
128
129
|
/**
|
|
129
|
-
* Exchange
|
|
130
|
+
* Exchange Authorization Code untuk JWT Token (OAuth 2.0)
|
|
130
131
|
*
|
|
131
|
-
*
|
|
132
|
-
* menjadi JWT token yang bisa diverifikasi.
|
|
132
|
+
* **Server-side only!** Jangan panggil function ini di browser karena mengandung appSecret.
|
|
133
133
|
*
|
|
134
134
|
* @param code - Authorization code dari callback URL
|
|
135
|
-
* @
|
|
135
|
+
* @param redirectUri - Redirect URI yang sama dengan saat request authorization code
|
|
136
|
+
* @returns Promise dengan JWT token dan user context
|
|
136
137
|
*
|
|
137
138
|
* @example
|
|
138
139
|
* ```typescript
|
|
139
140
|
* // Di endpoint /api/sso/callback
|
|
140
141
|
* const code = searchParams.get('code');
|
|
141
|
-
* const result = await ds.auth.exchangeCode(code);
|
|
142
|
-
* // Simpan result.
|
|
142
|
+
* const result = await ds.auth.exchangeCode(code, 'http://localhost:4000/api/sso/callback');
|
|
143
|
+
* // Simpan result.access_token ke session
|
|
143
144
|
* ```
|
|
144
145
|
*/
|
|
145
|
-
exchangeCode(code: string): Promise<
|
|
146
|
+
exchangeCode(code: string, redirectUri: string): Promise<TokenResponse>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* OAuth 2.0 Token Response
|
|
150
|
+
*/
|
|
151
|
+
interface TokenResponse {
|
|
152
|
+
access_token: string;
|
|
153
|
+
token_type: 'Bearer';
|
|
154
|
+
expires_in: number;
|
|
155
|
+
user: {
|
|
156
|
+
id: string;
|
|
157
|
+
email: string;
|
|
158
|
+
name: string | null;
|
|
159
|
+
};
|
|
160
|
+
tenant: {
|
|
161
|
+
id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
subdomain: string;
|
|
164
|
+
role: string;
|
|
165
|
+
};
|
|
166
|
+
subscription: {
|
|
167
|
+
plan: string;
|
|
168
|
+
status: string;
|
|
169
|
+
};
|
|
146
170
|
}
|
|
147
171
|
|
|
148
172
|
/**
|
|
@@ -393,6 +417,12 @@ declare class ConfigurationError extends AuthtaraError {
|
|
|
393
417
|
* Konfigurasi untuk Authtara SDK
|
|
394
418
|
*/
|
|
395
419
|
interface AuthtaraConfig {
|
|
420
|
+
/**
|
|
421
|
+
* App ID dari Dashboard Developer
|
|
422
|
+
*
|
|
423
|
+
* Didapatkan saat aplikasi dibuat
|
|
424
|
+
*/
|
|
425
|
+
appId: string;
|
|
396
426
|
/**
|
|
397
427
|
* App Secret dari Dashboard Developer
|
|
398
428
|
*
|
package/dist/index.js
CHANGED
|
@@ -153,10 +153,14 @@ var HttpClient = class {
|
|
|
153
153
|
// src/auth/index.ts
|
|
154
154
|
var import_jose = require("jose");
|
|
155
155
|
var AuthModule = class {
|
|
156
|
-
constructor(apiKey, httpClient, issuer = "platform.digitalsolution.com") {
|
|
156
|
+
constructor(appId, apiKey, httpClient, issuer = "platform.digitalsolution.com") {
|
|
157
|
+
if (!appId) {
|
|
158
|
+
throw new ConfigurationError("appId is required for AuthModule");
|
|
159
|
+
}
|
|
157
160
|
if (!apiKey) {
|
|
158
161
|
throw new ConfigurationError("apiKey is required for AuthModule");
|
|
159
162
|
}
|
|
163
|
+
this.appId = appId;
|
|
160
164
|
this.apiKey = apiKey;
|
|
161
165
|
this.httpClient = httpClient;
|
|
162
166
|
this.issuer = issuer;
|
|
@@ -207,30 +211,37 @@ var AuthModule = class {
|
|
|
207
211
|
}
|
|
208
212
|
}
|
|
209
213
|
/**
|
|
210
|
-
* Exchange
|
|
214
|
+
* Exchange Authorization Code untuk JWT Token (OAuth 2.0)
|
|
211
215
|
*
|
|
212
|
-
*
|
|
213
|
-
* menjadi JWT token yang bisa diverifikasi.
|
|
216
|
+
* **Server-side only!** Jangan panggil function ini di browser karena mengandung appSecret.
|
|
214
217
|
*
|
|
215
218
|
* @param code - Authorization code dari callback URL
|
|
216
|
-
* @
|
|
219
|
+
* @param redirectUri - Redirect URI yang sama dengan saat request authorization code
|
|
220
|
+
* @returns Promise dengan JWT token dan user context
|
|
217
221
|
*
|
|
218
222
|
* @example
|
|
219
223
|
* ```typescript
|
|
220
224
|
* // Di endpoint /api/sso/callback
|
|
221
225
|
* const code = searchParams.get('code');
|
|
222
|
-
* const result = await ds.auth.exchangeCode(code);
|
|
223
|
-
* // Simpan result.
|
|
226
|
+
* const result = await ds.auth.exchangeCode(code, 'http://localhost:4000/api/sso/callback');
|
|
227
|
+
* // Simpan result.access_token ke session
|
|
224
228
|
* ```
|
|
225
229
|
*/
|
|
226
|
-
async exchangeCode(code) {
|
|
230
|
+
async exchangeCode(code, redirectUri) {
|
|
227
231
|
if (!code) {
|
|
228
232
|
throw new ConfigurationError("Authorization code is required");
|
|
229
233
|
}
|
|
230
|
-
|
|
234
|
+
if (!redirectUri) {
|
|
235
|
+
throw new ConfigurationError("Redirect URI is required");
|
|
236
|
+
}
|
|
237
|
+
const response = await this.httpClient.post("/api/oauth/token", {
|
|
238
|
+
grant_type: "authorization_code",
|
|
231
239
|
code,
|
|
232
|
-
|
|
240
|
+
client_id: this.appId,
|
|
241
|
+
client_secret: this.apiKey,
|
|
242
|
+
redirect_uri: redirectUri
|
|
233
243
|
});
|
|
244
|
+
return response;
|
|
234
245
|
}
|
|
235
246
|
};
|
|
236
247
|
|
|
@@ -344,18 +355,22 @@ var Authtara = class {
|
|
|
344
355
|
* @throws ConfigurationError jika apiKey tidak disediakan
|
|
345
356
|
*/
|
|
346
357
|
constructor(config) {
|
|
358
|
+
if (!config.appId) {
|
|
359
|
+
throw new ConfigurationError(
|
|
360
|
+
"appId is required. Get it from your Developer Dashboard."
|
|
361
|
+
);
|
|
362
|
+
}
|
|
347
363
|
if (!config.apiKey) {
|
|
348
364
|
throw new ConfigurationError(
|
|
349
365
|
"apiKey is required. Get it from your Developer Dashboard."
|
|
350
366
|
);
|
|
351
367
|
}
|
|
352
|
-
const endpoint = config.endpoint ?? "https://api.digitalsolution.com";
|
|
353
368
|
const httpClient = new HttpClient({
|
|
354
|
-
baseUrl: endpoint,
|
|
369
|
+
baseUrl: config.endpoint || "https://api.digitalsolution.com",
|
|
355
370
|
apiKey: config.apiKey,
|
|
356
371
|
timeout: config.timeout
|
|
357
372
|
});
|
|
358
|
-
this.auth = new AuthModule(config.apiKey, httpClient);
|
|
373
|
+
this.auth = new AuthModule(config.appId, config.apiKey, httpClient);
|
|
359
374
|
this.billing = new BillingModule(httpClient);
|
|
360
375
|
this.metering = new MeteringModule(httpClient);
|
|
361
376
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -121,10 +121,14 @@ var HttpClient = class {
|
|
|
121
121
|
// src/auth/index.ts
|
|
122
122
|
import { jwtVerify } from "jose";
|
|
123
123
|
var AuthModule = class {
|
|
124
|
-
constructor(apiKey, httpClient, issuer = "platform.digitalsolution.com") {
|
|
124
|
+
constructor(appId, apiKey, httpClient, issuer = "platform.digitalsolution.com") {
|
|
125
|
+
if (!appId) {
|
|
126
|
+
throw new ConfigurationError("appId is required for AuthModule");
|
|
127
|
+
}
|
|
125
128
|
if (!apiKey) {
|
|
126
129
|
throw new ConfigurationError("apiKey is required for AuthModule");
|
|
127
130
|
}
|
|
131
|
+
this.appId = appId;
|
|
128
132
|
this.apiKey = apiKey;
|
|
129
133
|
this.httpClient = httpClient;
|
|
130
134
|
this.issuer = issuer;
|
|
@@ -175,30 +179,37 @@ var AuthModule = class {
|
|
|
175
179
|
}
|
|
176
180
|
}
|
|
177
181
|
/**
|
|
178
|
-
* Exchange
|
|
182
|
+
* Exchange Authorization Code untuk JWT Token (OAuth 2.0)
|
|
179
183
|
*
|
|
180
|
-
*
|
|
181
|
-
* menjadi JWT token yang bisa diverifikasi.
|
|
184
|
+
* **Server-side only!** Jangan panggil function ini di browser karena mengandung appSecret.
|
|
182
185
|
*
|
|
183
186
|
* @param code - Authorization code dari callback URL
|
|
184
|
-
* @
|
|
187
|
+
* @param redirectUri - Redirect URI yang sama dengan saat request authorization code
|
|
188
|
+
* @returns Promise dengan JWT token dan user context
|
|
185
189
|
*
|
|
186
190
|
* @example
|
|
187
191
|
* ```typescript
|
|
188
192
|
* // Di endpoint /api/sso/callback
|
|
189
193
|
* const code = searchParams.get('code');
|
|
190
|
-
* const result = await ds.auth.exchangeCode(code);
|
|
191
|
-
* // Simpan result.
|
|
194
|
+
* const result = await ds.auth.exchangeCode(code, 'http://localhost:4000/api/sso/callback');
|
|
195
|
+
* // Simpan result.access_token ke session
|
|
192
196
|
* ```
|
|
193
197
|
*/
|
|
194
|
-
async exchangeCode(code) {
|
|
198
|
+
async exchangeCode(code, redirectUri) {
|
|
195
199
|
if (!code) {
|
|
196
200
|
throw new ConfigurationError("Authorization code is required");
|
|
197
201
|
}
|
|
198
|
-
|
|
202
|
+
if (!redirectUri) {
|
|
203
|
+
throw new ConfigurationError("Redirect URI is required");
|
|
204
|
+
}
|
|
205
|
+
const response = await this.httpClient.post("/api/oauth/token", {
|
|
206
|
+
grant_type: "authorization_code",
|
|
199
207
|
code,
|
|
200
|
-
|
|
208
|
+
client_id: this.appId,
|
|
209
|
+
client_secret: this.apiKey,
|
|
210
|
+
redirect_uri: redirectUri
|
|
201
211
|
});
|
|
212
|
+
return response;
|
|
202
213
|
}
|
|
203
214
|
};
|
|
204
215
|
|
|
@@ -312,18 +323,22 @@ var Authtara = class {
|
|
|
312
323
|
* @throws ConfigurationError jika apiKey tidak disediakan
|
|
313
324
|
*/
|
|
314
325
|
constructor(config) {
|
|
326
|
+
if (!config.appId) {
|
|
327
|
+
throw new ConfigurationError(
|
|
328
|
+
"appId is required. Get it from your Developer Dashboard."
|
|
329
|
+
);
|
|
330
|
+
}
|
|
315
331
|
if (!config.apiKey) {
|
|
316
332
|
throw new ConfigurationError(
|
|
317
333
|
"apiKey is required. Get it from your Developer Dashboard."
|
|
318
334
|
);
|
|
319
335
|
}
|
|
320
|
-
const endpoint = config.endpoint ?? "https://api.digitalsolution.com";
|
|
321
336
|
const httpClient = new HttpClient({
|
|
322
|
-
baseUrl: endpoint,
|
|
337
|
+
baseUrl: config.endpoint || "https://api.digitalsolution.com",
|
|
323
338
|
apiKey: config.apiKey,
|
|
324
339
|
timeout: config.timeout
|
|
325
340
|
});
|
|
326
|
-
this.auth = new AuthModule(config.apiKey, httpClient);
|
|
341
|
+
this.auth = new AuthModule(config.appId, config.apiKey, httpClient);
|
|
327
342
|
this.billing = new BillingModule(httpClient);
|
|
328
343
|
this.metering = new MeteringModule(httpClient);
|
|
329
344
|
}
|
package/dist/react.js
CHANGED
package/dist/react.mjs
CHANGED
package/package.json
CHANGED