@voxgig/sdkgen 4.48.0 → 4.49.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.
Files changed (174) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/dist/utility.js +9 -1
  4. package/dist/utility.js.map +1 -1
  5. package/package.json +1 -1
  6. package/project/.sdk/model/feature/secrets.aontu +3 -0
  7. package/project/.sdk/src/cmp/c/Config_c.ts +6 -1
  8. package/project/.sdk/src/cmp/c/fragment/Entity.fragment.c +0 -10
  9. package/project/.sdk/src/cmp/clojure/fragment/Entity.fragment.clj +0 -9
  10. package/project/.sdk/src/cmp/csharp/fragment/EntityBase.fragment.cs +0 -11
  11. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +0 -7
  12. package/project/.sdk/src/cmp/java/fragment/EntityBase.fragment.java +0 -10
  13. package/project/.sdk/src/cmp/js/fragment/EntityBase.fragment.js +2 -11
  14. package/project/.sdk/src/cmp/kotlin/fragment/EntityBase.fragment.kt +0 -10
  15. package/project/.sdk/src/cmp/lua/fragment/Entity.fragment.lua +0 -11
  16. package/project/.sdk/src/cmp/ocaml/Entity_ocaml.ts +2 -10
  17. package/project/.sdk/src/cmp/perl/fragment/Entity.fragment.pm +0 -13
  18. package/project/.sdk/src/cmp/php/fragment/Entity.fragment.php +0 -10
  19. package/project/.sdk/src/cmp/py/fragment/Entity.fragment.py +0 -10
  20. package/project/.sdk/src/cmp/rb/fragment/Entity.fragment.rb +0 -10
  21. package/project/.sdk/src/cmp/rust/fragment/Entity.fragment.rs +0 -12
  22. package/project/.sdk/src/cmp/scala/fragment/EntityBase.fragment.scala +0 -10
  23. package/project/.sdk/src/cmp/swift/fragment/EntityBase.fragment.swift +0 -9
  24. package/project/.sdk/src/cmp/ts/fragment/EntityBase.fragment.ts +0 -7
  25. package/project/.sdk/src/cmp/zig/fragment/Entity.fragment.zig +1 -14
  26. package/project/.sdk/tm/c/feature/cache.c +16 -1
  27. package/project/.sdk/tm/c/feature/secrets.c +149 -18
  28. package/project/.sdk/tm/c/tests/feature/secrets/secrets_test.c +319 -70
  29. package/project/.sdk/tm/c/tests/feature_test.c +31 -0
  30. package/project/.sdk/tm/c/utility/make_spec.c +1 -1
  31. package/project/.sdk/tm/c/utility/prepare_body.c +64 -1
  32. package/project/.sdk/tm/c/utility/prepare_query.c +11 -6
  33. package/project/.sdk/tm/clojure/feature/secrets/sdk/feature/secrets.clj +74 -29
  34. package/project/.sdk/tm/clojure/src/sdk/core.clj +48 -10
  35. package/project/.sdk/tm/clojure/src/sdk/features.clj +16 -2
  36. package/project/.sdk/tm/clojure/test/sdk/test/feature/secrets.clj +191 -48
  37. package/project/.sdk/tm/clojure/test/sdk/test/feature.clj +16 -0
  38. package/project/.sdk/tm/cpp/core/types.hpp +1 -11
  39. package/project/.sdk/tm/cpp/feature/cache.hpp +14 -1
  40. package/project/.sdk/tm/cpp/feature/secrets.hpp +133 -18
  41. package/project/.sdk/tm/cpp/test/feature/secrets/secrets_test.cpp +175 -8
  42. package/project/.sdk/tm/cpp/test/feature_test.cpp +27 -0
  43. package/project/.sdk/tm/cpp/utility/pipeline.hpp +52 -4
  44. package/project/.sdk/tm/csharp/core/Control.cs +0 -5
  45. package/project/.sdk/tm/csharp/core/Point.cs +6 -0
  46. package/project/.sdk/tm/csharp/feature/CacheFeature.cs +16 -0
  47. package/project/.sdk/tm/csharp/feature/SecretsFeature.cs +77 -38
  48. package/project/.sdk/tm/csharp/test/FeatureTest.cs +29 -0
  49. package/project/.sdk/tm/csharp/test/feature/secrets/SecretsFeatureTest.cs +315 -68
  50. package/project/.sdk/tm/csharp/utility/MakeSpec.cs +2 -2
  51. package/project/.sdk/tm/csharp/utility/PrepareBody.cs +42 -0
  52. package/project/.sdk/tm/csharp/utility/PrepareQuery.cs +13 -2
  53. package/project/.sdk/tm/elixir/lib/projectname/entity_base.ex +0 -13
  54. package/project/.sdk/tm/elixir/lib/projectname/feature/cache.ex +32 -10
  55. package/project/.sdk/tm/elixir/lib/projectname/feature/secrets.ex +78 -22
  56. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +62 -6
  57. package/project/.sdk/tm/elixir/test/feature/secrets/secrets_test.exs +178 -19
  58. package/project/.sdk/tm/elixir/test/feature_test.exs +20 -0
  59. package/project/.sdk/tm/go/core/target.go +8 -0
  60. package/project/.sdk/tm/go/feature/cache_feature.go +14 -1
  61. package/project/.sdk/tm/go/feature/secrets_feature.go +110 -15
  62. package/project/.sdk/tm/go/test/feature/secrets/secrets_feature_test.go +373 -87
  63. package/project/.sdk/tm/go/test/feature_test.go +32 -0
  64. package/project/.sdk/tm/go/utility/media.go +2 -2
  65. package/project/.sdk/tm/go/utility/prepare_body.go +37 -1
  66. package/project/.sdk/tm/go/utility/prepare_query.go +10 -1
  67. package/project/.sdk/tm/java/core/Control.java +0 -5
  68. package/project/.sdk/tm/java/core/Point.java +7 -0
  69. package/project/.sdk/tm/java/feature/CacheFeature.java +12 -0
  70. package/project/.sdk/tm/java/feature/SecretsFeature.java +104 -34
  71. package/project/.sdk/tm/java/test/FeatureTest.java +25 -0
  72. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +39 -0
  73. package/project/.sdk/tm/java/test/feature/secrets/SecretsFeatureTest.java +267 -53
  74. package/project/.sdk/tm/java/utility/Fetcher.java +18 -2
  75. package/project/.sdk/tm/java/utility/MakeSpec.java +1 -1
  76. package/project/.sdk/tm/java/utility/Media.java +2 -2
  77. package/project/.sdk/tm/java/utility/PrepareBody.java +50 -0
  78. package/project/.sdk/tm/java/utility/PrepareQuery.java +11 -1
  79. package/project/.sdk/tm/js/src/Point.js +2 -0
  80. package/project/.sdk/tm/js/src/feature/cache/CacheFeature.js +13 -0
  81. package/project/.sdk/tm/js/src/feature/secrets/SecretsFeature.js +79 -29
  82. package/project/.sdk/tm/js/src/utility/MakeSpecUtility.js +1 -1
  83. package/project/.sdk/tm/js/src/utility/PrepareBodyUtility.js +29 -0
  84. package/project/.sdk/tm/js/src/utility/PrepareQueryUtility.js +5 -3
  85. package/project/.sdk/tm/js/test/feature/secrets/Secrets.test.js +282 -93
  86. package/project/.sdk/tm/js/test/feature.test.js +17 -0
  87. package/project/.sdk/tm/kotlin/core/Control.kt +0 -5
  88. package/project/.sdk/tm/kotlin/core/Point.kt +7 -0
  89. package/project/.sdk/tm/kotlin/feature/CacheFeature.kt +12 -0
  90. package/project/.sdk/tm/kotlin/feature/SecretsFeature.kt +84 -24
  91. package/project/.sdk/tm/kotlin/test/FeatureTest.kt +24 -0
  92. package/project/.sdk/tm/kotlin/test/PrimaryUtilityTest.kt +35 -0
  93. package/project/.sdk/tm/kotlin/test/feature/secrets/SecretsTest.kt +236 -54
  94. package/project/.sdk/tm/kotlin/utility/Fetcher.kt +13 -1
  95. package/project/.sdk/tm/kotlin/utility/MakeSpecUrl.kt +1 -1
  96. package/project/.sdk/tm/kotlin/utility/Prepare.kt +40 -10
  97. package/project/.sdk/tm/lua/feature/cache_feature.lua +20 -0
  98. package/project/.sdk/tm/lua/feature/secrets_feature.lua +92 -15
  99. package/project/.sdk/tm/lua/test/feature/secrets/secrets_feature_test.lua +208 -43
  100. package/project/.sdk/tm/lua/test/feature_test.lua +18 -0
  101. package/project/.sdk/tm/lua/utility/clean.lua +1 -0
  102. package/project/.sdk/tm/lua/utility/make_spec.lua +1 -1
  103. package/project/.sdk/tm/lua/utility/prepare_body.lua +40 -0
  104. package/project/.sdk/tm/lua/utility/prepare_query.lua +11 -1
  105. package/project/.sdk/tm/ocaml/feature/secrets_feature.ml +100 -14
  106. package/project/.sdk/tm/ocaml/sdk_features.ml +7 -1
  107. package/project/.sdk/tm/ocaml/sdk_runtime.ml +40 -5
  108. package/project/.sdk/tm/ocaml/test/feature/secrets/t_secrets.ml +143 -7
  109. package/project/.sdk/tm/ocaml/test/t_feature.ml +15 -0
  110. package/project/.sdk/tm/perl/feature/cache_feature.pm +13 -0
  111. package/project/.sdk/tm/perl/feature/secrets_feature.pm +87 -32
  112. package/project/.sdk/tm/perl/t/feature/secrets/secrets.t +177 -24
  113. package/project/.sdk/tm/perl/t/feature.t +24 -0
  114. package/project/.sdk/tm/perl/utility/make_spec.pm +1 -1
  115. package/project/.sdk/tm/perl/utility/prepare_body.pm +38 -4
  116. package/project/.sdk/tm/perl/utility/prepare_query.pm +7 -1
  117. package/project/.sdk/tm/php/feature/CacheFeature.php +13 -0
  118. package/project/.sdk/tm/php/feature/SecretsFeature.php +79 -23
  119. package/project/.sdk/tm/php/test/FeatureTest.php +23 -0
  120. package/project/.sdk/tm/php/test/feature/secrets/SecretsTest.php +258 -48
  121. package/project/.sdk/tm/php/utility/MakeSpec.php +2 -2
  122. package/project/.sdk/tm/php/utility/PrepareBody.php +31 -0
  123. package/project/.sdk/tm/php/utility/PrepareQuery.php +9 -2
  124. package/project/.sdk/tm/py/pkg/feature/cache_feature.py +7 -1
  125. package/project/.sdk/tm/py/pkg/feature/secrets_feature.py +90 -29
  126. package/project/.sdk/tm/py/pkg/utility/make_spec.py +1 -1
  127. package/project/.sdk/tm/py/pkg/utility/prepare_body.py +26 -0
  128. package/project/.sdk/tm/py/pkg/utility/prepare_query.py +7 -2
  129. package/project/.sdk/tm/py/test/feature/secrets/test_secrets.py +313 -80
  130. package/project/.sdk/tm/py/test/test_feature.py +18 -0
  131. package/project/.sdk/tm/rb/feature/cache_feature.rb +12 -0
  132. package/project/.sdk/tm/rb/feature/secrets_feature.rb +68 -21
  133. package/project/.sdk/tm/rb/test/feature/secrets/secrets_feature_test.rb +214 -43
  134. package/project/.sdk/tm/rb/test/feature_test.rb +20 -0
  135. package/project/.sdk/tm/rb/utility/make_spec.rb +1 -1
  136. package/project/.sdk/tm/rb/utility/prepare_body.rb +31 -3
  137. package/project/.sdk/tm/rb/utility/prepare_query.rb +7 -1
  138. package/project/.sdk/tm/rust/feature/cache.rs +15 -1
  139. package/project/.sdk/tm/rust/feature/secrets.rs +103 -23
  140. package/project/.sdk/tm/rust/tests/feature/secrets/main.rs +357 -67
  141. package/project/.sdk/tm/rust/tests/feature_test.rs +41 -0
  142. package/project/.sdk/tm/rust/utility/prepare_body.rs +51 -0
  143. package/project/.sdk/tm/rust/utility/prepare_query.rs +12 -4
  144. package/project/.sdk/tm/scala/core/Control.scala +0 -5
  145. package/project/.sdk/tm/scala/core/Point.scala +3 -0
  146. package/project/.sdk/tm/scala/feature/CacheFeature.scala +12 -0
  147. package/project/.sdk/tm/scala/feature/SecretsFeature.scala +88 -22
  148. package/project/.sdk/tm/scala/sdktest/SdkTestMain.scala +61 -1
  149. package/project/.sdk/tm/scala/sdktest/feature/secrets/SecretsTestMain.scala +230 -73
  150. package/project/.sdk/tm/scala/utility/Fetcher.scala +13 -1
  151. package/project/.sdk/tm/scala/utility/MakeSpec.scala +1 -1
  152. package/project/.sdk/tm/scala/utility/Prepare.scala +53 -12
  153. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Control.swift +0 -5
  154. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/core/Point.swift +3 -0
  155. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/CacheFeature.swift +11 -0
  156. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/feature/SecretsFeature.swift +76 -16
  157. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Make.swift +1 -1
  158. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +36 -1
  159. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/FeatureTest.swift +21 -0
  160. package/project/.sdk/tm/swift/Tests/ProjectNameSDKTests/feature/secrets/SecretsFeatureTest.swift +257 -73
  161. package/project/.sdk/tm/ts/src/Point.ts +3 -0
  162. package/project/.sdk/tm/ts/src/feature/cache/CacheFeature.ts +13 -0
  163. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +77 -17
  164. package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +29 -0
  165. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +5 -3
  166. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +282 -87
  167. package/project/.sdk/tm/ts/test/feature.test.ts +17 -0
  168. package/project/.sdk/tm/zig/core/utility.zig +47 -4
  169. package/project/.sdk/tm/zig/feature/cache.zig +15 -1
  170. package/project/.sdk/tm/zig/feature/secrets.zig +109 -32
  171. package/project/.sdk/tm/zig/test/feature/secrets/secrets_test.zig +232 -9
  172. package/project/.sdk/tm/zig/test/feature_test.zig +33 -0
  173. package/project/sdkgen-package.json +1 -1
  174. package/src/utility.ts +12 -1
