@atproto/oauth-types 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/atproto-loopback-client-metadata.d.ts.map +1 -1
  3. package/dist/atproto-loopback-client-metadata.js +4 -16
  4. package/dist/atproto-loopback-client-metadata.js.map +1 -1
  5. package/dist/constants.d.ts +0 -6
  6. package/dist/constants.d.ts.map +1 -1
  7. package/dist/constants.js +1 -17
  8. package/dist/constants.js.map +1 -1
  9. package/dist/index.d.ts +18 -5
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +18 -5
  12. package/dist/index.js.map +1 -1
  13. package/dist/oauth-access-token.d.ts +4 -0
  14. package/dist/oauth-access-token.d.ts.map +1 -0
  15. package/dist/oauth-access-token.js +6 -0
  16. package/dist/oauth-access-token.js.map +1 -0
  17. package/dist/oauth-authorization-code-grant-token-request.d.ts +20 -0
  18. package/dist/oauth-authorization-code-grant-token-request.d.ts.map +1 -0
  19. package/dist/oauth-authorization-code-grant-token-request.js +17 -0
  20. package/dist/oauth-authorization-code-grant-token-request.js.map +1 -0
  21. package/dist/oauth-authorization-request-jar.d.ts +16 -0
  22. package/dist/oauth-authorization-request-jar.d.ts.map +1 -0
  23. package/dist/oauth-authorization-request-jar.js +15 -0
  24. package/dist/oauth-authorization-request-jar.js.map +1 -0
  25. package/dist/oauth-authorization-request-par.d.ts +122 -0
  26. package/dist/oauth-authorization-request-par.d.ts.map +1 -0
  27. package/dist/oauth-authorization-request-par.js +11 -0
  28. package/dist/oauth-authorization-request-par.js.map +1 -0
  29. package/dist/{oauth-authentication-request-parameters.d.ts → oauth-authorization-request-parameters.d.ts} +18 -18
  30. package/dist/oauth-authorization-request-parameters.d.ts.map +1 -0
  31. package/dist/{oauth-authentication-request-parameters.js → oauth-authorization-request-parameters.js} +16 -17
  32. package/dist/oauth-authorization-request-parameters.js.map +1 -0
  33. package/dist/oauth-authorization-request-query.d.ts +128 -0
  34. package/dist/oauth-authorization-request-query.d.ts.map +1 -0
  35. package/dist/oauth-authorization-request-query.js +13 -0
  36. package/dist/oauth-authorization-request-query.js.map +1 -0
  37. package/dist/oauth-authorization-request-uri.d.ts +10 -0
  38. package/dist/oauth-authorization-request-uri.d.ts.map +1 -0
  39. package/dist/oauth-authorization-request-uri.js +9 -0
  40. package/dist/oauth-authorization-request-uri.js.map +1 -0
  41. package/dist/oauth-authorization-server-metadata.d.ts +16 -16
  42. package/dist/oauth-authorization-server-metadata.d.ts.map +1 -1
  43. package/dist/oauth-authorization-server-metadata.js +5 -1
  44. package/dist/oauth-authorization-server-metadata.js.map +1 -1
  45. package/dist/oauth-client-credentials-grant-token-request.d.ts +10 -0
  46. package/dist/oauth-client-credentials-grant-token-request.d.ts.map +1 -0
  47. package/dist/oauth-client-credentials-grant-token-request.js +8 -0
  48. package/dist/oauth-client-credentials-grant-token-request.js.map +1 -0
  49. package/dist/oauth-client-credentials.d.ts +18 -2
  50. package/dist/oauth-client-credentials.d.ts.map +1 -1
  51. package/dist/oauth-client-credentials.js +8 -2
  52. package/dist/oauth-client-credentials.js.map +1 -1
  53. package/dist/oauth-client-id-discoverable.d.ts +3 -2
  54. package/dist/oauth-client-id-discoverable.d.ts.map +1 -1
  55. package/dist/oauth-client-id-discoverable.js +22 -20
  56. package/dist/oauth-client-id-discoverable.js.map +1 -1
  57. package/dist/oauth-client-id-loopback.d.ts +10 -3
  58. package/dist/oauth-client-id-loopback.d.ts.map +1 -1
  59. package/dist/oauth-client-id-loopback.js +59 -23
  60. package/dist/oauth-client-id-loopback.js.map +1 -1
  61. package/dist/oauth-client-metadata.d.ts +91 -91
  62. package/dist/oauth-client-metadata.d.ts.map +1 -1
  63. package/dist/oauth-client-metadata.js +2 -1
  64. package/dist/oauth-client-metadata.js.map +1 -1
  65. package/dist/oauth-code-challenge-method.d.ts +3 -0
  66. package/dist/oauth-code-challenge-method.d.ts.map +1 -0
  67. package/dist/oauth-code-challenge-method.js +6 -0
  68. package/dist/oauth-code-challenge-method.js.map +1 -0
  69. package/dist/oauth-introspection-response.d.ts +20 -0
  70. package/dist/oauth-introspection-response.d.ts.map +1 -0
  71. package/dist/oauth-introspection-response.js +3 -0
  72. package/dist/oauth-introspection-response.js.map +1 -0
  73. package/dist/oauth-issuer-identifier.d.ts +2 -1
  74. package/dist/oauth-issuer-identifier.d.ts.map +1 -1
  75. package/dist/oauth-issuer-identifier.js +13 -12
  76. package/dist/oauth-issuer-identifier.js.map +1 -1
  77. package/dist/oauth-par-response.d.ts +3 -0
  78. package/dist/oauth-par-response.d.ts.map +1 -1
  79. package/dist/oauth-par-response.js +1 -0
  80. package/dist/oauth-par-response.js.map +1 -1
  81. package/dist/oauth-password-grant-token-request.d.ts +16 -0
  82. package/dist/oauth-password-grant-token-request.d.ts.map +1 -0
  83. package/dist/oauth-password-grant-token-request.js +10 -0
  84. package/dist/oauth-password-grant-token-request.js.map +1 -0
  85. package/dist/oauth-protected-resource-metadata.d.ts +2 -2
  86. package/dist/oauth-refresh-token-grant-token-request.d.ts +13 -0
  87. package/dist/oauth-refresh-token-grant-token-request.d.ts.map +1 -0
  88. package/dist/oauth-refresh-token-grant-token-request.js +10 -0
  89. package/dist/oauth-refresh-token-grant-token-request.js.map +1 -0
  90. package/dist/oauth-refresh-token.d.ts +4 -0
  91. package/dist/oauth-refresh-token.d.ts.map +1 -0
  92. package/dist/oauth-refresh-token.js +6 -0
  93. package/dist/oauth-refresh-token.js.map +1 -0
  94. package/dist/oauth-request-uri.d.ts +4 -0
  95. package/dist/oauth-request-uri.d.ts.map +1 -0
  96. package/dist/oauth-request-uri.js +6 -0
  97. package/dist/oauth-request-uri.js.map +1 -0
  98. package/dist/oauth-scope.d.ts +10 -0
  99. package/dist/oauth-scope.d.ts.map +1 -0
  100. package/dist/oauth-scope.js +16 -0
  101. package/dist/oauth-scope.js.map +1 -0
  102. package/dist/oauth-token-identification.d.ts +13 -0
  103. package/dist/oauth-token-identification.d.ts.map +1 -0
  104. package/dist/oauth-token-identification.js +11 -0
  105. package/dist/oauth-token-identification.js.map +1 -0
  106. package/dist/oauth-token-request.d.ts +46 -0
  107. package/dist/oauth-token-request.d.ts.map +1 -0
  108. package/dist/oauth-token-request.js +15 -0
  109. package/dist/oauth-token-request.js.map +1 -0
  110. package/dist/oauth-token-response.d.ts +3 -6
  111. package/dist/oauth-token-response.d.ts.map +1 -1
  112. package/dist/oauth-token-response.js +4 -2
  113. package/dist/oauth-token-response.js.map +1 -1
  114. package/dist/util.d.ts +2 -1
  115. package/dist/util.d.ts.map +1 -1
  116. package/dist/util.js +36 -6
  117. package/dist/util.js.map +1 -1
  118. package/package.json +2 -2
  119. package/src/atproto-loopback-client-metadata.ts +7 -20
  120. package/src/constants.ts +0 -16
  121. package/src/index.ts +18 -5
  122. package/src/oauth-access-token.ts +4 -0
  123. package/src/oauth-authorization-code-grant-token-request.ts +18 -0
  124. package/src/oauth-authorization-request-jar.ts +16 -0
  125. package/src/oauth-authorization-request-par.ts +13 -0
  126. package/src/{oauth-authentication-request-parameters.ts → oauth-authorization-request-parameters.ts} +21 -22
  127. package/src/oauth-authorization-request-query.ts +15 -0
  128. package/src/oauth-authorization-request-uri.ts +11 -0
  129. package/src/oauth-authorization-server-metadata.ts +5 -1
  130. package/src/oauth-client-credentials-grant-token-request.ts +9 -0
  131. package/src/oauth-client-credentials.ts +21 -1
  132. package/src/oauth-client-id-discoverable.ts +29 -26
  133. package/src/oauth-client-id-loopback.ts +78 -30
  134. package/src/oauth-client-metadata.ts +2 -1
  135. package/src/oauth-code-challenge-method.ts +3 -0
  136. package/src/oauth-introspection-response.ts +23 -0
  137. package/src/oauth-issuer-identifier.ts +17 -12
  138. package/src/oauth-par-response.ts +1 -0
  139. package/src/oauth-password-grant-token-request.ts +11 -0
  140. package/src/oauth-refresh-token-grant-token-request.ts +11 -0
  141. package/src/oauth-refresh-token.ts +4 -0
  142. package/src/oauth-request-uri.ts +5 -0
  143. package/src/oauth-scope.ts +15 -0
  144. package/src/oauth-token-identification.ts +12 -0
  145. package/src/oauth-token-request.ts +14 -0
  146. package/src/oauth-token-response.ts +4 -2
  147. package/src/util.ts +41 -1
  148. package/tsconfig.build.tsbuildinfo +1 -0
  149. package/dist/access-token.d.ts +0 -4
  150. package/dist/access-token.d.ts.map +0 -1
  151. package/dist/access-token.js +0 -6
  152. package/dist/access-token.js.map +0 -1
  153. package/dist/oauth-authentication-request-parameters.d.ts.map +0 -1
  154. package/dist/oauth-authentication-request-parameters.js.map +0 -1
  155. package/dist/oauth-client-id-url.d.ts +0 -3
  156. package/dist/oauth-client-id-url.d.ts.map +0 -1
  157. package/dist/oauth-client-id-url.js +0 -21
  158. package/dist/oauth-client-id-url.js.map +0 -1
  159. package/dist/oauth-client-identification.d.ts +0 -31
  160. package/dist/oauth-client-identification.d.ts.map +0 -1
  161. package/dist/oauth-client-identification.js +0 -12
  162. package/dist/oauth-client-identification.js.map +0 -1
  163. package/src/access-token.ts +0 -4
  164. package/src/oauth-client-id-url.ts +0 -25
  165. package/src/oauth-client-identification.ts +0 -14
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseOAuthDiscoverableClientId = exports.isOAuthClientIdDiscoverable = void 0;
4
- const oauth_client_id_url_js_1 = require("./oauth-client-id-url.js");
3
+ exports.isOAuthClientIdDiscoverable = isOAuthClientIdDiscoverable;
4
+ exports.assertOAuthDiscoverableClientId = assertOAuthDiscoverableClientId;
5
+ exports.parseOAuthDiscoverableClientId = parseOAuthDiscoverableClientId;
5
6
  const util_js_1 = require("./util.js");
