nextidp 0.1.5 → 0.4.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 (73) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +86 -0
  3. package/dist/cjs/access-token.d.ts +29 -4
  4. package/dist/cjs/access-token.js +53 -10
  5. package/dist/cjs/config.d.ts +36 -0
  6. package/dist/cjs/config.js +36 -1
  7. package/dist/cjs/discovery.d.ts +2 -0
  8. package/dist/cjs/discovery.js +2 -0
  9. package/dist/cjs/errors.d.ts +16 -3
  10. package/dist/cjs/errors.js +7 -1
  11. package/dist/cjs/exchange.d.ts +21 -0
  12. package/dist/cjs/exchange.js +76 -0
  13. package/dist/cjs/express.d.ts +12 -1
  14. package/dist/cjs/express.js +7 -0
  15. package/dist/cjs/fastify.d.ts +13 -1
  16. package/dist/cjs/fastify.js +14 -0
  17. package/dist/cjs/hono.d.ts +12 -1
  18. package/dist/cjs/hono.js +8 -0
  19. package/dist/cjs/id-token.js +1 -1
  20. package/dist/cjs/idp.d.ts +27 -1
  21. package/dist/cjs/idp.js +76 -8
  22. package/dist/cjs/index.d.ts +3 -2
  23. package/dist/cjs/nestjs.d.ts +2 -1
  24. package/dist/cjs/next.d.ts +12 -1
  25. package/dist/cjs/next.js +4 -0
  26. package/dist/cjs/node-adapter.d.ts +2 -0
  27. package/dist/cjs/node-adapter.js +8 -0
  28. package/dist/cjs/node.d.ts +7 -1
  29. package/dist/cjs/node.js +1 -0
  30. package/dist/cjs/pushed-authorization.d.ts +9 -0
  31. package/dist/cjs/pushed-authorization.js +66 -0
  32. package/dist/cjs/service.d.ts +3 -0
  33. package/dist/cjs/service.js +13 -41
  34. package/dist/cjs/token-cache.d.ts +18 -0
  35. package/dist/cjs/token-cache.js +75 -0
  36. package/dist/cjs/tokens.d.ts +13 -0
  37. package/dist/cjs/tokens.js +19 -0
  38. package/dist/esm/access-token.d.ts +29 -4
  39. package/dist/esm/access-token.js +50 -9
  40. package/dist/esm/config.d.ts +36 -0
  41. package/dist/esm/config.js +35 -1
  42. package/dist/esm/discovery.d.ts +2 -0
  43. package/dist/esm/discovery.js +2 -0
  44. package/dist/esm/errors.d.ts +16 -3
  45. package/dist/esm/errors.js +7 -1
  46. package/dist/esm/exchange.d.ts +21 -0
  47. package/dist/esm/exchange.js +52 -0
  48. package/dist/esm/express.d.ts +12 -1
  49. package/dist/esm/express.js +7 -0
  50. package/dist/esm/fastify.d.ts +13 -1
  51. package/dist/esm/fastify.js +15 -1
  52. package/dist/esm/hono.d.ts +12 -1
  53. package/dist/esm/hono.js +8 -0
  54. package/dist/esm/id-token.js +1 -1
  55. package/dist/esm/idp.d.ts +27 -1
  56. package/dist/esm/idp.js +79 -9
  57. package/dist/esm/index.d.ts +3 -2
  58. package/dist/esm/nestjs.d.ts +2 -1
  59. package/dist/esm/next.d.ts +12 -1
  60. package/dist/esm/next.js +4 -0
  61. package/dist/esm/node-adapter.d.ts +2 -0
  62. package/dist/esm/node-adapter.js +8 -0
  63. package/dist/esm/node.d.ts +7 -1
  64. package/dist/esm/node.js +1 -0
  65. package/dist/esm/pushed-authorization.d.ts +9 -0
  66. package/dist/esm/pushed-authorization.js +32 -0
  67. package/dist/esm/service.d.ts +3 -0
  68. package/dist/esm/service.js +11 -41
  69. package/dist/esm/token-cache.d.ts +18 -0
  70. package/dist/esm/token-cache.js +50 -0
  71. package/dist/esm/tokens.d.ts +13 -0
  72. package/dist/esm/tokens.js +16 -0
  73. package/package.json +3 -2
