@acosmi/sdk-ts 2.7.0 → 2.8.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/dist/index.mjs CHANGED
@@ -1259,10 +1259,17 @@ async function authorize(meta, clientID, scopes, opts = {}) {
1259
1259
  codeRejecter(new Error(`authorization denied: ${errMsg}`));
1260
1260
  return;
1261
1261
  }
1262
- res.setHeader("Content-Type", "text/html; charset=utf-8");
1263
- res.end(
1264
- `<!DOCTYPE html><html><head><meta charset="utf-8"><title>\u6388\u6743\u6210\u529F</title></head><body style="font-family:system-ui,sans-serif;text-align:center;padding:60px 20px"><h2>\u6388\u6743\u6210\u529F</h2><p>\u5DF2\u5B8C\u6210\u8EAB\u4EFD\u8BA4\u8BC1, \u8BF7\u8FD4\u56DE\u5E94\u7528\u7EE7\u7EED\u4F7F\u7528\u3002</p><p style="color:#888;font-size:14px">\u6B64\u7A97\u53E3\u5C06\u5728 3 \u79D2\u540E\u81EA\u52A8\u5173\u95ED\u2026</p><script>setTimeout(function(){window.close()},3000)</script></body></html>`
1265
- );
1262
+ const successRedirect = resolveSuccessRedirect(opts.successRedirectURL);
1263
+ if (successRedirect) {
1264
+ res.statusCode = 302;
1265
+ res.setHeader("Location", successRedirect);
1266
+ res.end();
1267
+ } else {
1268
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
1269
+ res.end(
1270
+ `<!DOCTYPE html><html><head><meta charset="utf-8"><title>\u6388\u6743\u6210\u529F</title></head><body style="font-family:system-ui,sans-serif;text-align:center;padding:60px 20px"><h2>\u6388\u6743\u6210\u529F</h2><p>\u5DF2\u5B8C\u6210\u8EAB\u4EFD\u8BA4\u8BC1, \u8BF7\u8FD4\u56DE\u5E94\u7528\u7EE7\u7EED\u4F7F\u7528\u3002</p><p style="color:#888;font-size:14px">\u6B64\u7A97\u53E3\u5C06\u5728 3 \u79D2\u540E\u81EA\u52A8\u5173\u95ED\u2026</p><script>setTimeout(function(){window.close()},3000)</script></body></html>`
1271
+ );
1272
+ }
1266
1273
  codeResolver(code);
1267
1274
  });
1268
1275
  const authURL = new URL(meta.authorization_endpoint);
@@ -1324,6 +1331,16 @@ async function authorize(meta, clientID, scopes, opts = {}) {
1324
1331
  function htmlEscape(s) {
1325
1332
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1326
1333
  }
1334
+ function resolveSuccessRedirect(raw) {
1335
+ if (!raw) return null;
1336
+ try {
1337
+ const u = new URL(raw);
1338
+ if (u.protocol !== "http:" && u.protocol !== "https:") return null;
1339
+ return u.toString();
1340
+ } catch {
1341
+ return null;
1342
+ }
1343
+ }
1327
1344
  async function createWebAuthorizationRequest(meta, opts) {
1328
1345
  const verifier = await generateCodeVerifier();
1329
1346
  const challenge = await codeChallenge(verifier);