6
7
  function isOAuthClientIdDiscoverable(clientId) {
7
8
  try {
@@ -12,37 +13,38 @@ function isOAuthClientIdDiscoverable(clientId) {
12
13
  return false;
13
14
  }
14
15
  }
15
- exports.isOAuthClientIdDiscoverable = isOAuthClientIdDiscoverable;
16
+ function assertOAuthDiscoverableClientId(value) {
17
+ void parseOAuthDiscoverableClientId(value);
18
+ }
16
19
  function parseOAuthDiscoverableClientId(clientId) {
17
- const url = (0, oauth_client_id_url_js_1.parseOAuthClientIdUrl)(clientId);
18
- // Optimization: cheap checks first
19
- if (url.hostname === 'localhost') {
20
- throw new TypeError('ClientID must not be a loopback hostname');
21
- }
20
+ const url = new URL(clientId);
22
21
  if (url.protocol !== 'https:') {
23
22
  throw new TypeError('ClientID must use the "https:" protocol');
24
23
  }
24
+ if (url.username || url.password) {
25
+ throw new TypeError('ClientID must not contain credentials');
26
+ }
25
27
  if (url.hash) {
26
28
  throw new TypeError('ClientID must not contain a fragment');
27
29
  }
28
- if (url.username || url.password) {
29
- throw new TypeError('ClientID must not contain credentials');
30
+ if (url.hostname === 'localhost') {
31
+ throw new TypeError('ClientID hostname must not be "localhost"');
30
32
  }
31
33
  if (url.pathname === '/') {
32
- throw new TypeError('ClientID must contain a path (e.g. "/client-metadata")');
34
+ throw new TypeError('ClientID must contain a path component (e.g. "/client-metadata.json")');
33
35
  }
34
- if (url.pathname !== '/' && url.pathname.endsWith('/')) {
35
- throw new TypeError('ClientID must not end with a trailing slash');
36
+ if (url.pathname.endsWith('/')) {
37
+ throw new TypeError('ClientID path must not end with a trailing slash');
36
38
  }
37
- if (url.pathname.includes('//')) {
38
- throw new TypeError(`ClientID must not contain any double slashes in its path`);
39
+ if ((0, util_js_1.isHostnameIP)(url.hostname)) {
40
+ throw new TypeError('ClientID hostname must not be an IP address');
39
41
  }
40
- // Note: Query string is allowed
41
- // Note: no restriction on the port for non-loopback URIs
42
- if ((0, util_js_1.isIP)(url.hostname)) {
43
- throw new TypeError('ClientID must not be an IP address');
42
+ // URL constructor normalizes the URL, so we extract the path manually to
43
+ // avoid normalization, then compare it to the normalized path to ensure
44
+ // that the URL does not contain path traversal or other unexpected characters
45
+ if ((0, util_js_1.extractUrlPath)(clientId) !== url.pathname) {
46
+ throw new TypeError(`ClientID must be in canonical form ("${url.href}", got "${clientId}")`);
44
47
  }
45
48
  return url;
46
49
  }
47
- exports.parseOAuthDiscoverableClientId = parseOAuthDiscoverableClientId;
48
50
  //# sourceMappingURL=oauth-client-id-discoverable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-client-id-discoverable.js","sourceRoot":"","sources":["../src/oauth-client-id-discoverable.ts"],"names":[],"mappings":";;;AAAA,qEAAgE;AAEhE,uCAAgC;AAOhC,SAAgB,2BAA2B,CACzC,QAAW;IAEX,IAAI,CAAC;QACH,8BAA8B,CAAC,QAAQ,CAAC,CAAA;QACxC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AATD,kEASC;AAED,SAAgB,8BAA8B,CAAC,QAAuB;IACpE,MAAM,GAAG,GAAG,IAAA,8CAAqB,EAAC,QAAQ,CAAC,CAAA;IAE3C,mCAAmC;IAEnC,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAA;IACjE,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAA;IAChE,CAAC;IAED,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAA;IAC7D,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CAAC,uCAAuC,CAAC,CAAA;IAC9D,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CACjB,wDAAwD,CACzD,CAAA;IACH,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvD,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAA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,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAA;IAClE,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CACjB,uEAAuE,CACxE,CAAA;IACH,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAA;IACzE,CAAC;IAED,IAAI,IAAA,sBAAY,EAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAA;IACpE,CAAC;IAED,yEAAyE;IACzE,wEAAwE;IACxE,8EAA8E;IAC9E,IAAI,IAAA,wBAAc,EAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,SAAS,CACjB,wCAAwC,GAAG,CAAC,IAAI,WAAW,QAAQ,IAAI,CACxE,CAAA;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
@@ -1,5 +1,12 @@
1
1
  import { OAuthClientId } from './oauth-client-id.js';
2
- export type OAuthClientIdLoopback = OAuthClientId & `http://localhost${'' | `${'/' | '?' | '#'}${string}`}`;
3
- export declare function isOAuthClientIdLoopback<C extends OAuthClientId>(clientId: C): clientId is C & OAuthClientIdLoopback;
4
- export declare function parseOAuthLoopbackClientId(clientId: OAuthClientId): URL;
2
+ import { OAuthScope } from './oauth-scope.js';
3
+ declare const OAUTH_CLIENT_ID_LOOPBACK_URL = "http://localhost";
4
+ export type OAuthClientIdLoopback = OAuthClientId & `${typeof OAUTH_CLIENT_ID_LOOPBACK_URL}${'' | '/'}${'' | `?${string}`}`;
5
+ export declare function isOAuthClientIdLoopback(clientId: string): clientId is OAuthClientIdLoopback;
6
+ export declare function assertOAuthLoopbackClientId(clientId: string): asserts clientId is OAuthClientIdLoopback;
7
+ export declare function parseOAuthLoopbackClientId(clientId: string): {
8
+ scope?: OAuthScope;
9
+ redirect_uris?: [string, ...string[]];
10
+ };
11
+ export {};
5
12
  //# sourceMappingURL=oauth-client-id-loopback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-client-id-loopback.d.ts","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAC/C,mBAAmB,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,EAAE,EAAE,CAAA;AAEzD,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,aAAa,EAC7D,QAAQ,EAAE,CAAC,GACV,QAAQ,IAAI,CAAC,GAAG,qBAAqB,CAOvC;AAED,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,aAAa,GAAG,GAAG,CAwCvE"}
1
+ {"version":3,"file":"oauth-client-id-loopback.d.ts","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAA;AAG/D,QAAA,MAAM,4BAA4B,qBAAqB,CAAA;AAEvD,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAC/C,GAAG,OAAO,4BAA4B,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,IAAI,MAAM,EAAE,EAAE,CAAA;AAEzE,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,GACf,QAAQ,IAAI,qBAAqB,CAOnC;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,QAAQ,IAAI,qBAAqB,CAE3C;AAID,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG;IAC5D,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;CACtC,CA0EA"}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseOAuthLoopbackClientId = exports.isOAuthClientIdLoopback = void 0;
4
- const oauth_client_id_url_js_1 = require("./oauth-client-id-url.js");
3
+ exports.isOAuthClientIdLoopback = isOAuthClientIdLoopback;
4
+ exports.assertOAuthLoopbackClientId = assertOAuthLoopbackClientId;
5
+ exports.parseOAuthLoopbackClientId = parseOAuthLoopbackClientId;
6
+ const oauth_scope_js_1 = require("./oauth-scope.js");
7
+ const util_js_1 = require("./util.js");
8
+ const OAUTH_CLIENT_ID_LOOPBACK_URL = 'http://localhost';
5
9
  function isOAuthClientIdLoopback(clientId) {
6
10
  try {
7
11
  parseOAuthLoopbackClientId(clientId);
@@ -11,34 +15,66 @@ function isOAuthClientIdLoopback(clientId) {
11
15
  return false;
12
16
  }
13
17
  }
14
- exports.isOAuthClientIdLoopback = isOAuthClientIdLoopback;
18
+ function assertOAuthLoopbackClientId(clientId) {
19
+ void parseOAuthLoopbackClientId(clientId);
20
+ }
21
+ // @TODO: should we turn this into a zod schema? (more coherent error with other
22
+ // validation functions)
15
23
  function parseOAuthLoopbackClientId(clientId) {
16
- const url = (0, oauth_client_id_url_js_1.parseOAuthClientIdUrl)(clientId);
17
- // Optimization: cheap checks first
18
- if (url.protocol !== 'http:') {
19
- throw new TypeError('Loopback ClientID must use the "http:" protocol');
24
+ if (!clientId.startsWith(OAUTH_CLIENT_ID_LOOPBACK_URL)) {
25
+ throw new TypeError(`Loopback ClientID must start with "${OAUTH_CLIENT_ID_LOOPBACK_URL}"`);
20
26
  }
21
- if (url.hostname !== 'localhost') {
22
- throw new TypeError('Loopback ClientID must use the "localhost" hostname');
27
+ else if (clientId.includes('#', OAUTH_CLIENT_ID_LOOPBACK_URL.length)) {
28
+ throw new TypeError('Loopback ClientID must not contain a hash component');
23
29
  }
24
- if (url.hash) {
25
- throw new TypeError('Loopback ClientID must not contain a fragment');
30
+ const queryStringIdx = clientId.length > OAUTH_CLIENT_ID_LOOPBACK_URL.length &&
31
+ clientId[OAUTH_CLIENT_ID_LOOPBACK_URL.length] === '/'
32
+ ? OAUTH_CLIENT_ID_LOOPBACK_URL.length + 1
33
+ : OAUTH_CLIENT_ID_LOOPBACK_URL.length;
34
+ if (clientId.length === queryStringIdx) {
35
+ return {}; // no query string to parse
26
36
  }
27
- if (url.username || url.password) {
28
- throw new TypeError('Loopback ClientID must not contain credentials');
37
+ if (clientId[queryStringIdx] !== '?') {
38
+ throw new TypeError('Loopback ClientID must not contain a path component');
29
39
  }
30
- if (url.port) {
31
- throw new TypeError('Loopback ClientID must not contain a port');
40
+ const searchParams = new URLSearchParams(clientId.slice(queryStringIdx + 1));
41
+ for (const name of searchParams.keys()) {
42
+ if (name !== 'redirect_uri' && name !== 'scope') {
43
+ throw new TypeError(`Invalid query parameter "${name}" in client ID`);
44
+ }
32
45
  }
33
- // Note: url.pathname === '/' is allowed for loopback URIs
34
- if (url.pathname !== '/' && url.pathname.endsWith('/')) {
35
- throw new TypeError('Loopback ClientID must not end with a trailing slash');
46
+ const scope = searchParams.get('scope') ?? undefined;
47
+ if (scope != null) {
48
+ if (searchParams.getAll('scope').length > 1) {
49
+ throw new TypeError('Loopback ClientID must contain at most one scope query parameter');
50
+ }
51
+ else if (!oauth_scope_js_1.oauthScopeSchema.safeParse(scope).success) {
52
+ throw new TypeError('Invalid scope query parameter in client ID');
53
+ }
36
54
  }
37
- if (url.pathname.includes('//')) {
38
- throw new TypeError(`Loopback ClientID must not contain any double slashes in its path`);
55
+ const redirect_uris = searchParams.has('redirect_uri')
56
+ ? searchParams.getAll('redirect_uri')
57
+ : undefined;
58
+ if (redirect_uris) {
59
+ for (const uri of redirect_uris) {
60
+ const url = (0, util_js_1.safeUrl)(uri);
61
+ if (!url) {
62
+ throw new TypeError(`Invalid redirect_uri in client ID: ${uri}`);
63
+ }
64
+ if (url.protocol !== 'http:') {
65
+ throw new TypeError(`Loopback ClientID must use "http:" redirect_uri's (got ${uri})`);
66
+ }
67
+ if (url.hostname === 'localhost') {
68
+ throw new TypeError(`Loopback ClientID must not use "localhost" as redirect_uri hostname (got ${uri})`);
69
+ }
70
+ if (!(0, util_js_1.isLoopbackHost)(url.hostname)) {
71
+ throw new TypeError(`Loopback ClientID must use loopback addresses as redirect_uri's (got ${uri})`);
72
+ }
73
+ }
39
74
  }
40
- // Note: Query string is allowed
41
- return url;
75
+ return {
76
+ scope,
77
+ redirect_uris,
78
+ };
42
79
  }
43
- exports.parseOAuthLoopbackClientId = parseOAuthLoopbackClientId;
44
80
  //# sourceMappingURL=oauth-client-id-loopback.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-client-id-loopback.js","sourceRoot":"","sources":["../src/oauth-client-id-loopback.ts"],"names":[],"mappings":";;;AAAA,qEAAgE;AAMhE,SAAgB,uBAAuB,CACrC,QAAW;IAEX,IAAI,CAAC;QACH,0BAA0B,CAAC,QAAQ,CAAC,CAAA;QACpC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AATD,0DASC;AAED,SAAgB,0BAA0B,CAAC,QAAuB;IAChE,MAAM,GAAG,GAAG,IAAA,8CAAqB,EAAC,QAAQ,CAAC,CAAA;IAE3C,mCAAmC;IAEnC,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAA;IACxE,CAAC;IAED,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CAAC,qDAAqD,CAAC,CAAA;IAC5E,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