@@ -14,6 +14,10 @@ export type Client = {
14
14
  clientId: string;
15
15
  clientSecret: string | undefined;
16
16
  };
17
+ /** A public client names itself in the body; a confidential one authenticates with Basic. */
18
+ export declare function authenticate(client: Client, form: URLSearchParams): Record<string, string>;
19
+ /** The OAuth error code in a refusal, if it's a plain word; never its description. */
20
+ export declare function oauthError(data: unknown): string | undefined;
17
21
  /** Redeems an authorization code, proving with the PKCE verifier that this app asked for it. */
18
22
  export declare function exchangeCode(http: Http, discovery: Discovery, client: Client, input: {
19
23
  code: string;
@@ -31,6 +35,15 @@ export declare function clientCredentials(http: Http, discovery: Discovery, clie
31
35
  scope: string | undefined;
32
36
  resource: string | undefined;
33
37
  }): Promise<TokenResponse>;
38
+ /**
39
+ * Token exchange (RFC 8693): the access token this API was called with, traded for one meant
40
+ * for another API, for the same person, with this client's own credentials.
41
+ */
42
+ export declare function exchangeAccessToken(http: Http, discovery: Discovery, client: Client, input: {
43
+ subjectToken: string;
44
+ resource: string;
45
+ scope: string | undefined;
46
+ }): Promise<TokenResponse>;
34
47
  /** Revokes a refresh token at sign-out, when the server offers revocation. Never throws. */
35
48
  export declare function revokeRefreshToken(http: Http, discovery: Discovery, client: Client, refreshToken: string): Promise<void>;
36
49
  /** The userinfo endpoint's claims for an access token. */
@@ -63,6 +63,19 @@ function clientCredentials(http, discovery, client, input) {
63
63
  if (input.resource) form.set("resource", input.resource);
64
64
  return tokenRequest(http, discovery, client, form, "service_token_failed");
65
65
  }
66
+ const TOKEN_EXCHANGE_GRANT = "urn:ietf:params:oauth:grant-type:token-exchange";
67
+ const ACCESS_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:access_token";
68
+ function exchangeAccessToken(http, discovery, client, input) {
69
+ const form = new URLSearchParams({
70
+ grant_type: TOKEN_EXCHANGE_GRANT,
71
+ subject_token: input.subjectToken,
72
+ subject_token_type: ACCESS_TOKEN_TYPE,
73
+ requested_token_type: ACCESS_TOKEN_TYPE,
74
+ resource: input.resource
75
+ });
76
+ if (input.scope) form.set("scope", input.scope);
77
+ return tokenRequest(http, discovery, client, form, "token_exchange_failed");
78
+ }
66
79
  async function revokeRefreshToken(http, discovery, client, refreshToken) {
67
80
  if (!discovery.revocation_endpoint) return;
68
81
  const form = new URLSearchParams({ token: refreshToken, token_type_hint: "refresh_token" });
@@ -92,9 +105,12 @@ async function fetchUserInfo(http, discovery, accessToken) {
92
105
  return answer.data;
93
106
  }
94
107
  export {
108
+ authenticate,
95
109
  clientCredentials,
110
+ exchangeAccessToken,
96
111
  exchangeCode,
97
112
  fetchUserInfo,
113
+ oauthError,
98
114
  refreshTokens,
99
115
  revokeRefreshToken
100
116
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nextidp",
3
- "version": "0.1.5",
3
+ "version": "0.4.0",
4
4
  "description": "Sign people in to Next.js, Express, Fastify, Hono and Node apps, and protect NestJS, Express, Fastify, Hono and Next.js APIs, with Next-Identity Server, in one call. Runs on Node and edge runtimes.",
5
5
  "keywords": [
6
6
  "oidc",
@@ -15,7 +15,8 @@
15
15
  "cloudflare-workers",
16
16
  "edge",
17
17
  "jwt",
18
- "idp"
18
+ "idp",
19
+ "mcp"
19
20
  ],
20
21
  "homepage": "https://sajanv88.github.io/next-identity-server/docs/#nextidp",
21
22
  "bugs": "https://github.com/sajanv88/next-identity-server/issues",