@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.
@@ -1261,10 +1261,17 @@ async function authorize(meta, clientID, scopes, opts = {}) {
1261
1261
  codeRejecter(new Error(`authorization denied: ${errMsg}`));
1262
1262
  return;
1263
1263
  }
1264
- res.setHeader("Content-Type", "text/html; charset=utf-8");
1265
- res.end(
1266
- `<!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>`
1267
- );
1264
+ const successRedirect = resolveSuccessRedirect(opts.successRedirectURL);
1265
+ if (successRedirect) {
1266
+ res.statusCode = 302;
1267
+ res.setHeader("Location", successRedirect);
1268
+ res.end();
1269
+ } else {
1270
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
1271
+ res.end(
1272
+ `<!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>`
1273
+ );
1274
+ }
1268
1275
  codeResolver(code);
1269
1276
  });
1270
1277
  const authURL = new URL(meta.authorization_endpoint);
@@ -1326,6 +1333,16 @@ async function authorize(meta, clientID, scopes, opts = {}) {
1326
1333
  function htmlEscape(s) {
1327
1334
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1328
1335
  }
1336
+ function resolveSuccessRedirect(raw) {
1337
+ if (!raw) return null;
1338
+ try {
1339
+ const u = new URL(raw);
1340
+ if (u.protocol !== "http:" && u.protocol !== "https:") return null;
1341
+ return u.toString();
1342
+ } catch {
1343
+ return null;
1344
+ }
1345
+ }
1329
1346
  async function createWebAuthorizationRequest(meta, opts) {
1330
1347
  const verifier = await generateCodeVerifier();
1331
1348
  const challenge = await codeChallenge(verifier);