@assinafy/sdk 2.4.2 → 2.5.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 +82 -20
- package/README.en.md +72 -14
- package/README.md +15 -10
- package/SECURITY.md +6 -5
- package/dist/index.d.mts +160 -38
- package/dist/index.d.ts +160 -38
- package/dist/index.js +167 -62
- package/dist/index.mjs +167 -62
- package/docs/API_COVERAGE.md +11 -0
- package/docs/COMPATIBILITY.md +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,61 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.5.1] - 2026-09-28
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- JSDoc reference corrections: missing response payloads and examples added to
|
|
15
|
+
public methods (`OAuthError.upgrade()`, `parseWwwAuthenticate()`,
|
|
16
|
+
`signerDocuments.search()`, `signerDocuments.confirmData()`,
|
|
17
|
+
`signerDocuments.getAssignment()`, `users.updateNotificationPreferences()`),
|
|
18
|
+
and stale `@throws` clauses corrected on `documents.details()` and
|
|
19
|
+
`signerDocuments.getCurrent()`. No behavior changes.
|
|
20
|
+
- `README.en.md` reaches parity with the pt-BR README: the Environments
|
|
21
|
+
section (sandbox base URL and explicit `issuer`/`authorizationEndpoint`
|
|
22
|
+
configuration), the verification/notification channel table with per-signer
|
|
23
|
+
costs, and the A1/A3 certificate-media note.
|
|
24
|
+
- The two browser URL helpers (`auth.getSocialLoginUrl()`,
|
|
25
|
+
`auth.getSocialLoginCallbackUrl()`) are listed in the coverage ledger's
|
|
26
|
+
compatibility extensions.
|
|
27
|
+
- OAuth callback examples use reserved example domains, and the CONTRIBUTING
|
|
28
|
+
live-test examples point at the sandbox API.
|
|
29
|
+
|
|
30
|
+
## [2.5.0] - 2026-09-25
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- `IDocumentVerification.agreement_code`: the agreement code printed on the
|
|
35
|
+
document certificate, returned by `documents.verify()` (`null` when the hash
|
|
36
|
+
does not verify).
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- `oauth.exchangeCode()`, `oauth.refreshToken()` and `oauth.revokeToken()` send
|
|
41
|
+
`application/x-www-form-urlencoded` bodies, the encoding RFC 6749 and RFC 7009
|
|
42
|
+
define. The fields are unchanged.
|
|
43
|
+
- `oauth.readAuthorizationCallback()` always checks `iss`. When the stored
|
|
44
|
+
request carries no `issuer`, the callback must come from
|
|
45
|
+
`https://auth.assinafy.com.br`; pass the stored request for any other
|
|
46
|
+
authorization server, such as the sandbox's.
|
|
47
|
+
|
|
48
|
+
### Security
|
|
49
|
+
|
|
50
|
+
- `oauth.refreshToken()` rejects a successful response that carries no
|
|
51
|
+
replacement `refresh_token` instead of returning it: the token that was sent
|
|
52
|
+
has already been retired, so the connection must be re-established.
|
|
53
|
+
- Migration: callers of `oauth.readAuthorizationCallback()` that stored only
|
|
54
|
+
`state` now get the production issuer check; callbacks without `iss` are
|
|
55
|
+
refused. Store and pass the whole authorization request.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- The OAuth documentation describes the refresh-token lifetime correctly: a
|
|
60
|
+
refresh token is valid for 30 days and every refresh returns a new one with a
|
|
61
|
+
fresh 30 days, so a connection only expires after 30 days without a refresh.
|
|
62
|
+
- The README OAuth example revokes the most recently saved refresh token, and
|
|
63
|
+
the docs say never to resend a refresh token after an ambiguous timeout.
|
|
64
|
+
|
|
10
65
|
## [2.4.2] - 2026-09-23
|
|
11
66
|
|
|
12
67
|
### Changed
|
|
@@ -270,8 +325,9 @@ type, or API surface changed.
|
|
|
270
325
|
request credentials or user payloads.
|
|
271
326
|
- Restored the official name-only signer request and account
|
|
272
327
|
`notification_sender_type` field. Both are now represented exactly as the
|
|
273
|
-
OpenAPI defines them; the
|
|
274
|
-
|
|
328
|
+
OpenAPI defines them; the sandbox's lagging rejection of
|
|
329
|
+
`notification_sender_type` is recorded as a known deployment divergence
|
|
330
|
+
without blocking unrelated endpoint tests.
|
|
275
331
|
- Restored the official public, code-free signer artifact download while
|
|
276
332
|
retaining an optional access-code argument for legacy deployments, and made
|
|
277
333
|
owner-only assignment-signer fields optional in signer-context responses.
|
|
@@ -285,12 +341,13 @@ type, or API surface changed.
|
|
|
285
341
|
- Clarified that webhook HMAC verification is an opt-in utility: the current
|
|
286
342
|
Assinafy OpenAPI document does not specify a signing header or algorithm.
|
|
287
343
|
|
|
288
|
-
###
|
|
344
|
+
### Additional fixes (completed 2026-07-19)
|
|
289
345
|
|
|
290
|
-
|
|
291
|
-
and the OpenAPI reference: every safely runnable operation was
|
|
292
|
-
or legal
|
|
293
|
-
SDK was
|
|
346
|
+
Validated against the live sandbox API (`https://sandbox.assinafy.com.br/v1`)
|
|
347
|
+
and the OpenAPI reference: every safely runnable operation was exercised live,
|
|
348
|
+
operations that depend on fixtures or legal consent were recorded as explicit
|
|
349
|
+
skips, and the SDK was brought in line with the observed request/response
|
|
350
|
+
shapes.
|
|
294
351
|
|
|
295
352
|
#### Fixed
|
|
296
353
|
|
|
@@ -471,10 +528,11 @@ SDK was reconciled against the observed request/response shapes.
|
|
|
471
528
|
|
|
472
529
|
## [1.5.0] - 2026-06-05
|
|
473
530
|
|
|
474
|
-
Full
|
|
475
|
-
re-
|
|
476
|
-
Closes the last coverage gap (Template
|
|
477
|
-
endpoint, tightens types to the real
|
|
531
|
+
Full coverage of [the live API docs](https://api.assinafy.com.br/v1/docs),
|
|
532
|
+
re-validated end-to-end against the live **sandbox**
|
|
533
|
+
(`https://sandbox.assinafy.com.br/v1`). Closes the last coverage gap (Template
|
|
534
|
+
create/update/delete), removes a dead endpoint, tightens types to the real
|
|
535
|
+
wire shapes, and modernises the toolchain.
|
|
478
536
|
|
|
479
537
|
### Removed
|
|
480
538
|
|
|
@@ -549,9 +607,9 @@ including template create/get/update/downloadPage/delete.
|
|
|
549
607
|
|
|
550
608
|
## [1.4.0] - 2026-05-27
|
|
551
609
|
|
|
552
|
-
Full
|
|
553
|
-
re-validated end-to-end against the live API. Closes the last coverage gap
|
|
554
|
-
and fixes signer-creation and type accuracy.
|
|
610
|
+
Full coverage of [the live API docs](https://api.assinafy.com.br/v1/docs),
|
|
611
|
+
re-validated end-to-end against the live API. Closes the last coverage gap
|
|
612
|
+
(Tags) and fixes signer-creation and type accuracy.
|
|
555
613
|
|
|
556
614
|
### Added
|
|
557
615
|
|
|
@@ -593,8 +651,8 @@ CPF normalisation. All read and write paths re-verified against the live API
|
|
|
593
651
|
|
|
594
652
|
## [1.3.0] - 2026-05-12
|
|
595
653
|
|
|
596
|
-
100% endpoint coverage of [the live API docs](https://api.assinafy.com.br/v1/docs)
|
|
597
|
-
|
|
654
|
+
100% endpoint coverage of [the live API docs](https://api.assinafy.com.br/v1/docs),
|
|
655
|
+
validated end-to-end against the live API.
|
|
598
656
|
|
|
599
657
|
### Added
|
|
600
658
|
|
|
@@ -634,8 +692,8 @@ live API.
|
|
|
634
692
|
|
|
635
693
|
## [1.2.0] - 2026-05-06
|
|
636
694
|
|
|
637
|
-
|
|
638
|
-
fields
|
|
695
|
+
Adds the Template resource and missing Document operations, and expands the
|
|
696
|
+
signer fields with `cpf` and `whatsapp_phone_number`.
|
|
639
697
|
|
|
640
698
|
### Added
|
|
641
699
|
|
|
@@ -646,7 +704,7 @@ fields (`cpf`, `whatsapp_phone_number`) with the PHP SDK and n8n node.
|
|
|
646
704
|
- `createFromTemplate(templateId, signers, options?, accountId?)` — `POST /accounts/{accountId}/templates/{templateId}/documents`
|
|
647
705
|
- `estimateCostFromTemplate(templateId, signers, accountId?)` — `POST /accounts/{accountId}/templates/{templateId}/documents/estimate-cost`
|
|
648
706
|
- `verify(hash)` — `GET /documents/{hash}/verify`
|
|
649
|
-
- **`cpf` field** in `ICreateSignerPayload`, `IUpdateSignerPayload`, `ISigner`, and `IUploadAndRequestSignaturesSigner`. The `normaliseSignerPayload` helper strips non-digit characters before sending
|
|
707
|
+
- **`cpf` field** in `ICreateSignerPayload`, `IUpdateSignerPayload`, `ISigner`, and `IUploadAndRequestSignaturesSigner`. The `normaliseSignerPayload` helper strips non-digit characters before sending.
|
|
650
708
|
- New types: `ITemplateListItem`, `ITemplateListResponse`, `ITemplateDetailsResponse`, `ITemplateRole`, `ITemplateSigner`, `ICreateDocumentFromTemplateOptions`.
|
|
651
709
|
- `TemplateResource` exported from `index.ts`.
|
|
652
710
|
|
|
@@ -667,7 +725,11 @@ fields (`cpf`, `whatsapp_phone_number`) with the PHP SDK and n8n node.
|
|
|
667
725
|
- High-level `uploadAndRequestSignatures` helper on `AssinafyClient`.
|
|
668
726
|
- `PaginatedResult<T>` with parsed `X-Pagination-*` header meta.
|
|
669
727
|
|
|
670
|
-
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.
|
|
728
|
+
[Unreleased]: https://github.com/assinafy/typescript-sdk/compare/v2.5.1...HEAD
|
|
729
|
+
[2.5.1]: https://github.com/assinafy/typescript-sdk/compare/v2.5.0...v2.5.1
|
|
730
|
+
[2.5.0]: https://github.com/assinafy/typescript-sdk/compare/v2.4.2...v2.5.0
|
|
731
|
+
[2.4.2]: https://github.com/assinafy/typescript-sdk/compare/v2.4.1...v2.4.2
|
|
732
|
+
[2.4.1]: https://github.com/assinafy/typescript-sdk/compare/v2.4.0...v2.4.1
|
|
671
733
|
[2.4.0]: https://github.com/assinafy/typescript-sdk/compare/v2.3.0...v2.4.0
|
|
672
734
|
[2.3.0]: https://github.com/assinafy/typescript-sdk/compare/v2.2.0...v2.3.0
|
|
673
735
|
[2.2.0]: https://github.com/assinafy/typescript-sdk/compare/v2.1.2...v2.2.0
|
package/README.en.md
CHANGED
|
@@ -45,7 +45,8 @@ afterwards.
|
|
|
45
45
|
[signer-side endpoints](#signer-side-endpoints)
|
|
46
46
|
|
|
47
47
|
**Everything else** — [High-level helper](#high-level-helper) ·
|
|
48
|
-
[Errors](#errors) · [
|
|
48
|
+
[Errors](#errors) · [Environments](#environments) ·
|
|
49
|
+
[Development](#development) · [License](#license)
|
|
49
50
|
|
|
50
51
|
## Requirements
|
|
51
52
|
|
|
@@ -53,6 +54,8 @@ afterwards.
|
|
|
53
54
|
CJS and ESM imports are tested on 22 (maintenance LTS), 24 (active LTS), and
|
|
54
55
|
26 (Current); Node 20 reached end-of-life in April 2026 and is unsupported.
|
|
55
56
|
- or Bun 1.4.0 (the version pinned for development and CI)
|
|
57
|
+
- HTTPS with TLS 1.2 or higher, which the API requires; Node.js 22+ and Bun
|
|
58
|
+
negotiate it by default
|
|
56
59
|
|
|
57
60
|
## Installation
|
|
58
61
|
|
|
@@ -170,18 +173,18 @@ const client = new AssinafyClient(); // no credentials needed
|
|
|
170
173
|
// completes PKCE, `nonce` validates the id_token.
|
|
171
174
|
const request = await client.oauth.createAuthorizationUrl({
|
|
172
175
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
173
|
-
redirectUri: 'https://myapp.com/oauth/callback',
|
|
176
|
+
redirectUri: 'https://myapp.example.com/oauth/callback',
|
|
174
177
|
scopes: ['documents:read', 'documents:write', 'offline_access'],
|
|
175
178
|
});
|
|
176
179
|
session.oauth = request;
|
|
177
180
|
response.redirect(request.url); // full page navigation
|
|
178
181
|
|
|
179
|
-
// 2 — on https://myapp.com/oauth/callback
|
|
182
|
+
// 2 — on https://myapp.example.com/oauth/callback
|
|
180
183
|
const { code } = client.oauth.readAuthorizationCallback(query, session.oauth);
|
|
181
184
|
const tokens = await client.oauth.exchangeCode({
|
|
182
185
|
code,
|
|
183
186
|
codeVerifier: session.oauth.codeVerifier,
|
|
184
|
-
redirectUri: 'https://myapp.com/oauth/callback',
|
|
187
|
+
redirectUri: 'https://myapp.example.com/oauth/callback',
|
|
185
188
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
186
189
|
clientSecret: process.env.ASSINAFY_CLIENT_SECRET, // confidential apps only
|
|
187
190
|
});
|
|
@@ -202,9 +205,10 @@ const renewed = await client.oauth.refreshToken({
|
|
|
202
205
|
});
|
|
203
206
|
await connection.save({ refreshToken: renewed.refresh_token }); // BEFORE using it
|
|
204
207
|
|
|
205
|
-
// 5 — when the user disconnects
|
|
208
|
+
// 5 — when the user disconnects: revoke the token you saved most recently
|
|
209
|
+
const current = await connection.load(); // never a retired copy
|
|
206
210
|
await client.oauth.revokeToken({
|
|
207
|
-
token:
|
|
211
|
+
token: current.refreshToken,
|
|
208
212
|
tokenTypeHint: 'refresh_token',
|
|
209
213
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
210
214
|
clientSecret: process.env.ASSINAFY_CLIENT_SECRET,
|
|
@@ -274,11 +278,15 @@ try {
|
|
|
274
278
|
|
|
275
279
|
Refresh tokens **rotate**: every refresh returns a new one and retires the old
|
|
276
280
|
one, and replaying a retired token ends the entire connection. Persist the new
|
|
277
|
-
value before using the response,
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
value before using the response, and never refresh one connection twice
|
|
282
|
+
concurrently. Treat a timeout as "it may have worked": re-read your stored
|
|
283
|
+
token, and if it is still the one you sent, never send it again — ask the user
|
|
284
|
+
to reconnect. Only a failure that provably happened before sending (DNS,
|
|
285
|
+
refused connection, TLS handshake) is safe to retry. A refresh token is valid for 30 days, and every
|
|
286
|
+
refresh returns a new one with a fresh 30 days: a connection only expires if
|
|
287
|
+
your app goes 30 days without refreshing it, after which the user has to
|
|
288
|
+
connect again. The authorize/token endpoints accept 50 requests per minute per
|
|
289
|
+
IP.
|
|
282
290
|
|
|
283
291
|
AI assistants such as Claude, Claude Code and ChatGPT connect to Assinafy
|
|
284
292
|
through their own connector settings; your users do not need you to register
|
|
@@ -568,8 +576,8 @@ can sign in parallel.
|
|
|
568
576
|
accessCode, entries)` with a non-empty array of
|
|
569
577
|
`{ itemId, fieldId, pageId, value }`. A virtual signer must confirm their data
|
|
570
578
|
before signing. A `DigitalCertificate` signer cannot call `sign`; that branch
|
|
571
|
-
uses Assinafy's certificate
|
|
572
|
-
|
|
579
|
+
uses Assinafy's certificate flow, described in
|
|
580
|
+
[ICP-Brasil digital certificate](#icp-brasil-digital-certificate).
|
|
573
581
|
|
|
574
582
|
### 5. Observe completion and download artifacts
|
|
575
583
|
|
|
@@ -819,6 +827,19 @@ Keep the email flow as the default. Enable either branch below only after the
|
|
|
819
827
|
workspace has the required plan or feature and the returned cost estimate is
|
|
820
828
|
acceptable.
|
|
821
829
|
|
|
830
|
+
The verification method and the notification method are **coupled**: send one,
|
|
831
|
+
both, or neither — the missing side is inferred. With neither, both default
|
|
832
|
+
to `Email`.
|
|
833
|
+
|
|
834
|
+
| Verification | How the signer proves who they are | Allowed notification | Cost per signer |
|
|
835
|
+
| --- | --- | --- | --- |
|
|
836
|
+
| `Email` *(default)* | One-time code (OTP) by email | `Email` | Free |
|
|
837
|
+
| `Whatsapp` | One-time code (OTP) by WhatsApp | `Whatsapp` | 0.45 credit (the notification), paid plans only |
|
|
838
|
+
| `DigitalCertificate` | The signer signs with their **own ICP-Brasil certificate — A1 or A3 —** through the Web PKI extension, producing a **qualified PAdES signature** | `Email` **or** `Whatsapp` | 2 credits + the notification |
|
|
839
|
+
|
|
840
|
+
Exactly one notification method per signer. The SDK rejects an invalid
|
|
841
|
+
combination before the request; the API would answer `400`.
|
|
842
|
+
|
|
822
843
|
#### WhatsApp verification and notification
|
|
823
844
|
|
|
824
845
|
WhatsApp is available only on paid subscriptions and costs 0.45 credit per
|
|
@@ -864,6 +885,14 @@ signer's `government_id`, and exactly one certificate signer in that signing
|
|
|
864
885
|
step. It costs two credits per certificate signer in addition to the selected
|
|
865
886
|
notification cost.
|
|
866
887
|
|
|
888
|
+
**A1 and A3 are certificate media**, chosen by the signer in their browser at
|
|
889
|
+
signing time: A1 lives in software (a file on the machine) and A3 in hardware
|
|
890
|
+
(a token or smartcard). The API models both with the single
|
|
891
|
+
`DigitalCertificate` value — there is no `A1`/`A3` field to send, and the
|
|
892
|
+
resulting PAdES signature is qualified in either case. Certificate signers
|
|
893
|
+
complete a Web PKI handshake on two production-only routes that are not part
|
|
894
|
+
of this SDK.
|
|
895
|
+
|
|
867
896
|
```ts
|
|
868
897
|
const certificateSigner = await client.signers.update(signerId, {
|
|
869
898
|
government_id: '390.533.447-05',
|
|
@@ -1333,7 +1362,8 @@ whether to retry the workflow.
|
|
|
1333
1362
|
## Errors
|
|
1334
1363
|
|
|
1335
1364
|
HTTP methods reject with an `AssinafyError` subclass. Synchronous helpers such
|
|
1336
|
-
as `getSocialLoginUrl()`
|
|
1365
|
+
as `getSocialLoginUrl()` and `readAuthorizationCallback()` can throw
|
|
1366
|
+
`ValidationError` before any request.
|
|
1337
1367
|
|
|
1338
1368
|
```ts
|
|
1339
1369
|
import { ApiError, OAuthError, ValidationError, NetworkError, AssinafyError } from '@assinafy/sdk';
|
|
@@ -1358,6 +1388,34 @@ try {
|
|
|
1358
1388
|
}
|
|
1359
1389
|
```
|
|
1360
1390
|
|
|
1391
|
+
## Environments
|
|
1392
|
+
|
|
1393
|
+
| | |
|
|
1394
|
+
| --- | --- |
|
|
1395
|
+
| Production | `https://api.assinafy.com.br/v1` |
|
|
1396
|
+
| Sandbox | `https://sandbox.assinafy.com.br/v1` |
|
|
1397
|
+
|
|
1398
|
+
The sandbox runs its own authorization server at
|
|
1399
|
+
`https://auth-sandbox.assinafy.com.br`, with the consent screen at
|
|
1400
|
+
`/oauth/authorize`. Its discovery documents are unreachable: nginx refuses
|
|
1401
|
+
paths that start with a dot, so pass the endpoints explicitly:
|
|
1402
|
+
|
|
1403
|
+
```ts
|
|
1404
|
+
const client = new AssinafyClient({ baseUrl: 'https://sandbox.assinafy.com.br/v1' });
|
|
1405
|
+
|
|
1406
|
+
const request = await client.oauth.createAuthorizationUrl({
|
|
1407
|
+
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
1408
|
+
redirectUri: 'https://myapp.example.com/oauth/callback',
|
|
1409
|
+
scopes: ['documents:read'],
|
|
1410
|
+
issuer: 'https://auth-sandbox.assinafy.com.br',
|
|
1411
|
+
authorizationEndpoint: 'https://auth-sandbox.assinafy.com.br/oauth/authorize',
|
|
1412
|
+
});
|
|
1413
|
+
```
|
|
1414
|
+
|
|
1415
|
+
The token, revocation and userinfo endpoints follow the configured `baseUrl`.
|
|
1416
|
+
Confirm that the sandbox exposes them before running the exchange step
|
|
1417
|
+
there — see [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md).
|
|
1418
|
+
|
|
1361
1419
|
## Development
|
|
1362
1420
|
|
|
1363
1421
|
```bash
|
package/README.md
CHANGED
|
@@ -49,6 +49,7 @@ recurso. Leia na ordem na primeira vez; use como referência depois.
|
|
|
49
49
|
empacotados são testados no 22 (LTS de manutenção), 24 (LTS ativo) e 26 (Current). O Node 20
|
|
50
50
|
chegou ao fim da vida em abril de 2026 e não é suportado.
|
|
51
51
|
- ou Bun 1.4.0 (versão fixada no desenvolvimento e na CI)
|
|
52
|
+
- HTTPS com TLS 1.2 ou superior, exigido pela API; o Node.js 22+ e o Bun já negociam isso por padrão
|
|
52
53
|
|
|
53
54
|
## Instalação
|
|
54
55
|
|
|
@@ -164,18 +165,18 @@ const client = new AssinafyClient(); // nenhuma credencial nece
|
|
|
164
165
|
// PKCE e `nonce` valida o id_token.
|
|
165
166
|
const requisicao = await client.oauth.createAuthorizationUrl({
|
|
166
167
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
167
|
-
redirectUri: 'https://meuapp.com.br/oauth/callback',
|
|
168
|
+
redirectUri: 'https://meuapp.exemplo.com.br/oauth/callback',
|
|
168
169
|
scopes: ['documents:read', 'documents:write', 'offline_access'],
|
|
169
170
|
});
|
|
170
171
|
sessao.oauth = requisicao;
|
|
171
172
|
resposta.redirect(requisicao.url); // navegação de página inteira
|
|
172
173
|
|
|
173
|
-
// 2 — em https://meuapp.com.br/oauth/callback
|
|
174
|
+
// 2 — em https://meuapp.exemplo.com.br/oauth/callback
|
|
174
175
|
const { code } = client.oauth.readAuthorizationCallback(query, sessao.oauth);
|
|
175
176
|
const tokens = await client.oauth.exchangeCode({
|
|
176
177
|
code,
|
|
177
178
|
codeVerifier: sessao.oauth.codeVerifier,
|
|
178
|
-
redirectUri: 'https://meuapp.com.br/oauth/callback',
|
|
179
|
+
redirectUri: 'https://meuapp.exemplo.com.br/oauth/callback',
|
|
179
180
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
180
181
|
clientSecret: process.env.ASSINAFY_CLIENT_SECRET, // só aplicações confidenciais
|
|
181
182
|
});
|
|
@@ -196,9 +197,10 @@ const renovado = await client.oauth.refreshToken({
|
|
|
196
197
|
});
|
|
197
198
|
await conexao.save({ refreshToken: renovado.refresh_token }); // ANTES de usar
|
|
198
199
|
|
|
199
|
-
// 5 — quando o usuário desconectar
|
|
200
|
+
// 5 — quando o usuário desconectar: revogue o token salvo mais recentemente
|
|
201
|
+
const atual = await conexao.load(); // nunca uma cópia aposentada
|
|
200
202
|
await client.oauth.revokeToken({
|
|
201
|
-
token:
|
|
203
|
+
token: atual.refreshToken,
|
|
202
204
|
tokenTypeHint: 'refresh_token',
|
|
203
205
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
204
206
|
clientSecret: process.env.ASSINAFY_CLIENT_SECRET,
|
|
@@ -267,10 +269,13 @@ try {
|
|
|
267
269
|
|
|
268
270
|
Refresh tokens **rotacionam**: cada renovação devolve um novo e aposenta o anterior, e reutilizar um
|
|
269
271
|
token aposentado encerra a conexão inteira. Persista o novo valor antes de usar a resposta, trate um
|
|
270
|
-
timeout como "talvez tenha funcionado"
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
timeout como "talvez tenha funcionado" e nunca renove a mesma conexão duas vezes em paralelo. Após
|
|
273
|
+
um timeout, releia o token guardado; se ainda for o enviado, nunca o envie de novo — peça ao
|
|
274
|
+
usuário para reconectar. Só uma falha que comprovadamente ocorreu antes do envio (DNS, conexão
|
|
275
|
+
recusada, handshake TLS) pode ser repetida. Um refresh token vale 30 dias, e cada renovação
|
|
276
|
+
devolve um novo com mais 30 dias: a conexão só expira se o seu app passar 30 dias sem renová-la, e
|
|
277
|
+
aí o usuário precisa conectar de novo. Os endpoints de autorização e token aceitam 50 requisições
|
|
278
|
+
por minuto por IP.
|
|
274
279
|
|
|
275
280
|
Assistentes de IA como Claude, Claude Code e ChatGPT se conectam à Assinafy pelas próprias
|
|
276
281
|
configurações de conector; seus usuários não precisam que você registre nada para eles.
|
|
@@ -1374,7 +1379,7 @@ const client = new AssinafyClient({ baseUrl: 'https://sandbox.assinafy.com.br/v1
|
|
|
1374
1379
|
|
|
1375
1380
|
const requisicao = await client.oauth.createAuthorizationUrl({
|
|
1376
1381
|
clientId: process.env.ASSINAFY_CLIENT_ID!,
|
|
1377
|
-
redirectUri: 'https://meuapp.com.br/oauth/callback',
|
|
1382
|
+
redirectUri: 'https://meuapp.exemplo.com.br/oauth/callback',
|
|
1378
1383
|
scopes: ['documents:read'],
|
|
1379
1384
|
issuer: 'https://auth-sandbox.assinafy.com.br',
|
|
1380
1385
|
authorizationEndpoint: 'https://auth-sandbox.assinafy.com.br/oauth/authorize',
|
package/SECURITY.md
CHANGED
|
@@ -43,11 +43,12 @@ opportunity to upgrade.
|
|
|
43
43
|
- Protected resources require explicit account credentials. Public,
|
|
44
44
|
authentication, and signer-access-code flows use an auth-free transport so
|
|
45
45
|
configured account credentials are not sent to public endpoints.
|
|
46
|
-
- Consumers must use HTTPS endpoints and protect all SDK
|
|
47
|
-
secrets. The client enforces this: a `baseUrl` using
|
|
48
|
-
rejected unless its host is loopback, so a credential
|
|
49
|
-
clear to a remote host. Debug logging and error
|
|
50
|
-
for response data before being enabled in
|
|
46
|
+
- Consumers must use HTTPS endpoints (TLS 1.2 or higher) and protect all SDK
|
|
47
|
+
configuration as secrets. The client enforces this: a `baseUrl` using
|
|
48
|
+
plaintext `http` is rejected unless its host is loopback, so a credential
|
|
49
|
+
cannot be sent in the clear to a remote host. Debug logging and error
|
|
50
|
+
telemetry must be reviewed for response data before being enabled in
|
|
51
|
+
production.
|
|
51
52
|
- An OAuth `client_secret` belongs only on a server you control: never in
|
|
52
53
|
browser code, a mobile application, or a repository. A public application has
|
|
53
54
|
no secret and authenticates with PKCE alone. The SDK sends the token and
|