@assinafy/cli 2.2.0 → 2.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.
- package/README.en.md +2 -1
- package/README.md +2 -2
- package/dist/api.cjs +19 -6
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +19 -6
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +55 -20
- package/dist/types/api/resources/assignments.d.ts +0 -1
- package/dist/types/api/resources/assignments.d.ts.map +1 -1
- package/dist/types/api/resources/oauth.d.ts +4 -1
- package/dist/types/api/resources/oauth.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +9 -3
- package/dist/types/api/types.d.ts.map +1 -1
- package/docs/api-operations.json +2 -2
- package/docs/api-reference.md +40 -18
- package/docs/oauth-guide.md +23 -14
- package/docs/oauth.md +4 -4
- package/docs/sdk-reference.md +2 -2
- package/package.json +1 -1
package/docs/oauth-guide.md
CHANGED
|
@@ -4,7 +4,7 @@ Assinafy uses OAuth 2.1 authorization code with mandatory S256 PKCE for public a
|
|
|
4
4
|
|
|
5
5
|
Use a separate connection for each customer workspace. An OAuth access token carries the consenting user's permissions, the granted scopes, and exactly one workspace. It never grants billing, workspace creation/deletion, API-key management, or other platform administration. An API key remains available for direct owner integrations. Signer access codes remain a separate authentication mechanism.
|
|
6
6
|
|
|
7
|
-
Use `oauth.userinfo()` for the consenting user's profile. Production rejects OAuth application tokens for `users.self`, user statistics and notification preferences, workspace statistics, API-key lookup
|
|
7
|
+
Use `oauth.userinfo()` for the consenting user's profile. Production rejects OAuth application tokens for `users.self`, user statistics and notification preferences, workspace statistics, and API-key lookup. These operations require the owner or first-party credential supported by their endpoint. Per the live OAuth guide, `documents:read` covers webhook event types, webhook delivery history and the WhatsApp notifications sent for an assignment, and `account:read` covers reading the workspace's webhook subscription. Requesting additional OAuth scopes does not grant access to them.
|
|
8
8
|
|
|
9
9
|
## Register the application
|
|
10
10
|
|
|
@@ -34,12 +34,13 @@ The resource indicator is an origin, distinct from the SDK `baseUrl`, which incl
|
|
|
34
34
|
| `templates:read` | Read templates. |
|
|
35
35
|
| `templates:write` | Permitted template operations. |
|
|
36
36
|
| `account:read` | Read the selected workspace. |
|
|
37
|
+
| `webhooks:write` | Change webhook delivery and deactivate the subscription. Requested by `oauth connect` by default. |
|
|
37
38
|
| `openid` | Request OpenID Connect identity and UserInfo. |
|
|
38
39
|
| `profile` | Include permitted profile claims. |
|
|
39
40
|
| `email` | Include permitted email claims. |
|
|
40
41
|
| `offline_access` | Request rotating refresh tokens for background work. |
|
|
41
42
|
|
|
42
|
-
`oauth connect` requests all
|
|
43
|
+
`oauth connect` requests all ten published scopes by default, so the CLI can access documents, templates, the selected workspace, webhook settings and UserInfo, and obtain refresh tokens. The public application registration must permit all ten. Existing connections need a new authorization with the larger scope set; refreshing an old token does not add permissions. Use `--scope` to explicitly select fewer scopes when needed. For other applications, request only scopes they use. Resource metadata lists API scopes; authorization-server metadata also describes authentication features such as `offline_access`. The returned `scope` string is authoritative for the access token; do not infer granted scopes from what the browser requested. It never lists `offline_access`, even when granted: a `refresh_token` in the response is the only signal that refresh is available. A scope never bypasses a user's role or the token's workspace boundary. Billing, subscriptions, workspace membership, credential management, and administration remain unavailable to OAuth tokens; those CLI operations require the non-OAuth credential documented for each endpoint.
|
|
43
44
|
|
|
44
45
|
## Discover and start authorization
|
|
45
46
|
|
|
@@ -62,7 +63,7 @@ const request = await oauthClient.oauth.authorize({
|
|
|
62
63
|
{
|
|
63
64
|
"resource": "https://api.assinafy.com.br",
|
|
64
65
|
"authorization_servers": ["https://auth.assinafy.com.br"],
|
|
65
|
-
"scopes_supported": ["documents:read", "documents:write", "templates:read", "templates:write", "account:read", "openid", "profile", "email"],
|
|
66
|
+
"scopes_supported": ["documents:read", "documents:write", "templates:read", "templates:write", "account:read", "webhooks:write", "openid", "profile", "email"],
|
|
66
67
|
"bearer_methods_supported": ["header"]
|
|
67
68
|
}
|
|
68
69
|
```
|
|
@@ -77,7 +78,7 @@ const request = await oauthClient.oauth.authorize({
|
|
|
77
78
|
"revocation_endpoint": "https://api.assinafy.com.br/v1/oauth/revoke",
|
|
78
79
|
"userinfo_endpoint": "https://api.assinafy.com.br/v1/oauth/userinfo",
|
|
79
80
|
"jwks_uri": "https://auth.assinafy.com.br/.well-known/jwks.json",
|
|
80
|
-
"scopes_supported": ["documents:read", "documents:write", "templates:read", "templates:write", "account:read", "openid", "profile", "email", "offline_access"],
|
|
81
|
+
"scopes_supported": ["documents:read", "documents:write", "templates:read", "templates:write", "account:read", "webhooks:write", "openid", "profile", "email", "offline_access"],
|
|
81
82
|
"response_types_supported": ["code"],
|
|
82
83
|
"grant_types_supported": ["authorization_code", "refresh_token"],
|
|
83
84
|
"code_challenge_methods_supported": ["S256"],
|
|
@@ -142,7 +143,7 @@ For applications that already perform callback validation, `token(payload)` acce
|
|
|
142
143
|
}
|
|
143
144
|
```
|
|
144
145
|
|
|
145
|
-
The SDK
|
|
146
|
+
The SDK sends these fields form-encoded (`application/x-www-form-urlencoded`). Omit `client_secret` for public clients. `resource` is optional in the token request; if provided, use the authorization resource. A direct `token()` call does not validate a browser callback, state, issuer, or session. The verifier must contain 43–128 RFC 7636 unreserved characters.
|
|
146
147
|
|
|
147
148
|
Both methods return the direct `IOAuthTokenResponse`, without an Assinafy `{ data }` envelope:
|
|
148
149
|
|
|
@@ -180,9 +181,10 @@ Persist the workspace ID with the application's tenant/customer ID, issuer, reso
|
|
|
180
181
|
|
|
181
182
|
## Refresh without losing the connection
|
|
182
183
|
|
|
183
|
-
`token(payload)` accepts the refresh grant:
|
|
184
|
+
`token(payload)` accepts the refresh grant. In these examples, `tokenStore` stands for the application's encrypted per-connection storage. Hold the connection's refresh lock from reading the stored token until the new response is saved:
|
|
184
185
|
|
|
185
186
|
```ts
|
|
187
|
+
const storedRefreshToken = await tokenStore.getRefreshToken(connectionId);
|
|
186
188
|
const next = await oauthClient.oauth.token({
|
|
187
189
|
grant_type: 'refresh_token',
|
|
188
190
|
client_id: process.env.ASSINAFY_OAUTH_CLIENT_ID!,
|
|
@@ -190,9 +192,11 @@ const next = await oauthClient.oauth.token({
|
|
|
190
192
|
refresh_token: storedRefreshToken,
|
|
191
193
|
resource: 'https://api.assinafy.com.br',
|
|
192
194
|
});
|
|
195
|
+
// storedRefreshToken is now retired. Save the whole response, with its new refresh token, before using it.
|
|
196
|
+
await tokenStore.save(connectionId, next);
|
|
193
197
|
```
|
|
194
198
|
|
|
195
|
-
The complete
|
|
199
|
+
The complete payload, sent form-encoded, is:
|
|
196
200
|
|
|
197
201
|
```json
|
|
198
202
|
{
|
|
@@ -206,7 +210,9 @@ The complete wire body is:
|
|
|
206
210
|
|
|
207
211
|
Its response has the same token shape above, with new access and refresh values. Each successful refresh consumes the previous refresh token. Reusing it revokes the entire connection. Serialize refreshes per connection across every worker and process; atomically store the complete new response before releasing the lock or using it. A lock local to one process is insufficient for a distributed application.
|
|
208
212
|
|
|
209
|
-
|
|
213
|
+
If a successful refresh response has no new `refresh_token`, or returns the submitted one, `token()` throws `ValidationError` with `errors.field` set to `'refresh_token'` instead of returning the response. The submitted token may already be retired: do not reuse it; mark the connection for reconnection.
|
|
214
|
+
|
|
215
|
+
Access tokens last one hour. A refresh token is valid for 30 days, and every refresh returns a new one with a fresh 30 days, so a connection expires only after 30 days without a refresh; after that, the user must connect again. Approving the application again with different permissions immediately invalidates the previous tokens; treat that as a reconnect. A timeout means the refresh may have succeeded: re-read the stored token before retrying and never replay the old one blindly; if nothing new was stored, mark that connection for recovery/reconnection. On `invalid_grant`, require new consent. The SDK has no automatic refresh or request retry and never persists tokens. Construct a new authenticated `AssinafyClient` with the current access token after rotation.
|
|
210
216
|
|
|
211
217
|
## UserInfo and disconnect
|
|
212
218
|
|
|
@@ -227,7 +233,7 @@ const identity = await new AssinafyClient({ token: tokens.access_token }).oauth.
|
|
|
227
233
|
|
|
228
234
|
Only `sub` is mandatory; other claims can be missing or null. Prefer the stable subject over an email address as an identity key, and include the issuer in that key.
|
|
229
235
|
|
|
230
|
-
To disconnect, `revoke(payload)`
|
|
236
|
+
To disconnect, `revoke(payload)` sends these form fields:
|
|
231
237
|
|
|
232
238
|
```json
|
|
233
239
|
{
|
|
@@ -239,21 +245,23 @@ To disconnect, `revoke(payload)` posts:
|
|
|
239
245
|
```
|
|
240
246
|
|
|
241
247
|
```ts
|
|
248
|
+
// Under the same lock, read back the latest saved token: each refresh retires the previous one.
|
|
249
|
+
const latestRefreshToken = await tokenStore.getRefreshToken(connectionId);
|
|
242
250
|
await oauthClient.oauth.revoke({
|
|
243
|
-
token:
|
|
251
|
+
token: latestRefreshToken,
|
|
244
252
|
client_id: process.env.ASSINAFY_OAUTH_CLIENT_ID!,
|
|
245
253
|
client_secret: process.env.ASSINAFY_OAUTH_CLIENT_SECRET,
|
|
246
254
|
token_type_hint: 'refresh_token',
|
|
247
255
|
});
|
|
248
256
|
```
|
|
249
257
|
|
|
250
|
-
`token_type_hint` is optional and accepts `access_token` or `refresh_token`. Successful revocation returns HTTP 200 with no required response body; the SDK resolves to `undefined`. Unknown/already revoked tokens also succeed for an authenticated client. Invalid client authentication returns 401. Revoke the connection before removing local credentials when possible, then mark it disconnected and stop its background work. CLI success prints `{ "revoked": true }`, a local confirmation rather than an API response payload.
|
|
258
|
+
`token_type_hint` is optional and accepts `access_token` or `refresh_token`. Successful revocation returns HTTP 200 with no required response body; the SDK resolves to `undefined`. Unknown/already revoked tokens also succeed for an authenticated client, so revoking a retired refresh token reports success while its replacement stays active. Invalid client authentication returns 401. Revoke the connection before removing local credentials when possible, then mark it disconnected and stop its background work. CLI success prints `{ "revoked": true }`, a local confirmation rather than an API response payload.
|
|
251
259
|
|
|
252
260
|
## CLI flow
|
|
253
261
|
|
|
254
262
|
### Automatic browser return
|
|
255
263
|
|
|
256
|
-
The distributed CLI includes the official **Public** application's client ID, `96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88`. This public identifier is not a secret. The CLI uses PKCE S256 and the scopes `account:read documents:read documents:write templates:read templates:write openid profile email offline_access`; keep the registered permissions consistent with the requested scopes. No client secret is used by `oauth connect`, including when `ASSINAFY_OAUTH_CLIENT_SECRET` is set for another application.
|
|
264
|
+
The distributed CLI includes the official **Public** application's client ID, `96BZZ0sZTb2NkEXt1GCaIRCTprI2YKHZr8JDHawuXUyCLC88`. This public identifier is not a secret. The CLI uses PKCE S256 and the scopes `account:read documents:read documents:write templates:read templates:write webhooks:write openid profile email offline_access`; keep the registered permissions consistent with the requested scopes. No client secret is used by `oauth connect`, including when `ASSINAFY_OAUTH_CLIENT_SECRET` is set for another application.
|
|
257
265
|
|
|
258
266
|
Application maintainers must deploy the callback from `integrations-generic-callback` and register this exact HTTPS URI, without an extension or trailing slash:
|
|
259
267
|
|
|
@@ -279,7 +287,7 @@ assinafy documents list --json
|
|
|
279
287
|
| --- | --- |
|
|
280
288
|
| `--client-id <id>` | Override the bundled public application ID; takes precedence over `ASSINAFY_OAUTH_CLIENT_ID`. |
|
|
281
289
|
| `--redirect-uri <uri>` | Registered HTTPS relay URI; defaults to the extensionless URL above. Query parameters and fragments are unsupported for this browser relay. |
|
|
282
|
-
| `--scope '<scopes>'` | Space-separated scopes; defaults to `account:read documents:read documents:write templates:read templates:write openid profile email offline_access`. |
|
|
290
|
+
| `--scope '<scopes>'` | Space-separated scopes; defaults to `account:read documents:read documents:write templates:read templates:write webhooks:write openid profile email offline_access`. |
|
|
283
291
|
| `--timeout <seconds>` | Browser response deadline, 1–600 seconds; default 180. API calls use the SDK's network timeout. |
|
|
284
292
|
| `--no-browser` | Print the authorization URL for manual opening; the local listener still receives the return automatically. |
|
|
285
293
|
|
|
@@ -328,7 +336,7 @@ Select the single returned workspace as `ASSINAFY_ACCOUNT_ID`. Remove the consum
|
|
|
328
336
|
|
|
329
337
|
An API key wins when both credential types are supplied at the same precedence level. A higher-precedence `--token` overrides environment or profile credentials as a group. Avoid leaving a stale `ASSINAFY_API_KEY` in an OAuth session.
|
|
330
338
|
|
|
331
|
-
Provision the current refresh token as `ASSINAFY_OAUTH_REFRESH_TOKEN`; `assinafy oauth refresh --resource https://api.assinafy.com.br --json` emits the rotated token response. Save to a private new file and atomically replace the previous file only on success. Never launch concurrent refresh commands. Use `ASSINAFY_OAUTH_REVOKE_TOKEN` for `assinafy oauth revoke --token-type-hint refresh_token --json`. For UserInfo, request `openid` during consent and run `assinafy oauth userinfo --json` with the access token.
|
|
339
|
+
Provision the current refresh token as `ASSINAFY_OAUTH_REFRESH_TOKEN`; `assinafy oauth refresh --resource https://api.assinafy.com.br --json` emits the rotated token response. Save to a private new file and atomically replace the previous file only on success. Never launch concurrent refresh commands. If the command reports that the response has no new refresh token, do not run it again with the same token; run `assinafy oauth connect`. Use `ASSINAFY_OAUTH_REVOKE_TOKEN` with the latest saved refresh token for `assinafy oauth revoke --token-type-hint refresh_token --json`. For UserInfo, request `openid` during consent and run `assinafy oauth userinfo --json` with the access token.
|
|
332
340
|
|
|
333
341
|
Request files, callback URLs, token output, and environment variables are sensitive. Protect them using the OS's user-only permissions, keep them out of logs and version control, and remove consumed requests. The CLI's temporary listener serves only a browser handoff; token storage and connection lifecycle remain the caller's responsibility.
|
|
334
342
|
|
|
@@ -337,6 +345,7 @@ Request files, callback URLs, token output, and environment variables are sensit
|
|
|
337
345
|
| Result | Application behavior |
|
|
338
346
|
| --- | --- |
|
|
339
347
|
| `400 invalid_grant` | Code expired/used or refresh no longer usable; reconnect rather than retrying the old grant. |
|
|
348
|
+
| `ValidationError`, `errors.field` `refresh_token` | Refresh returned no new refresh token; the submitted one may be retired. Do not reuse it; reconnect. |
|
|
340
349
|
| `401 invalid_client` | Check application type, client ID, client secret, and environment. |
|
|
341
350
|
| API `401` | Access token invalid/expired; perform one serialized refresh if the connection is recoverable. |
|
|
342
351
|
| `403` with `insufficient_scope` | Read `ApiError.wwwAuthenticate`; obtain consent for the missing scope. |
|
package/docs/oauth.md
CHANGED
|
@@ -41,10 +41,10 @@ Options:
|
|
|
41
41
|
ASSINAFY_OAUTH_CLIENT_ID)
|
|
42
42
|
--redirect-uri <uri> Exactly registered HTTPS relay URI (default:
|
|
43
43
|
"https://integrations.assinafy.com.br/assinafy-cli/oauth-callback")
|
|
44
|
-
--scope <scopes> Space-separated scopes;
|
|
45
|
-
|
|
46
|
-
documents:write templates:read templates:write
|
|
47
|
-
profile email offline_access")
|
|
44
|
+
--scope <scopes> Space-separated scopes; the default requests every
|
|
45
|
+
published scope (default: "account:read documents:read
|
|
46
|
+
documents:write templates:read templates:write
|
|
47
|
+
webhooks:write openid profile email offline_access")
|
|
48
48
|
--timeout <seconds> Wait for browser consent (1–600 seconds) (default:
|
|
49
49
|
"180")
|
|
50
50
|
--no-browser Print the authorization URL without opening the system
|
package/docs/sdk-reference.md
CHANGED
|
@@ -423,13 +423,13 @@ Login/social/reset bootstrap calls can use an unauthenticated client. The publis
|
|
|
423
423
|
| `discovery(issuer)` | `GET {issuer}/.well-known/oauth-authorization-server`; requires HTTPS and matching issuer | `IOAuthAuthorizationServer` |
|
|
424
424
|
| `authorize({ clientId, redirectUri, scopes })` | Discover resource/server and generate a fresh S256 verifier, state, and optional OIDC nonce | `IOAuthAuthorizationRequest` |
|
|
425
425
|
| `exchangeCode(callbackUrl, request, clientSecret?)` | Validate callback URI/state/issuer and submit the authorization code | `IOAuthTokenResponse` |
|
|
426
|
-
| `token(payload)` | [`POST /oauth/token`](./api-reference.md#exchange-a-code-or-
|
|
426
|
+
| `token(payload)` | [`POST /oauth/token`](./api-reference.md#exchange-a-code-refresh-token-or-subject-token-for-an-access-token), with code or refresh grant | `IOAuthTokenResponse` |
|
|
427
427
|
| `revoke(payload)` | [`POST /oauth/revoke`](./api-reference.md#revoke-a-token) | `void` |
|
|
428
428
|
| `userinfo()` | `GET /oauth/userinfo`, using the current OAuth bearer token with `openid` | `IOAuthUserInfo` |
|
|
429
429
|
|
|
430
430
|
All request types, full payload examples and response shapes are in the [OAuth guide](./oauth-guide.md). `IOAuthTokenPayload` is a discriminated union: code exchange requires `code`, `redirect_uri`, and `code_verifier`; refresh requires `refresh_token`; both require `client_id` and optionally accept `client_secret` and `resource`. `IOAuthRevokePayload` requires `token` and `client_id`, with optional `client_secret` and `token_type_hint`.
|
|
431
431
|
|
|
432
|
-
Metadata, discovery, token, and revoke calls remove owner headers. UserInfo uses the configured credential; construct the client with `token` for OAuth. OAuth bodies have no Assinafy envelope. The SDK returns credentials to the caller and does not persist, retry, or automatically refresh them. Store authorization requests in a single-use session; serialize refreshes across workers and atomically save the rotated result. Use an OIDC library to validate ID tokens before relying on identity claims.
|
|
432
|
+
Metadata, discovery, token, and revoke calls remove owner headers. UserInfo uses the configured credential; construct the client with `token` for OAuth. OAuth bodies have no Assinafy envelope. The SDK returns credentials to the caller and does not persist, retry, or automatically refresh them. A refresh response without a new `refresh_token`, or with the submitted one, throws `ValidationError` with `errors.field` set to `'refresh_token'`; do not reuse the submitted token, reconnect instead. Store authorization requests in a single-use session; serialize refreshes across workers and atomically save the rotated result. Use an OIDC library to validate ID tokens before relying on identity claims.
|
|
433
433
|
|
|
434
434
|
## Fields (`client.fields`)
|
|
435
435
|
|