@@ -100,6 +100,7 @@ typedef struct {
100
100
  int64_t* statuses;
101
101
  size_t nstatuses;
102
102
  int64_t retries;
103
+ bool sameorigin;
103
104
  } SecretsExchange;
104
105
 
105
106
  typedef struct {
@@ -120,6 +121,11 @@ typedef struct {
120
121
  // never written.
121
122
  voxgig_value* liveopts;
122
123
 
124
+ // What prepare_auth was generated from: the config declares auth only
125
+ // where it places a credential, and Basic only where it composes one.
126
+ bool declared;
127
+ bool basic;
128
+
123
129
  const char* secretname;
124
130
  bool cache;
125
131
 
@@ -277,6 +283,13 @@ static bool spec_of_map(sek_pool* pool, voxgig_value* m, sek_spec* spec, const c
277
283
 
278
284
  // ---- credential injection ---------------------------------------------------
279
285
 
286
+ // prepare_auth's decision: auth the config declares, not suppressed by
287
+ // `auth: null`.
288
+ static bool secrets_authon(SecretsFeature* f) {
289
+ voxgig_value* auth = getp(f->liveopts, "auth");
290
+ return f->declared && !v_is_noval(auth) && !v_is_null(auth);
291
+ }
292
+
280
293
  // Write the resolved credential into THIS request's credential header,
281
294
  // the way prepare_auth builds it (same options auth name and prefix, same
282
295
  // suppression rule), so the two cannot drift.
@@ -303,7 +316,7 @@ static void secrets_reauth(SecretsFeature* f, voxgig_value* fetchdef) {
303
316
  }
304
317
 
305
318
  voxgig_value* auth = getp(f->liveopts, "auth");
306
- if (v_is_noval(auth) || v_is_null(auth)) {
319
+ if (!secrets_authon(f)) {
307
320
  voxgig_value* k = voxgig_new_string(name);
308
321
  voxgig_delprop(headers, k);
309
322
  voxgig_release(k);
@@ -316,16 +329,42 @@ static void secrets_reauth(SecretsFeature* f, voxgig_value* fetchdef) {
316
329
  return;
317
330
  }
318
331
 
332
+ // Under Basic the token is the key half, as apikey is: prepare_auth's pair.
333
+ bool want_basic = false;
334
+ if (f->basic) get_bool(auth, "basic", &want_basic);
335
+ char* value = NULL;
336
+ if (want_basic) {
337
+ const char* secret = get_str(f->liveopts, "secret");
338
+ if (NULL == secret) secret = "";
339
+ size_t n = strlen(f->cred) + 1 + strlen(secret) + 1;
340
+ char* pair = (char*)malloc(n);
341
+ if (NULL == pair) {
342
+ free(name);
343
+ return;
344
+ }
345
+ snprintf(pair, n, "%s:%s", f->cred, secret);
346
+ value = clean_base64(pair);
347
+ free(pair);
348
+ if (NULL != value) clean_add_opts(f->liveopts, value);
349
+ } else {
350
+ value = strdup(f->cred);
351
+ }
352
+ if (NULL == value) {
353
+ free(name);
354
+ return;
355
+ }
356
+
319
357
  const char* prefix = get_str(auth, "prefix");
320
358
  if (NULL == prefix || '\0' == prefix[0]) {
321
- setp(headers, name, v_str(f->cred));
359
+ setp(headers, name, v_str(value));
322
360
  } else {
323
- size_t n = strlen(prefix) + 1 + strlen(f->cred) + 1;
361
+ size_t n = strlen(prefix) + 1 + strlen(value) + 1;
324
362
  char* buf = (char*)malloc(n);
325
- snprintf(buf, n, "%s %s", prefix, f->cred);
363
+ snprintf(buf, n, "%s %s", prefix, value);
326
364
  setp(headers, name, v_str(buf));
327
365
  free(buf);
328
366
  }
367
+ free(value);
329
368
  free(name);
330
369
  }
331
370
 
@@ -341,6 +380,90 @@ static void secrets_setcred(SecretsFeature* f, const char* value) {
341
380
 
342
381
  // ---- the exchange -----------------------------------------------------------
343
382
 
383
+ #define SECRETS_REDIRECT_MAX 5
384
+
385
+ // "scheme://host:port" of an absolute http(s) URL, the port defaulted; and,
386
+ // in *rest, where its authority ends. 0 when it is not one.
387
+ static int secrets_origin(const char* url, char* out, size_t size, const char** rest) {
388
+ const char* sep = strstr(url, "://");
389
+ size_t slen = NULL == sep ? 0 : (size_t)(sep - url);
390
+ char scheme[6] = "";
391
+ if (5 < slen) return 0;
392
+ for (size_t i = 0; i < slen; i++) {
393
+ scheme[i] = (char)('A' <= url[i] && url[i] <= 'Z' ? url[i] - 'A' + 'a' : url[i]);
394
+ }
395
+ int https = 0 == strcmp(scheme, "https");
396
+ if (!https && 0 != strcmp(scheme, "http")) return 0;
397
+ const char* auth = sep + 3;
398
+ const char* end = auth + strcspn(auth, "/?#");
399
+ for (const char* at = auth; at < end; at++) if ('@' == *at) auth = at + 1;
400
+ const char* colon = '[' == *auth ? memchr(auth, ']', (size_t)(end - auth)) : auth;
401
+ if (NULL == colon) return 0;
402
+ colon = memchr(colon, ':', (size_t)(end - colon));
403
+ const char* hostend = NULL == colon ? end : colon;
404
+ if (hostend == auth) return 0;
405
+ long port = https ? 443 : 80;
406
+ if (NULL != colon && colon + 1 < end) {
407
+ char* stop = NULL;
408
+ port = strtol(colon + 1, &stop, 10);
409
+ if (stop != end || port < 0 || 65535 < port) return 0;
410
+ }
411
+ int n = snprintf(out, size, "%s://%.*s:%ld", https ? "https" : "http",
412
+ (int)(hostend - auth), auth, port);
413
+ if (n < 0 || (size_t)n >= size) return 0;
414
+ for (char* c = out; '\0' != *c; c++) if ('A' <= *c && *c <= 'Z') *c = (char)(*c - 'A' + 'a');
415
+ if (NULL != rest) *rest = end;
416
+ return 1;
417
+ }
418
+
419
+ // Where a 307 or 308 points, when that is on the exchange's own origin. Any
420
+ // other redirect would drop the body or leave the origin.
421
+ static char* secrets_moved(sek_pool* pool, const char* url, const char* at, voxgig_value* res) {
422
+ int64_t status = to_int(getp(res, "status"));
423
+ const char* location = get_str(getp(res, "headers"), "location");
424
+ char own[320];
425
+ char from[320];
426
+ char to[320];
427
+ const char* rest = NULL;
428
+ if ((307 != status && 308 != status) || NULL == location || '\0' == location[0] ||
429
+ !secrets_origin(url, own, sizeof(own), NULL) ||
430
+ !secrets_origin(at, from, sizeof(from), &rest)) {
431
+ return NULL;
432
+ }
433
+ char* next;
434
+ if (NULL != strstr(location, "://")) {
435
+ next = sek_strdup(pool, location);
436
+ } else if ('/' == location[0] && '/' == location[1]) {
437
+ next = sek_fmt(pool, "%.*s:%s", (int)(strstr(at, "://") - at), at, location);
438
+ } else if ('/' == location[0]) {
439
+ next = sek_fmt(pool, "%.*s%s", (int)(rest - at), at, location);
440
+ } else if ('?' == location[0]) {
441
+ next = sek_fmt(pool, "%.*s%s", (int)strcspn(at, "?#"), at, location);
442
+ } else {
443
+ size_t dir = (size_t)(rest - at);
444
+ for (size_t i = dir; '\0' != at[i] && '?' != at[i] && '#' != at[i]; i++) {
445
+ if ('/' == at[i]) dir = i + 1;
446
+ }
447
+ next = sek_fmt(pool, "%.*s%s%s", (int)dir, at, dir == (size_t)(rest - at) ? "/" : "", location);
448
+ }
449
+ return secrets_origin(next, to, sizeof(to), NULL) && 0 == strcmp(own, to) ? next : NULL;
450
+ }
451
+
452
+ // One request of the exchange: options.system.fetch when supplied, else the
453
+ // transport of last resort. A pool-owned message on failure.
454
+ static const char* secrets_send(SecretsFeature* f, Context* ctx, voxgig_value* sys_fetch,
455
+ const char* url, voxgig_value* fetchdef, voxgig_value** res) {
456
+ if (voxgig_is_func(sys_fetch)) {
457
+ *res = call_vfn(sys_fetch, clist(2, v_str(url), v_share(fetchdef)));
458
+ const char* emsg = get_str(*res, "__err__");
459
+ return NULL == emsg ? NULL : sek_strdup(f->pool, emsg);
460
+ }
461
+ PNError* ferr = NULL;
462
+ *res = secrets_rawfetch(ctx, url, fetchdef, &ferr);
463
+ return NULL == ferr ? NULL :
464
+ sek_strdup(f->pool, ferr->msg ? ferr->msg : "secrets: transport failed");
465
+ }
466
+
344
467
  // Buy an access token with the refresh token. Answers sekreto-style: a
345
468
  // pool-owned message, or NULL for success with the token in f->cred.
346
469
  static const char* secrets_buy(SecretsFeature* f, Context* ctx) {
@@ -402,15 +525,18 @@ static const char* secrets_buy(SecretsFeature* f, Context* ctx) {
402
525
  // supplied one (the seam every live c request already uses), else the
403
526
  // bundled transport of last resort from the generated kinds.c.
404
527
  voxgig_value* sys_fetch = getpath2(options, "system", "fetch");
405
- voxgig_value* res;
406
- if (voxgig_is_func(sys_fetch)) {
407
- res = call_vfn(sys_fetch, clist(2, v_str(url), v_share(fetchdef)));
408
- const char* emsg = get_str(res, "__err__");
409
- if (NULL != emsg) return sek_strdup(f->pool, emsg);
410
- } else {
411
- PNError* ferr = NULL;
412
- res = secrets_rawfetch(ctx, url, fetchdef, &ferr);
413
- if (NULL != ferr) return sek_strdup(f->pool, ferr->msg ? ferr->msg : "secrets: transport failed");
528
+ voxgig_value* res = NULL;
529
+ const char* sent = secrets_send(f, ctx, sys_fetch, url, fetchdef, &res);
530
+ if (NULL != sent) return sent;
531
+
532
+ // By option alone, and only while the exchange stays on its own origin.
533
+ const char* at = url;
534
+ for (int hops = 0; x->sameorigin && hops < SECRETS_REDIRECT_MAX; hops++) {
535
+ char* next = secrets_moved(f->pool, url, at, res);
536
+ if (NULL == next) break;
537
+ at = next;
538
+ sent = secrets_send(f, ctx, sys_fetch, at, fetchdef, &res);
539
+ if (NULL != sent) return sent;
414
540
  }
415
541
 
416
542
  int64_t status = to_int(getp(res, "status"));
@@ -458,7 +584,7 @@ static bool secrets_spent(SecretsFeature* f, voxgig_value* res) {
458
584
  static const char* secrets_resolve(SecretsFeature* f, Context* ctx) {
459
585
  if (NULL != f->initerr) return f->initerr;
460
586
  if (f->cache && f->resolved) return NULL;
461
- if (NULL == f->sek) return NULL;
587
+ if (NULL == f->sek || !secrets_authon(f)) return NULL;
462
588
 
463
589
  char* found = NULL;
464
590
  sek_err err = sek_try(f->sek, f->secretname, &found);
@@ -542,10 +668,9 @@ static voxgig_value* secrets_fetch(Fetcher* self, Context* ctx, const char* url,
542
668
  return st->inner->fn(st->inner, ctx, url, fetchdef, err);
543
669
  }
544
670
 
545
- // `auth: null` is a deliberately unauthenticated request: a refusal of it
546
- // is not an expired token and cannot be fixed by buying one.
547
- voxgig_value* auth = getp(f->liveopts, "auth");
548
- if (v_is_noval(auth) || v_is_null(auth)) {
671
+ // A refusal of an unauthenticated request is not an expired token, and
672
+ // retrying would transmit the credential that auth off withholds.
673
+ if (!secrets_authon(f)) {
549
674
  return st->inner->fn(st->inner, ctx, url, fetchdef, err);
550
675
  }
551
676
 
@@ -609,6 +734,11 @@ static void secrets_init(Feature* fb, Context* ctx, voxgig_value* options) {
609
734
  f->client = ctx->client;
610
735
  f->liveopts = ctx->options;
611
736
 
737
+ voxgig_value* declared = NULL == ctx->config ? NULL : getpath2(ctx->config, "options", "auth");
738
+ f->declared = voxgig_is_map(declared);
739
+ f->basic = false;
740
+ if (f->declared) get_bool(declared, "basic", &f->basic);
741
+
612
742
  // WRAP FIRST. The fail-closed gate needs the seam whatever happens
613
743
  // below - a chain that fails to build must still refuse to send - so the
614
744
  // wrapper is installed before anything here can fail, and the exchange
@@ -638,6 +768,7 @@ static void secrets_init(Feature* fb, Context* ctx, voxgig_value* options) {
638
768
  x->request = fopt_str(xopts, "request", "refresh_token");
639
769
  x->response = fopt_str(xopts, "response", "access_token");
640
770
  x->retries = fopt_int(xopts, "retries", 1);
771
+ x->sameorigin = 0 == strcmp("same-origin", fopt_str(xopts, "redirect", "refuse"));
641
772
  voxgig_value* sl = fopt_list(xopts, "statuses");
642
773
  if (voxgig_is_list(sl) && 0 < voxgig_as_list(sl)->len) {
643
774
  voxgig_list* l = voxgig_as_list(sl);