@scalar/mock-server 0.3.26 → 0.3.27

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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @scalar/mock-server
2
2
 
3
+ ## 0.3.27
4
+
5
+ ### Patch Changes
6
+
7
+ - cb9428c: Support additional query parameters for the OAuth authorization request (prompt, audience, anything), and handle OAuth authorization denials
8
+ - Updated dependencies [cb9428c]
9
+ - Updated dependencies [67aa0f4]
10
+ - @scalar/openapi-types@0.2.3
11
+ - @scalar/oas-utils@0.2.143
12
+ - @scalar/openapi-parser@0.10.17
13
+
3
14
  ## 0.3.26
4
15
 
5
16
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"respondWithAuthorizePage.d.ts","sourceRoot":"","sources":["../../src/routes/respondWithAuthorizePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAKnC;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,SAAK,YAoC9D"}
1
+ {"version":3,"file":"respondWithAuthorizePage.d.ts","sourceRoot":"","sources":["../../src/routes/respondWithAuthorizePage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAKnC;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,SAAK,YA2C9D"}
@@ -17,7 +17,13 @@ function respondWithAuthorizePage(c, title = "") {
17
17
  if (state) {
18
18
  redirectUrl.searchParams.set("state", state);
19
19
  }
20
- const htmlContent = generateAuthorizationHtml(redirectUrl.toString(), title);
20
+ const deniedUrl = new URL(redirectUri);
21
+ if (state) {
22
+ deniedUrl.searchParams.set("state", state);
23
+ }
24
+ deniedUrl.searchParams.set("error", "access_denied");
25
+ deniedUrl.searchParams.set("error_description", "User has denied the authorization request");
26
+ const htmlContent = generateAuthorizationHtml(redirectUrl.toString(), deniedUrl.toString(), title);
21
27
  return c.html(htmlContent);
22
28
  } catch {
23
29
  return c.html(
@@ -29,7 +35,7 @@ function respondWithAuthorizePage(c, title = "") {
29
35
  );
30
36
  }
31
37
  }
32
- function generateAuthorizationHtml(redirectUrl, title = "") {
38
+ function generateAuthorizationHtml(redirectUrl, deniedUrl, title = "") {
33
39
  return `
34
40
  <!DOCTYPE html>
35
41
  <html lang="en">
@@ -63,7 +69,7 @@ function generateAuthorizationHtml(redirectUrl, title = "") {
63
69
  </p>
64
70
  </div>
65
71
  <div class="px-6 py-4 pt-0 flex justify-between">
66
- <a href="javascript:history.back()" class="inline-block px-6 py-2 text-gray-600 rounded border" aria-label="Cancel authorization">
72
+ <a href="${deniedUrl}" class="inline-block px-6 py-2 text-gray-600 rounded border" aria-label="Cancel authorization">
67
73
  Cancel
68
74
  </a>
69
75
  <a href="${redirectUrl}" class="inline-block px-6 py-2 bg-black text-white rounded transition-colors duration-300 hover:bg-gray-800" aria-label="Authorize application">
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/routes/respondWithAuthorizePage.ts"],
4
- "sourcesContent": ["import type { Context } from 'hono'\n\n/** Always responds with this code */\nconst EXAMPLE_AUTHORIZATION_CODE = 'super-secret-token'\n\n/**\n * Responds with an HTML page that simulates an OAuth 2.0 authorization page.\n */\nexport function respondWithAuthorizePage(c: Context, title = '') {\n const redirectUri = c.req.query('redirect_uri')\n const state = c.req.query('state')\n\n if (!redirectUri) {\n return c.html(\n generateErrorHtml(\n 'Missing redirect_uri parameter',\n 'This parameter is required for the OAuth 2.0 authorization flow to function correctly. Please provide a valid redirect URI in your request.',\n ),\n 400,\n )\n }\n\n try {\n // Validate redirect URI against allowed domains\n const redirectUrl = new URL(redirectUri)\n\n redirectUrl.searchParams.set('code', EXAMPLE_AUTHORIZATION_CODE)\n\n if (state) {\n redirectUrl.searchParams.set('state', state)\n }\n\n const htmlContent = generateAuthorizationHtml(redirectUrl.toString(), title)\n\n return c.html(htmlContent)\n } catch {\n return c.html(\n generateErrorHtml(\n 'Invalid redirect_uri format',\n 'Please provide a valid URL. The redirect_uri parameter must be a properly formatted URL that includes the protocol (e.g., https://) and a valid domain. This is essential for the OAuth 2.0 flow to securely redirect after authorization.',\n ),\n 400,\n )\n }\n}\n\nfunction generateAuthorizationHtml(redirectUrl: string, title = '') {\n return `\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>OAuth 2.0 Authorization</title>\n <script src=\"https://cdn.tailwindcss.com\"></script>\n </head>\n <body class=\"flex justify-center items-center h-screen bg-gray-100\">\n\n <div class=\"flex flex-col\">\n <div class=\"mb-5 flex justify-center items-center gap-2\">\n <img src=\"https://scalar.com/logo-dark.svg\" class=\"w-6 inline-block\" />\n <div class=\"font-medium truncate max-w-[26ch] text-lg\">\n ${title}\n </div>\n </div>\n <div class=\"bg-gray-50 rounded-lg p-1 rounded-lg w-[28rem] shadow\">\n <div class=\"\">\n <h1 class=\"text font-medium text-gray-800 px-6 pt-2 pb-3 flex gap-3 rounded-t-lg\">\n OAuth 2.0 Authorization\n </h1>\n <div class=\"bg-white rounded\">\n <div class=\"text-gray-600 text-base px-6 py-5 flex flex-col gap-3\">\n <p>\n This application is requesting access to your account. By granting authorization, you allow the application to perform certain actions on your behalf.\n </p>\n <p>\n If you\u2019re comfortable with the access being requested, click the button below to grant authorization:\n </p>\n </div>\n <div class=\"px-6 py-4 pt-0 flex justify-between\">\n <a href=\"javascript:history.back()\" class=\"inline-block px-6 py-2 text-gray-600 rounded border\" aria-label=\"Cancel authorization\">\n Cancel\n </a>\n <a href=\"${redirectUrl}\" class=\"inline-block px-6 py-2 bg-black text-white rounded transition-colors duration-300 hover:bg-gray-800\" aria-label=\"Authorize application\">\n Authorize\n </a>\n </div>\n </div>\n </div>\n </div>\n\n <p class=\"text-xs text-gray-400 mt-5 text-center\">\n This authorization page is provided by @scalar/mock-server\n </p>\n\n </div>\n </body>\n</html>\n `\n}\n\nfunction generateErrorHtml(title: string, message: string) {\n return `<html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>OAuth 2.0 Authorization</title>\n <script src=\"https://cdn.tailwindcss.com\"></script>\n </head>\n <body>\n <div class=\"p-4 m-8 flex flex-col gap-4 text-lg\">\n <h1 class=\"font-bold\">\n Error: ${title}\n </h1>\n <p>\n ${message}\n </p>\n <p>\n Example: <code class=\"bg-gray-100 py-1 px-2 rounded text-base\"><a href=\"?redirect_uri=https://example.com/callback\">?redirect_uri=https://example.com/callback</a></code>\n </p>\n </div>\n </body>\n</html>`\n}\n"],
5
- "mappings": "AAGA,MAAM,6BAA6B;AAK5B,SAAS,yBAAyB,GAAY,QAAQ,IAAI;AAC/D,QAAM,cAAc,EAAE,IAAI,MAAM,cAAc;AAC9C,QAAM,QAAQ,EAAE,IAAI,MAAM,OAAO;AAEjC,MAAI,CAAC,aAAa;AAChB,WAAO,EAAE;AAAA,MACP;AAAA,QACE;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AAEF,UAAM,cAAc,IAAI,IAAI,WAAW;AAEvC,gBAAY,aAAa,IAAI,QAAQ,0BAA0B;AAE/D,QAAI,OAAO;AACT,kBAAY,aAAa,IAAI,SAAS,KAAK;AAAA,IAC7C;AAEA,UAAM,cAAc,0BAA0B,YAAY,SAAS,GAAG,KAAK;AAE3E,WAAO,EAAE,KAAK,WAAW;AAAA,EAC3B,QAAQ;AACN,WAAO,EAAE;AAAA,MACP;AAAA,QACE;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,0BAA0B,aAAqB,QAAQ,IAAI;AAClE,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAeG,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAqBQ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBpC;AAEA,SAAS,kBAAkB,OAAe,SAAiB;AACzD,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAWQ,KAAK;AAAA;AAAA;AAAA,UAGZ,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQjB;",
4
+ "sourcesContent": ["import type { Context } from 'hono'\n\n/** Always responds with this code */\nconst EXAMPLE_AUTHORIZATION_CODE = 'super-secret-token'\n\n/**\n * Responds with an HTML page that simulates an OAuth 2.0 authorization page.\n */\nexport function respondWithAuthorizePage(c: Context, title = '') {\n const redirectUri = c.req.query('redirect_uri')\n const state = c.req.query('state')\n\n if (!redirectUri) {\n return c.html(\n generateErrorHtml(\n 'Missing redirect_uri parameter',\n 'This parameter is required for the OAuth 2.0 authorization flow to function correctly. Please provide a valid redirect URI in your request.',\n ),\n 400,\n )\n }\n\n try {\n // Validate redirect URI against allowed domains\n const redirectUrl = new URL(redirectUri)\n\n redirectUrl.searchParams.set('code', EXAMPLE_AUTHORIZATION_CODE)\n\n if (state) {\n redirectUrl.searchParams.set('state', state)\n }\n\n const deniedUrl = new URL(redirectUri)\n if (state) {\n deniedUrl.searchParams.set('state', state)\n }\n deniedUrl.searchParams.set('error', 'access_denied')\n deniedUrl.searchParams.set('error_description', 'User has denied the authorization request')\n\n const htmlContent = generateAuthorizationHtml(redirectUrl.toString(), deniedUrl.toString(), title)\n\n return c.html(htmlContent)\n } catch {\n return c.html(\n generateErrorHtml(\n 'Invalid redirect_uri format',\n 'Please provide a valid URL. The redirect_uri parameter must be a properly formatted URL that includes the protocol (e.g., https://) and a valid domain. This is essential for the OAuth 2.0 flow to securely redirect after authorization.',\n ),\n 400,\n )\n }\n}\n\nfunction generateAuthorizationHtml(redirectUrl: string, deniedUrl: string, title = '') {\n return `\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>OAuth 2.0 Authorization</title>\n <script src=\"https://cdn.tailwindcss.com\"></script>\n </head>\n <body class=\"flex justify-center items-center h-screen bg-gray-100\">\n\n <div class=\"flex flex-col\">\n <div class=\"mb-5 flex justify-center items-center gap-2\">\n <img src=\"https://scalar.com/logo-dark.svg\" class=\"w-6 inline-block\" />\n <div class=\"font-medium truncate max-w-[26ch] text-lg\">\n ${title}\n </div>\n </div>\n <div class=\"bg-gray-50 rounded-lg p-1 rounded-lg w-[28rem] shadow\">\n <div class=\"\">\n <h1 class=\"text font-medium text-gray-800 px-6 pt-2 pb-3 flex gap-3 rounded-t-lg\">\n OAuth 2.0 Authorization\n </h1>\n <div class=\"bg-white rounded\">\n <div class=\"text-gray-600 text-base px-6 py-5 flex flex-col gap-3\">\n <p>\n This application is requesting access to your account. By granting authorization, you allow the application to perform certain actions on your behalf.\n </p>\n <p>\n If you\u2019re comfortable with the access being requested, click the button below to grant authorization:\n </p>\n </div>\n <div class=\"px-6 py-4 pt-0 flex justify-between\">\n <a href=\"${deniedUrl}\" class=\"inline-block px-6 py-2 text-gray-600 rounded border\" aria-label=\"Cancel authorization\">\n Cancel\n </a>\n <a href=\"${redirectUrl}\" class=\"inline-block px-6 py-2 bg-black text-white rounded transition-colors duration-300 hover:bg-gray-800\" aria-label=\"Authorize application\">\n Authorize\n </a>\n </div>\n </div>\n </div>\n </div>\n\n <p class=\"text-xs text-gray-400 mt-5 text-center\">\n This authorization page is provided by @scalar/mock-server\n </p>\n\n </div>\n </body>\n</html>\n `\n}\n\nfunction generateErrorHtml(title: string, message: string) {\n return `<html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>OAuth 2.0 Authorization</title>\n <script src=\"https://cdn.tailwindcss.com\"></script>\n </head>\n <body>\n <div class=\"p-4 m-8 flex flex-col gap-4 text-lg\">\n <h1 class=\"font-bold\">\n Error: ${title}\n </h1>\n <p>\n ${message}\n </p>\n <p>\n Example: <code class=\"bg-gray-100 py-1 px-2 rounded text-base\"><a href=\"?redirect_uri=https://example.com/callback\">?redirect_uri=https://example.com/callback</a></code>\n </p>\n </div>\n </body>\n</html>`\n}\n"],
5
+ "mappings": "AAGA,MAAM,6BAA6B;AAK5B,SAAS,yBAAyB,GAAY,QAAQ,IAAI;AAC/D,QAAM,cAAc,EAAE,IAAI,MAAM,cAAc;AAC9C,QAAM,QAAQ,EAAE,IAAI,MAAM,OAAO;AAEjC,MAAI,CAAC,aAAa;AAChB,WAAO,EAAE;AAAA,MACP;AAAA,QACE;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AAEF,UAAM,cAAc,IAAI,IAAI,WAAW;AAEvC,gBAAY,aAAa,IAAI,QAAQ,0BAA0B;AAE/D,QAAI,OAAO;AACT,kBAAY,aAAa,IAAI,SAAS,KAAK;AAAA,IAC7C;AAEA,UAAM,YAAY,IAAI,IAAI,WAAW;AACrC,QAAI,OAAO;AACT,gBAAU,aAAa,IAAI,SAAS,KAAK;AAAA,IAC3C;AACA,cAAU,aAAa,IAAI,SAAS,eAAe;AACnD,cAAU,aAAa,IAAI,qBAAqB,2CAA2C;AAE3F,UAAM,cAAc,0BAA0B,YAAY,SAAS,GAAG,UAAU,SAAS,GAAG,KAAK;AAEjG,WAAO,EAAE,KAAK,WAAW;AAAA,EAC3B,QAAQ;AACN,WAAO,EAAE;AAAA,MACP;AAAA,QACE;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,0BAA0B,aAAqB,WAAmB,QAAQ,IAAI;AACrF,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAeG,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAkBQ,SAAS;AAAA;AAAA;AAAA,yBAGT,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBpC;AAEA,SAAS,kBAAkB,OAAe,SAAiB;AACzD,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAWQ,KAAK;AAAA;AAAA;AAAA,UAGZ,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQjB;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "swagger",
17
17
  "cli"
18
18
  ],
19
- "version": "0.3.26",
19
+ "version": "0.3.27",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -38,16 +38,16 @@
38
38
  "dependencies": {
39
39
  "hono": "^4.6.5",
40
40
  "object-to-xml": "^2.0.0",
41
- "@scalar/oas-utils": "0.2.142",
42
- "@scalar/openapi-parser": "0.10.17",
43
- "@scalar/openapi-types": "0.2.2"
41
+ "@scalar/oas-utils": "0.2.143",
42
+ "@scalar/openapi-types": "0.2.3",
43
+ "@scalar/openapi-parser": "0.10.17"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@hono/node-server": "^1.11.0",
47
47
  "@types/node": "^20.17.10",
48
48
  "vite": "5.4.19",
49
49
  "@scalar/build-tooling": "0.1.19",
50
- "@scalar/hono-api-reference": "0.8.8"
50
+ "@scalar/hono-api-reference": "0.8.9"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "scalar-build-esbuild",