@assinafy/cli 2.1.1 → 2.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/README.en.md +2 -0
- package/README.md +2 -0
- package/dist/api.cjs +5 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.js +5 -1
- package/dist/api.js.map +1 -1
- package/dist/cli.cjs +84 -11
- package/dist/types/api/resources/oauth.d.ts.map +1 -1
- package/docs/oauth-guide.md +4 -0
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -22309,7 +22309,11 @@ var OAuthResource = class extends BaseResource {
|
|
|
22309
22309
|
throw new ValidationError("OAuth issuer mismatch");
|
|
22310
22310
|
}
|
|
22311
22311
|
if (callback.searchParams.has("error")) {
|
|
22312
|
-
|
|
22312
|
+
const error = callback.searchParams.get("error");
|
|
22313
|
+
const oauthError = error.length > 0 && error.length <= 64 && !/[^a-z_]/.test(error) ? error : "unknown_error";
|
|
22314
|
+
throw new ValidationError(`OAuth authorization was declined or failed: ${oauthError}`, {
|
|
22315
|
+
oauthError
|
|
22316
|
+
});
|
|
22313
22317
|
}
|
|
22314
22318
|
return this.token({
|
|
22315
22319
|
grant_type: "authorization_code",
|
|
@@ -25892,12 +25896,81 @@ var import_node_events2 = require("events");
|
|
|
25892
25896
|
var import_node_http = require("http");
|
|
25893
25897
|
var CLI_OAUTH_REDIRECT_URI = "https://integrations.assinafy.com.br/assinafy-cli/oauth-callback";
|
|
25894
25898
|
var clearHistory = "history.replaceState(null, '', '/');";
|
|
25895
|
-
var
|
|
25899
|
+
var brandOrigin = "https://integrations.assinafy.com.br";
|
|
25900
|
+
var callbackCopy = {
|
|
25901
|
+
received: {
|
|
25902
|
+
heading: "Volte ao terminal.",
|
|
25903
|
+
status: "A resposta de autoriza\xE7\xE3o foi recebida. Confira no terminal se a conex\xE3o foi conclu\xEDda."
|
|
25904
|
+
},
|
|
25905
|
+
denied: {
|
|
25906
|
+
heading: "Conex\xE3o n\xE3o autorizada.",
|
|
25907
|
+
status: "A autoriza\xE7\xE3o n\xE3o foi conclu\xEDda. Confira o erro no terminal e inicie uma nova conex\xE3o."
|
|
25908
|
+
},
|
|
25909
|
+
invalid: {
|
|
25910
|
+
heading: "Retorno inv\xE1lido.",
|
|
25911
|
+
status: "Continue na janela original de autoriza\xE7\xE3o. Se ela expirou, inicie uma nova conex\xE3o no terminal."
|
|
25912
|
+
}
|
|
25913
|
+
};
|
|
25914
|
+
function callbackPage(status) {
|
|
25915
|
+
const copy = callbackCopy[status];
|
|
25916
|
+
return `<!doctype html>
|
|
25917
|
+
<html lang="pt-BR">
|
|
25918
|
+
<head>
|
|
25919
|
+
<meta charset="utf-8">
|
|
25920
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
25921
|
+
<meta name="referrer" content="no-referrer">
|
|
25922
|
+
<meta name="robots" content="noindex, nofollow, noarchive">
|
|
25923
|
+
<title>${copy.heading} | Assinafy CLI</title>
|
|
25924
|
+
<script>${clearHistory}</script>
|
|
25925
|
+
<link rel="icon" href="${brandOrigin}/brand/assinafy-icon.png">
|
|
25926
|
+
<link rel="stylesheet" href="${brandOrigin}/brand/colors.css">
|
|
25927
|
+
<link rel="stylesheet" href="${brandOrigin}/brand/site.css">
|
|
25928
|
+
<link rel="stylesheet" href="${brandOrigin}/oauth-callback.css">
|
|
25929
|
+
</head>
|
|
25930
|
+
<body>
|
|
25931
|
+
<a class="skip-link" href="#conteudo">Pular para o conte\xFAdo</a>
|
|
25932
|
+
<header class="site-header wrap">
|
|
25933
|
+
<a class="brand" href="${brandOrigin}" aria-label="Assinafy Integra\xE7\xF5es, in\xEDcio">
|
|
25934
|
+
<img src="${brandOrigin}/brand/assinafy-logotype.svg" width="148" height="32" alt="Assinafy">
|
|
25935
|
+
<span class="brand-section">integra\xE7\xF5es</span>
|
|
25936
|
+
</a>
|
|
25937
|
+
</header>
|
|
25938
|
+
<main id="conteudo" class="hero wrap">
|
|
25939
|
+
<div>
|
|
25940
|
+
<p class="eyebrow"><img src="${brandOrigin}/assinafy-cli/cli-icon.svg" width="24" height="24" alt="">Conex\xE3o com a Assinafy CLI</p>
|
|
25941
|
+
<h1>${copy.heading}</h1>
|
|
25942
|
+
<p class="hero-description" role="status">${copy.status}</p>
|
|
25943
|
+
<a class="button button-primary" href="${brandOrigin}/assinafy-cli">Ajuda para conectar<svg width="19" height="19" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 12h16m-7-7 7 7-7 7"/></svg></a>
|
|
25944
|
+
</div>
|
|
25945
|
+
<figure class="connection-art">
|
|
25946
|
+
<div class="connection-map" role="img" aria-label="Retorno de autoriza\xE7\xE3o: Assinafy para Assinafy CLI.">
|
|
25947
|
+
<svg class="connection-lines" viewBox="0 0 480 240" preserveAspectRatio="none" fill="none" aria-hidden="true">
|
|
25948
|
+
<path class="connection-route" d="M120 106H240"/>
|
|
25949
|
+
<path class="connection-complete" d="M240 106H374m-64-5 5 5-5 5"/>
|
|
25950
|
+
</svg>
|
|
25951
|
+
<div class="connection-node connection-assinafy" aria-hidden="true">
|
|
25952
|
+
<span class="connection-tile"><img src="${brandOrigin}/brand/assinafy-icon.png" width="60" height="60" alt=""></span>
|
|
25953
|
+
<span class="connection-label">Assinafy</span>
|
|
25954
|
+
</div>
|
|
25955
|
+
<div class="connection-node connection-application" aria-hidden="true">
|
|
25956
|
+
<span class="connection-tile"><img src="${brandOrigin}/assinafy-cli/cli-icon.svg" width="36" height="36" alt=""></span>
|
|
25957
|
+
<span class="connection-label">Assinafy CLI</span>
|
|
25958
|
+
</div>
|
|
25959
|
+
</div>
|
|
25960
|
+
<figcaption class="connection-caption">Continue no terminal que iniciou a conex\xE3o.</figcaption>
|
|
25961
|
+
</figure>
|
|
25962
|
+
</main>
|
|
25963
|
+
<footer class="site-footer wrap"><span>Assinafy. Assinaturas que conectam.</span></footer>
|
|
25964
|
+
</body>
|
|
25965
|
+
</html>`;
|
|
25966
|
+
}
|
|
25896
25967
|
var callbackHeaders = {
|
|
25968
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
25897
25969
|
"Cache-Control": "no-store",
|
|
25898
25970
|
"Referrer-Policy": "no-referrer",
|
|
25899
25971
|
"X-Content-Type-Options": "nosniff",
|
|
25900
|
-
"
|
|
25972
|
+
"X-Robots-Tag": "noindex, nofollow, noarchive",
|
|
25973
|
+
"Content-Security-Policy": `default-src 'none'; script-src 'sha256-${(0, import_node_crypto4.createHash)("sha256").update(clearHistory).digest("base64")}'; style-src ${brandOrigin}; img-src ${brandOrigin}; font-src ${brandOrigin}; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`,
|
|
25901
25974
|
Connection: "close"
|
|
25902
25975
|
};
|
|
25903
25976
|
function openBrowser(url2) {
|
|
@@ -25959,11 +26032,8 @@ async function connectOAuth(oauth, options, onAuthorize, timeoutMs = 18e4) {
|
|
|
25959
26032
|
const state = Buffer.from(query.get("state") ?? "");
|
|
25960
26033
|
const valid = !consumed && incoming.method === "GET" && incoming.headers.host === host && raw.startsWith("/callback?") && raw.length <= 8192 && url2.origin === `http://${host}` && url2.pathname === "/callback" && !url2.hash && [...query.keys()].every((key) => query.getAll(key).length === 1) && state.length === expectedState.length && (0, import_node_crypto4.timingSafeEqual)(state, expectedState) && query.get("iss") === request.issuer && query.has("code") !== query.has("error") && Boolean((query.get("code") ?? query.get("error"))?.trim());
|
|
25961
26034
|
if (!valid) {
|
|
25962
|
-
response.writeHead(400,
|
|
25963
|
-
|
|
25964
|
-
"Content-Type": "text/plain; charset=utf-8"
|
|
25965
|
-
});
|
|
25966
|
-
response.end("Invalid authorization response. Continue in the original browser session.");
|
|
26035
|
+
response.writeHead(400, callbackHeaders);
|
|
26036
|
+
response.end(callbackPage("invalid"));
|
|
25967
26037
|
return;
|
|
25968
26038
|
}
|
|
25969
26039
|
consumed = true;
|
|
@@ -25971,8 +26041,11 @@ async function connectOAuth(oauth, options, onAuthorize, timeoutMs = 18e4) {
|
|
|
25971
26041
|
for (const key of ["code", "state", "iss", "error"]) {
|
|
25972
26042
|
if (query.has(key)) callback.searchParams.set(key, query.get(key));
|
|
25973
26043
|
}
|
|
25974
|
-
response.writeHead(200,
|
|
25975
|
-
response.end(
|
|
26044
|
+
response.writeHead(200, callbackHeaders);
|
|
26045
|
+
response.end(
|
|
26046
|
+
callbackPage(query.has("error") ? "denied" : "received"),
|
|
26047
|
+
() => resolve(callback.toString())
|
|
26048
|
+
);
|
|
25976
26049
|
});
|
|
25977
26050
|
void Promise.resolve().then(() => onAuthorize(request.authorization_url)).catch(reject);
|
|
25978
26051
|
});
|
|
@@ -27038,7 +27111,7 @@ function handleStreamError(err, fallback, exit = process.exit) {
|
|
|
27038
27111
|
// package.json
|
|
27039
27112
|
var package_default = {
|
|
27040
27113
|
name: "@assinafy/cli",
|
|
27041
|
-
version: "2.1.
|
|
27114
|
+
version: "2.1.2",
|
|
27042
27115
|
description: "The official command-line interface for the Assinafy digital-signature API",
|
|
27043
27116
|
license: "MIT",
|
|
27044
27117
|
type: "module",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/oauth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,2FAA2F;AAC3F,qBAAa,aAAc,SAAQ,YAAY;IAC9C,oFAAoF;IAC9E,QAAQ,IAAI,OAAO,CAAC,uBAAuB,CAAC,CASjD;IAED,kFAAkF;IAC5E,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAgBlE;IAED,yFAAyF;IACnF,SAAS,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CA6CxF;IAED,oFAAoF;IAC9E,YAAY,CACjB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,0BAA0B,EACnC,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,mBAAmB,CAAC,
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/oauth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,0BAA0B,EAC1B,0BAA0B,EAC1B,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,2FAA2F;AAC3F,qBAAa,aAAc,SAAQ,YAAY;IAC9C,oFAAoF;IAC9E,QAAQ,IAAI,OAAO,CAAC,uBAAuB,CAAC,CASjD;IAED,kFAAkF;IAC5E,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAgBlE;IAED,yFAAyF;IACnF,SAAS,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CA6CxF;IAED,oFAAoF;IAC9E,YAAY,CACjB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,0BAA0B,EACnC,YAAY,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,mBAAmB,CAAC,CA8C9B;IAED,wFAAwF;IAClF,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuBrE;IAED,2FAA2F;IACrF,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAaxD;IAED,uFAAuF;IACjF,QAAQ,IAAI,OAAO,CAAC,cAAc,CAAC,CAExC;CACD"}
|
package/docs/oauth-guide.md
CHANGED
|
@@ -124,6 +124,8 @@ const tokens = await oauthClient.oauth.exchangeCode(
|
|
|
124
124
|
|
|
125
125
|
`exchangeCode(callbackUrl, request, clientSecret?)` checks the callback origin/path and registered query parameters, rejects duplicate protocol parameters, compares `state` in constant time, and requires the exact stored issuer. It rejects denied authorization before calling the token endpoint. Authorization codes expire after 60 seconds and can be used once. Exchange immediately and never retry a code blindly after a timeout.
|
|
126
126
|
|
|
127
|
+
An authorization error raises `ValidationError` with a bounded OAuth error code in `errors.oauthError` and the message, without retaining the callback URL. Unrecognized formats become `unknown_error`. For `invalid_scope`, check that the application registration permits every requested scope, including `offline_access`; do not treat the browser return as successful authorization.
|
|
128
|
+
|
|
127
129
|
For applications that already perform callback validation, `token(payload)` accepts the same complete code grant directly:
|
|
128
130
|
|
|
129
131
|
```json
|
|
@@ -290,6 +292,8 @@ The callback protocol is:
|
|
|
290
292
|
5. The CLI accepts only GET on `/callback` with the exact loopback Host, the original state, and the discovered issuer. Malformed or unrelated requests do not consume the pending connection. A valid authorization response is accepted once; the browser receives a page clearing its query and directing the user to the terminal.
|
|
291
293
|
6. Close the listener and remove its timeout/signal handlers. Reconstruct the response against the saved HTTPS redirect URI and call `oauth.exchangeCode`; the token request still uses that exact HTTPS URI. Tokens and the PKCE verifier are never sent to the callback site.
|
|
292
294
|
|
|
295
|
+
The local return page uses the logo, colors, Mona Sans fonts, and responsive layout hosted at `https://integrations.assinafy.com.br`. It distinguishes a received response, authorization failure, and invalid return. A received response does not confirm token exchange; check the CLI exit status and output. Browser history is cleared before loading assets, every response sends `Referrer-Policy: no-referrer`, and CSP permits only the fixed history script plus that origin's styles, images, and fonts. No callback parameters are included in the HTML or asset URLs. Public font responses must allow cross-origin loading from the temporary loopback origin.
|
|
296
|
+
|
|
293
297
|
The shared callback page accepts the production and staging issuers configured by the integration site. A custom issuer needs a compatible relay allowlist as well as `--base-url` and `--redirect-uri`. Do not add access logging, analytics, third-party scripts, or caching to callback routes. Deploy the site and register the application before using the default URL; installing the CLI does not deploy that site.
|
|
294
298
|
|
|
295
299
|
### Manual authorization and exchange
|