@shware/security 7.1.0 → 8.0.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 (212) hide show
  1. package/README.md +108 -30
  2. package/dist/auth/attributes.cjs +5 -5
  3. package/dist/auth/attributes.cjs.map +1 -1
  4. package/dist/auth/attributes.d.cts +3 -5
  5. package/dist/auth/attributes.d.cts.map +1 -1
  6. package/dist/auth/attributes.d.mts +3 -5
  7. package/dist/auth/attributes.d.mts.map +1 -1
  8. package/dist/auth/attributes.mjs +5 -5
  9. package/dist/auth/attributes.mjs.map +1 -1
  10. package/dist/auth/desktop-codes.cjs +57 -0
  11. package/dist/auth/desktop-codes.cjs.map +1 -0
  12. package/dist/auth/desktop-codes.d.cts +24 -0
  13. package/dist/auth/desktop-codes.d.cts.map +1 -0
  14. package/dist/auth/desktop-codes.d.mts +24 -0
  15. package/dist/auth/desktop-codes.d.mts.map +1 -0
  16. package/dist/auth/desktop-codes.mjs +55 -0
  17. package/dist/auth/desktop-codes.mjs.map +1 -0
  18. package/dist/auth/email-codes.cjs +77 -0
  19. package/dist/auth/email-codes.cjs.map +1 -0
  20. package/dist/auth/email-codes.d.cts +39 -0
  21. package/dist/auth/email-codes.d.cts.map +1 -0
  22. package/dist/auth/email-codes.d.mts +39 -0
  23. package/dist/auth/email-codes.d.mts.map +1 -0
  24. package/dist/auth/email-codes.mjs +75 -0
  25. package/dist/auth/email-codes.mjs.map +1 -0
  26. package/dist/auth/error.cjs +47 -0
  27. package/dist/auth/error.cjs.map +1 -0
  28. package/dist/auth/error.d.cts +88 -0
  29. package/dist/auth/error.d.cts.map +1 -0
  30. package/dist/auth/error.d.mts +88 -0
  31. package/dist/auth/error.d.mts.map +1 -0
  32. package/dist/auth/error.mjs +45 -0
  33. package/dist/auth/error.mjs.map +1 -0
  34. package/dist/auth/index.cjs +245 -385
  35. package/dist/auth/index.cjs.map +1 -1
  36. package/dist/auth/index.d.cts +66 -57
  37. package/dist/auth/index.d.cts.map +1 -1
  38. package/dist/auth/index.d.mts +66 -57
  39. package/dist/auth/index.d.mts.map +1 -1
  40. package/dist/auth/index.mjs +248 -388
  41. package/dist/auth/index.mjs.map +1 -1
  42. package/dist/auth/respond.cjs +99 -0
  43. package/dist/auth/respond.cjs.map +1 -0
  44. package/dist/auth/respond.d.cts +39 -0
  45. package/dist/auth/respond.d.cts.map +1 -0
  46. package/dist/auth/respond.d.mts +39 -0
  47. package/dist/auth/respond.d.mts.map +1 -0
  48. package/dist/auth/respond.mjs +92 -0
  49. package/dist/auth/respond.mjs.map +1 -0
  50. package/dist/auth/types.d.cts +27 -13
  51. package/dist/auth/types.d.cts.map +1 -1
  52. package/dist/auth/types.d.mts +27 -13
  53. package/dist/auth/types.d.mts.map +1 -1
  54. package/dist/core/index.cjs +1 -2
  55. package/dist/core/index.d.cts +0 -2
  56. package/dist/core/index.d.cts.map +1 -1
  57. package/dist/core/index.d.mts +0 -2
  58. package/dist/core/index.d.mts.map +1 -1
  59. package/dist/core/index.mjs +1 -2
  60. package/dist/email/schema.cjs +1 -2
  61. package/dist/email/schema.d.cts +0 -2
  62. package/dist/email/schema.d.cts.map +1 -1
  63. package/dist/email/schema.d.mts +0 -2
  64. package/dist/email/schema.d.mts.map +1 -1
  65. package/dist/email/schema.mjs +1 -2
  66. package/dist/index.cjs +5 -0
  67. package/dist/index.d.cts +4 -1
  68. package/dist/index.d.mts +4 -1
  69. package/dist/index.mjs +3 -1
  70. package/dist/oauth2/client.cjs +1 -2
  71. package/dist/oauth2/client.d.cts +0 -2
  72. package/dist/oauth2/client.d.cts.map +1 -1
  73. package/dist/oauth2/client.d.mts +0 -2
  74. package/dist/oauth2/client.d.mts.map +1 -1
  75. package/dist/oauth2/client.mjs +1 -2
  76. package/dist/oauth2/error.cjs +1 -9
  77. package/dist/oauth2/error.cjs.map +1 -1
  78. package/dist/oauth2/error.d.cts +0 -5
  79. package/dist/oauth2/error.d.cts.map +1 -1
  80. package/dist/oauth2/error.d.mts +0 -5
  81. package/dist/oauth2/error.d.mts.map +1 -1
  82. package/dist/oauth2/error.mjs +2 -9
  83. package/dist/oauth2/error.mjs.map +1 -1
  84. package/dist/oauth2/name.cjs +1 -2
  85. package/dist/oauth2/name.d.cts +0 -2
  86. package/dist/oauth2/name.d.cts.map +1 -1
  87. package/dist/oauth2/name.d.mts +0 -2
  88. package/dist/oauth2/name.d.mts.map +1 -1
  89. package/dist/oauth2/name.mjs +1 -2
  90. package/dist/oauth2/provider/apple-client-secret.cjs +1 -2
  91. package/dist/oauth2/provider/apple-client-secret.d.cts +0 -2
  92. package/dist/oauth2/provider/apple-client-secret.d.cts.map +1 -1
  93. package/dist/oauth2/provider/apple-client-secret.d.mts +0 -2
  94. package/dist/oauth2/provider/apple-client-secret.d.mts.map +1 -1
  95. package/dist/oauth2/provider/apple-client-secret.mjs +1 -2
  96. package/dist/oauth2/provider/apple.cjs +1 -2
  97. package/dist/oauth2/provider/apple.d.cts +0 -2
  98. package/dist/oauth2/provider/apple.d.cts.map +1 -1
  99. package/dist/oauth2/provider/apple.d.mts +0 -2
  100. package/dist/oauth2/provider/apple.d.mts.map +1 -1
  101. package/dist/oauth2/provider/apple.mjs +1 -2
  102. package/dist/oauth2/provider/common.cjs +2 -3
  103. package/dist/oauth2/provider/common.cjs.map +1 -1
  104. package/dist/oauth2/provider/common.d.cts +0 -2
  105. package/dist/oauth2/provider/common.d.cts.map +1 -1
  106. package/dist/oauth2/provider/common.d.mts +0 -2
  107. package/dist/oauth2/provider/common.d.mts.map +1 -1
  108. package/dist/oauth2/provider/common.mjs +2 -3
  109. package/dist/oauth2/provider/common.mjs.map +1 -1
  110. package/dist/oauth2/provider/facebook.cjs +3 -6
  111. package/dist/oauth2/provider/facebook.cjs.map +1 -1
  112. package/dist/oauth2/provider/facebook.d.cts +0 -3
  113. package/dist/oauth2/provider/facebook.d.cts.map +1 -1
  114. package/dist/oauth2/provider/facebook.d.mts +0 -3
  115. package/dist/oauth2/provider/facebook.d.mts.map +1 -1
  116. package/dist/oauth2/provider/facebook.mjs +3 -6
  117. package/dist/oauth2/provider/facebook.mjs.map +1 -1
  118. package/dist/oauth2/provider/github.cjs +1 -2
  119. package/dist/oauth2/provider/github.d.cts +0 -2
  120. package/dist/oauth2/provider/github.d.cts.map +1 -1
  121. package/dist/oauth2/provider/github.d.mts +0 -2
  122. package/dist/oauth2/provider/github.d.mts.map +1 -1
  123. package/dist/oauth2/provider/github.mjs +1 -2
  124. package/dist/oauth2/provider/google.cjs +1 -2
  125. package/dist/oauth2/provider/google.d.cts +0 -2
  126. package/dist/oauth2/provider/google.d.cts.map +1 -1
  127. package/dist/oauth2/provider/google.d.mts +0 -2
  128. package/dist/oauth2/provider/google.d.mts.map +1 -1
  129. package/dist/oauth2/provider/google.mjs +1 -2
  130. package/dist/oauth2/provider/wechat.cjs +1 -2
  131. package/dist/oauth2/provider/wechat.d.cts +0 -2
  132. package/dist/oauth2/provider/wechat.d.cts.map +1 -1
  133. package/dist/oauth2/provider/wechat.d.mts +0 -2
  134. package/dist/oauth2/provider/wechat.d.mts.map +1 -1
  135. package/dist/oauth2/provider/wechat.mjs +1 -2
  136. package/dist/oauth2/provider/x.cjs +7 -6
  137. package/dist/oauth2/provider/x.cjs.map +1 -1
  138. package/dist/oauth2/provider/x.d.cts +3 -4
  139. package/dist/oauth2/provider/x.d.cts.map +1 -1
  140. package/dist/oauth2/provider/x.d.mts +3 -4
  141. package/dist/oauth2/provider/x.d.mts.map +1 -1
  142. package/dist/oauth2/provider/x.mjs +7 -6
  143. package/dist/oauth2/provider/x.mjs.map +1 -1
  144. package/dist/oauth2/types.cjs +1 -2
  145. package/dist/oauth2/types.cjs.map +1 -1
  146. package/dist/oauth2/types.d.cts +5 -2
  147. package/dist/oauth2/types.d.cts.map +1 -1
  148. package/dist/oauth2/types.d.mts +5 -2
  149. package/dist/oauth2/types.d.mts.map +1 -1
  150. package/dist/oauth2/types.mjs +1 -2
  151. package/dist/oauth2/types.mjs.map +1 -1
  152. package/dist/session/common.cjs +11 -15
  153. package/dist/session/common.cjs.map +1 -1
  154. package/dist/session/common.d.cts +7 -5
  155. package/dist/session/common.d.cts.map +1 -1
  156. package/dist/session/common.d.mts +7 -5
  157. package/dist/session/common.d.mts.map +1 -1
  158. package/dist/session/common.mjs +11 -14
  159. package/dist/session/common.mjs.map +1 -1
  160. package/dist/session/db.cjs +3 -4
  161. package/dist/session/db.cjs.map +1 -1
  162. package/dist/session/db.d.cts +0 -2
  163. package/dist/session/db.d.cts.map +1 -1
  164. package/dist/session/db.d.mts +0 -2
  165. package/dist/session/db.d.mts.map +1 -1
  166. package/dist/session/db.mjs +4 -5
  167. package/dist/session/db.mjs.map +1 -1
  168. package/dist/session/map-session.cjs +1 -2
  169. package/dist/session/map-session.d.cts +0 -2
  170. package/dist/session/map-session.d.cts.map +1 -1
  171. package/dist/session/map-session.d.mts +0 -2
  172. package/dist/session/map-session.d.mts.map +1 -1
  173. package/dist/session/map-session.mjs +1 -2
  174. package/dist/session/redis.cjs +7 -10
  175. package/dist/session/redis.cjs.map +1 -1
  176. package/dist/session/redis.d.cts +0 -2
  177. package/dist/session/redis.d.cts.map +1 -1
  178. package/dist/session/redis.d.mts +0 -2
  179. package/dist/session/redis.d.mts.map +1 -1
  180. package/dist/session/redis.mjs +8 -11
  181. package/dist/session/redis.mjs.map +1 -1
  182. package/dist/session/types.d.cts +0 -14
  183. package/dist/session/types.d.cts.map +1 -1
  184. package/dist/session/types.d.mts +0 -14
  185. package/dist/session/types.d.mts.map +1 -1
  186. package/dist/utils/http.cjs +1 -2
  187. package/dist/utils/http.d.cts +0 -2
  188. package/dist/utils/http.d.cts.map +1 -1
  189. package/dist/utils/http.d.mts +0 -2
  190. package/dist/utils/http.d.mts.map +1 -1
  191. package/dist/utils/http.mjs +1 -2
  192. package/dist/utils/oauth2.cjs +1 -2
  193. package/dist/utils/oauth2.d.cts +0 -2
  194. package/dist/utils/oauth2.d.cts.map +1 -1
  195. package/dist/utils/oauth2.d.mts +0 -2
  196. package/dist/utils/oauth2.d.mts.map +1 -1
  197. package/dist/utils/oauth2.mjs +1 -2
  198. package/dist/utils/timing.cjs +1 -2
  199. package/dist/utils/timing.d.cts +0 -2
  200. package/dist/utils/timing.d.cts.map +1 -1
  201. package/dist/utils/timing.d.mts +0 -2
  202. package/dist/utils/timing.d.mts.map +1 -1
  203. package/dist/utils/timing.mjs +1 -2
  204. package/dist/utils/valid.cjs +35 -54
  205. package/dist/utils/valid.cjs.map +1 -1
  206. package/dist/utils/valid.d.cts +8 -25
  207. package/dist/utils/valid.d.cts.map +1 -1
  208. package/dist/utils/valid.d.mts +8 -25
  209. package/dist/utils/valid.d.mts.map +1 -1
  210. package/dist/utils/valid.mjs +33 -52
  211. package/dist/utils/valid.mjs.map +1 -1
  212. package/package.json +4 -4
@@ -1,7 +1,7 @@
1
1
  import { OAuth2Error } from "../error.mjs";
2
2
  import { createAuthorizationUri, exchangeAuthorizationCode } from "./common.mjs";
3
3
  import { invariant } from "@shware/utils";
4
- //#region src/oauth2/provider/github.ts
4
+ // src/oauth2/provider/github.ts
5
5
  /**
6
6
  * GitHub's REST API rejects any request without a `User-Agent` header with a 403. Node's fetch sends
7
7
  * a default one, but Cloudflare Workers' fetch sends none, so every GitHub request sets it explicitly.
@@ -81,7 +81,6 @@ function createGithubProvider() {
81
81
  };
82
82
  }
83
83
  const github = createGithubProvider();
84
- //#endregion
85
84
  export { createGithubProvider, github };
86
85
 
87
86
  //# sourceMappingURL=github.mjs.map
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_oauth2_error = require("../error.cjs");
3
3
  const require_oauth2_provider_common = require("./common.cjs");
4
4
  let _shware_utils = require("@shware/utils");
5
- //#region src/oauth2/provider/google.ts
5
+ // src/oauth2/provider/google.ts
6
6
  /** Google signs id tokens with either `iss`, the URL or the bare host. */
7
7
  const GOOGLE_ISSUERS = ["https://accounts.google.com", "accounts.google.com"];
8
8
  function claims(data) {
@@ -109,7 +109,6 @@ function createGoogleProvider() {
109
109
  };
110
110
  }
111
111
  const google = createGoogleProvider();
112
- //#endregion
113
112
  exports.createGoogleProvider = createGoogleProvider;
114
113
  exports.google = google;
115
114
 
@@ -1,5 +1,4 @@
1
1
  import { NativeCredential, OAuth2Token, OneTapProvider } from "../types.cjs";
2
- //#region src/oauth2/provider/google.d.ts
3
2
  export declare function createGoogleProvider(): OneTapProvider;
4
3
  export declare const google: OneTapProvider;
5
4
  export interface GoogleUserInfo {
@@ -39,5 +38,4 @@ export interface GoogleErrorResponse {
39
38
  error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_token' | 'invalid_scope' | 'unauthorized_client' | 'unsupported_grant_type' | 'access_denied' | 'server_error';
40
39
  error_description: string;
41
40
  }
42
- //#endregion
43
41
  //# sourceMappingURL=google.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.cts","names":[],"sources":["../../../src/oauth2/provider/google.ts"],"mappings":";;wBA0BgB,wBAAwB;qBAyF3B,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA;;iBAIe,4BAA4B;EAC3C;EACA;EACA;EACA;;iBAGe;EACf;EAUA"}
1
+ {"version":3,"file":"google.d.cts","names":[],"sources":["../../../src/oauth2/provider/google.ts"],"mappings":";wBA0BgB,wBAAwB;qBAyF3B,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA;;iBAIe,4BAA4B;EAC3C;EACA;EACA;EACA;;iBAGe;EACf;EAUA"}
@@ -1,5 +1,4 @@
1
1
  import { NativeCredential, OAuth2Token, OneTapProvider } from "../types.mjs";
2
- //#region src/oauth2/provider/google.d.ts
3
2
  export declare function createGoogleProvider(): OneTapProvider;
4
3
  export declare const google: OneTapProvider;
5
4
  export interface GoogleUserInfo {
@@ -39,5 +38,4 @@ export interface GoogleErrorResponse {
39
38
  error: 'invalid_request' | 'invalid_client' | 'invalid_grant' | 'invalid_token' | 'invalid_scope' | 'unauthorized_client' | 'unsupported_grant_type' | 'access_denied' | 'server_error';
40
39
  error_description: string;
41
40
  }
42
- //#endregion
43
41
  //# sourceMappingURL=google.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.mts","names":[],"sources":["../../../src/oauth2/provider/google.ts"],"mappings":";;wBA0BgB,wBAAwB;qBAyF3B,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA;;iBAIe,4BAA4B;EAC3C;EACA;EACA;EACA;;iBAGe;EACf;EAUA"}
1
+ {"version":3,"file":"google.d.mts","names":[],"sources":["../../../src/oauth2/provider/google.ts"],"mappings":";wBA0BgB,wBAAwB;qBAyF3B,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA;;iBAIe,4BAA4B;EAC3C;EACA;EACA;EACA;;iBAGe;EACf;EAUA"}
@@ -1,7 +1,7 @@
1
1
  import { OAuth2Error } from "../error.mjs";
2
2
  import { createAuthorizationUri, exchangeAuthorizationCode, verifyIdToken } from "./common.mjs";
3
3
  import { invariant } from "@shware/utils";
4
- //#region src/oauth2/provider/google.ts
4
+ // src/oauth2/provider/google.ts
5
5
  /** Google signs id tokens with either `iss`, the URL or the bare host. */
6
6
  const GOOGLE_ISSUERS = ["https://accounts.google.com", "accounts.google.com"];
7
7
  function claims(data) {
@@ -108,7 +108,6 @@ function createGoogleProvider() {
108
108
  };
109
109
  }
110
110
  const google = createGoogleProvider();
111
- //#endregion
112
111
  export { createGoogleProvider, google };
113
112
 
114
113
  //# sourceMappingURL=google.mjs.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_oauth2_error = require("../error.cjs");
3
3
  let _shware_utils = require("@shware/utils");
4
- //#region src/oauth2/provider/wechat.ts
4
+ // src/oauth2/provider/wechat.ts
5
5
  /**
6
6
  * WeChat error codes mapped to the closest OAuth2 error. Anything not listed is a `server_error`.
7
7
  * reference: https://developers.weixin.qq.com/doc/oplatform/Return_codes/Return_code_descriptions_new.html
@@ -127,7 +127,6 @@ function createWechatProvider(options = { isWechatBrowser: false }) {
127
127
  };
128
128
  }
129
129
  const wechat = createWechatProvider();
130
- //#endregion
131
130
  exports.createWechatProvider = createWechatProvider;
132
131
  exports.wechat = wechat;
133
132
 
@@ -1,5 +1,4 @@
1
1
  import { OAuth2Token, Provider } from "../types.cjs";
2
- //#region src/oauth2/provider/wechat.d.ts
3
2
  export type Options = {
4
3
  isWechatBrowser: boolean;
5
4
  };
@@ -34,5 +33,4 @@ export interface WechatToken extends OAuth2Token {
34
33
  scope: string;
35
34
  unionid?: string;
36
35
  }
37
- //#endregion
38
36
  //# sourceMappingURL=wechat.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wechat.d.cts","names":[],"sources":["../../../src/oauth2/provider/wechat.ts"],"mappings":";;YAkDY;EAAY;;;;;wBAKR,qBAAqB,UAAS,UAAuC;qBA2DxE,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;EAQA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"wechat.d.cts","names":[],"sources":["../../../src/oauth2/provider/wechat.ts"],"mappings":";YAkDY;EAAY;;;;;wBAKR,qBAAqB,UAAS,UAAuC;qBA2DxE,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;EAQA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA"}
@@ -1,5 +1,4 @@
1
1
  import { OAuth2Token, Provider } from "../types.mjs";
2
- //#region src/oauth2/provider/wechat.d.ts
3
2
  export type Options = {
4
3
  isWechatBrowser: boolean;
5
4
  };
@@ -34,5 +33,4 @@ export interface WechatToken extends OAuth2Token {
34
33
  scope: string;
35
34
  unionid?: string;
36
35
  }
37
- //#endregion
38
36
  //# sourceMappingURL=wechat.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wechat.d.mts","names":[],"sources":["../../../src/oauth2/provider/wechat.ts"],"mappings":";;YAkDY;EAAY;;;;;wBAKR,qBAAqB,UAAS,UAAuC;qBA2DxE,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;EAQA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"wechat.d.mts","names":[],"sources":["../../../src/oauth2/provider/wechat.ts"],"mappings":";YAkDY;EAAY;;;;;wBAKR,qBAAqB,UAAS,UAAuC;qBA2DxE,QAAM;iBAEF;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;;EAQA;EACA;EACA;;iBAGe,oBAAoB;EACnC;EACA;EACA;EACA;EACA;EACA"}
@@ -1,6 +1,6 @@
1
1
  import { OAuth2Error } from "../error.mjs";
2
2
  import { invariant } from "@shware/utils";
3
- //#region src/oauth2/provider/wechat.ts
3
+ // src/oauth2/provider/wechat.ts
4
4
  /**
5
5
  * WeChat error codes mapped to the closest OAuth2 error. Anything not listed is a `server_error`.
6
6
  * reference: https://developers.weixin.qq.com/doc/oplatform/Return_codes/Return_code_descriptions_new.html
@@ -126,7 +126,6 @@ function createWechatProvider(options = { isWechatBrowser: false }) {
126
126
  };
127
127
  }
128
128
  const wechat = createWechatProvider();
129
- //#endregion
130
129
  export { createWechatProvider, wechat };
131
130
 
132
131
  //# sourceMappingURL=wechat.mjs.map
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_oauth2_error = require("../error.cjs");
3
3
  const require_oauth2_provider_common = require("./common.cjs");
4
4
  let _shware_utils = require("@shware/utils");
5
- //#region src/oauth2/provider/x.ts
5
+ // src/oauth2/provider/x.ts
6
6
  const defaultUserFields = [
7
7
  "id",
8
8
  "name",
@@ -10,7 +10,8 @@ const defaultUserFields = [
10
10
  "url",
11
11
  "username",
12
12
  "location",
13
- "verified"
13
+ "verified",
14
+ "confirmed_email"
14
15
  ];
15
16
  function createXProvider(options) {
16
17
  return {
@@ -22,6 +23,7 @@ function createXProvider(options) {
22
23
  defaultScope: [
23
24
  "users.read",
24
25
  "tweet.read",
26
+ "users.email",
25
27
  "offline.access"
26
28
  ],
27
29
  createAuthorizationUri(params) {
@@ -55,7 +57,7 @@ function createXProvider(options) {
55
57
  };
56
58
  const url = new URL(this.userInfoUri);
57
59
  userFields.forEach((field) => url.searchParams.append("user.fields", field));
58
- const response = await fetch(this.userInfoUri, { headers });
60
+ const response = await fetch(url, { headers });
59
61
  if (!response.ok) {
60
62
  const { errors } = await response.json();
61
63
  throw new require_oauth2_error.OAuth2Error(response.status, "invalid_request", `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`);
@@ -67,8 +69,8 @@ function createXProvider(options) {
67
69
  sub: profile.data.id,
68
70
  name: profile.data.name,
69
71
  picture: profile.data.profile_image_url,
70
- email: profile.data.email,
71
- email_verified: profile.data.verified ?? false,
72
+ email: profile.data.confirmed_email,
73
+ email_verified: profile.data.confirmed_email ? true : void 0,
72
74
  preferred_username: profile.data.username,
73
75
  profile: `https://x.com/${profile.data.username}`,
74
76
  website: profile.data.url
@@ -99,7 +101,6 @@ function createXProvider(options) {
99
101
  };
100
102
  }
101
103
  const x = createXProvider();
102
- //#endregion
103
104
  exports.createXProvider = createXProvider;
104
105
  exports.x = x;
105
106
 
@@ -1 +1 @@
1
- {"version":3,"file":"x.cjs","names":["createAuthorizationUri","exchangeAuthorizationCode","OAuth2Error","refreshAccessToken","revokeToken"],"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { OAuth2Token, Provider } from '../types';\nimport {\n createAuthorizationUri,\n exchangeAuthorizationCode,\n refreshAccessToken,\n revokeToken,\n} from './common';\n\nexport interface XOptions {\n userFields?: UserField[];\n}\n\nconst defaultUserFields = [\n 'id',\n 'name',\n 'profile_image_url',\n 'url',\n 'username',\n 'location',\n 'verified',\n];\n\nexport function createXProvider(options?: XOptions): Provider {\n return {\n authorizationUri: 'https://x.com/i/oauth2/authorize',\n tokenUri: 'https://api.x.com/2/oauth2/token',\n tokenRefreshUri: 'https://api.x.com/2/oauth2/token',\n tokenRevokeUri: 'https://api.x.com/2/oauth2/revoke',\n // https://docs.x.com/x-api/users/user-lookup-me\n userInfoUri: 'https://api.x.com/2/users/me',\n defaultScope: ['users.read', 'tweet.read', 'offline.access'],\n createAuthorizationUri(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n const response = await exchangeAuthorizationCode({\n ...params,\n tokenUri: this.tokenUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n\n const userFields = options?.userFields ?? defaultUserFields;\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n\n const url = new URL(this.userInfoUri);\n userFields.forEach((field) => url.searchParams.append('user.fields', field));\n\n const response = await fetch(this.userInfoUri, { headers });\n if (!response.ok) {\n const { errors } = (await response.json()) as XAPIErrorResponse;\n throw new OAuth2Error(\n response.status,\n 'invalid_request',\n `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`\n );\n }\n const profile = (await response.json()) as XUserInfo;\n return {\n data: profile,\n claims: {\n sub: profile.data.id,\n name: profile.data.name,\n picture: profile.data.profile_image_url,\n email: profile.data.email,\n email_verified: profile.data.verified ?? false,\n preferred_username: profile.data.username,\n profile: `https://x.com/${profile.data.username}`,\n website: profile.data.url,\n },\n };\n },\n async refreshAccessToken(params) {\n invariant(this.tokenRefreshUri, 'tokenRefreshUri is required');\n const response = await refreshAccessToken({\n ...params,\n tokenUri: this.tokenRefreshUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async revokeToken(params) {\n invariant(this.tokenRevokeUri, 'tokenRevokeUri is required');\n return revokeToken({\n ...params,\n tokenRevokeUri: this.tokenRevokeUri,\n authentication: 'basic',\n });\n },\n };\n}\n\nexport const x = createXProvider();\n\ntype UserField =\n | 'affiliation'\n | 'connection_status'\n | 'created_at'\n | 'description'\n | 'entities'\n | 'id'\n | 'is_identity_verified'\n | 'location'\n | 'most_recent_tweet_id'\n | 'name'\n | 'parody'\n | 'pinned_tweet_id'\n | 'profile_banner_url'\n | 'profile_image_url'\n | 'protected'\n | 'public_metrics'\n | 'receives_your_dm'\n | 'subscription'\n | 'subscription_type'\n | 'url'\n | 'username'\n | 'verified'\n | 'verified_followers_count'\n | 'verified_type'\n | 'withheld';\n\nexport interface XUser {\n id: string;\n name: string;\n email?: string;\n username: string;\n location?: string;\n entities?: {\n url: { urls: UrlEntity[] };\n description: {\n hashtags: HashtagEntity[];\n cashtags: HashtagEntity[];\n mentions: MentionEntity[];\n };\n };\n verified?: boolean;\n description?: string;\n url?: string;\n profile_image_url?: string;\n protected?: boolean;\n pinned_tweet_id?: string;\n created_at?: string;\n}\n\nexport interface XUserInfo {\n data: XUser;\n includes?: { tweets?: { id: string; text: string }[]; users?: XUser[] };\n}\n\ntype UrlEntity = {\n start: number;\n end: number;\n url: string;\n display_url: string;\n expanded_url: string;\n};\ntype HashtagEntity = { start: number; end: number; tag: string };\ntype MentionEntity = { start: number; end: string; username: string };\n\nexport interface XToken extends OAuth2Token {\n token_type: string;\n expires_in: number;\n access_token: string;\n scope: string;\n refresh_token: string;\n}\n\ntype XErrorResponse = { error: string; error_description: string };\ntype XAPIErrorResponse = {\n errors: { title: string; type: string; detail?: string; status?: number }[];\n};\n"],"mappings":";;;;;AAcA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,gBAAgB,SAA8B;CAC5D,OAAO;EACL,kBAAkB;EAClB,UAAU;EACV,iBAAiB;EACjB,gBAAgB;EAEhB,aAAa;EACb,cAAc;GAAC;GAAc;GAAc;EAAgB;EAC3D,uBAAuB,QAAQ;GAC7B,IAAI,CAAC,OAAO,MAAM,MAAM,IAAI,MAAM,wBAAwB;GAC1D,OAAOA,+BAAAA,uBAAuB;IAC5B,GAAG;IACH,OAAO,OAAO,SAAS,KAAK;IAC5B,kBAAkB,KAAK;GACzB,CAAC;EACH;EACA,MAAM,0BAA0B,QAAQ;GACtC,IAAI,CAAC,OAAO,MAAM,MAAM,IAAI,MAAM,wBAAwB;GAC1D,MAAM,WAAW,MAAMC,+BAAAA,0BAA0B;IAC/C,GAAG;IACH,UAAU,KAAK;IACf,gBAAgB;GAClB,CAAC;GACD,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,OAAO,sBAAuB,MAAM,SAAS,KAAK;IAC1D,MAAM,IAAIC,qBAAAA,YAAY,SAAS,QAAQ,OAAO,iBAAiB;GACjE;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,EAAE,gBAAgB;GAClC,CAAA,GAAA,cAAA,UAAA,CAAU,cAAc,0BAA0B;GAClD,CAAA,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A,CAAU,KAAK,gBAAgB,4BAA4B;GAC3D,OAAOE,+BAAAA,YAAY;IACjB,GAAG;IACH,gBAAgB,KAAK;IACrB,gBAAgB;GAClB,CAAC;EACH;CACF;AACF;AAEA,MAAa,IAAI,gBAAgB"}
1
+ {"version":3,"file":"x.cjs","names":["createAuthorizationUri","exchangeAuthorizationCode","OAuth2Error","refreshAccessToken","revokeToken"],"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { OAuth2Token, Provider } from '../types';\nimport {\n createAuthorizationUri,\n exchangeAuthorizationCode,\n refreshAccessToken,\n revokeToken,\n} from './common';\n\nexport interface XOptions {\n userFields?: UserField[];\n}\n\n// `confirmed_email` is the address X has confirmed; it needs the `users.email` scope and\n// \"Request email from users\" enabled on the app in the developer console, else it is absent.\nconst defaultUserFields: UserField[] = [\n 'id',\n 'name',\n 'profile_image_url',\n 'url',\n 'username',\n 'location',\n 'verified',\n 'confirmed_email',\n];\n\nexport function createXProvider(options?: XOptions): Provider {\n return {\n authorizationUri: 'https://x.com/i/oauth2/authorize',\n tokenUri: 'https://api.x.com/2/oauth2/token',\n tokenRefreshUri: 'https://api.x.com/2/oauth2/token',\n tokenRevokeUri: 'https://api.x.com/2/oauth2/revoke',\n // https://docs.x.com/x-api/users/user-lookup-me\n userInfoUri: 'https://api.x.com/2/users/me',\n defaultScope: ['users.read', 'tweet.read', 'users.email', 'offline.access'],\n createAuthorizationUri(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n const response = await exchangeAuthorizationCode({\n ...params,\n tokenUri: this.tokenUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n\n const userFields = options?.userFields ?? defaultUserFields;\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n\n const url = new URL(this.userInfoUri);\n userFields.forEach((field) => url.searchParams.append('user.fields', field));\n\n const response = await fetch(url, { headers });\n if (!response.ok) {\n const { errors } = (await response.json()) as XAPIErrorResponse;\n throw new OAuth2Error(\n response.status,\n 'invalid_request',\n `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`\n );\n }\n const profile = (await response.json()) as XUserInfo;\n return {\n data: profile,\n claims: {\n sub: profile.data.id,\n name: profile.data.name,\n picture: profile.data.profile_image_url,\n // X returns only an address it has confirmed, as `confirmed_email`; `verified` /\n // `verified_type` are the blue check and say nothing about the email.\n email: profile.data.confirmed_email,\n email_verified: profile.data.confirmed_email ? true : undefined,\n preferred_username: profile.data.username,\n profile: `https://x.com/${profile.data.username}`,\n website: profile.data.url,\n },\n };\n },\n async refreshAccessToken(params) {\n invariant(this.tokenRefreshUri, 'tokenRefreshUri is required');\n const response = await refreshAccessToken({\n ...params,\n tokenUri: this.tokenRefreshUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async revokeToken(params) {\n invariant(this.tokenRevokeUri, 'tokenRevokeUri is required');\n return revokeToken({\n ...params,\n tokenRevokeUri: this.tokenRevokeUri,\n authentication: 'basic',\n });\n },\n };\n}\n\nexport const x = createXProvider();\n\ntype UserField =\n | 'affiliation'\n | 'confirmed_email'\n | 'connection_status'\n | 'created_at'\n | 'description'\n | 'entities'\n | 'id'\n | 'is_identity_verified'\n | 'location'\n | 'most_recent_tweet_id'\n | 'name'\n | 'parody'\n | 'pinned_tweet_id'\n | 'profile_banner_url'\n | 'profile_image_url'\n | 'protected'\n | 'public_metrics'\n | 'receives_your_dm'\n | 'subscription'\n | 'subscription_type'\n | 'url'\n | 'username'\n | 'verified'\n | 'verified_followers_count'\n | 'verified_type'\n | 'withheld';\n\nexport interface XUser {\n id: string;\n name: string;\n /** The address X has confirmed; only with the `users.email` scope and `confirmed_email` requested. */\n confirmed_email?: string;\n username: string;\n location?: string;\n entities?: {\n url: { urls: UrlEntity[] };\n description: {\n hashtags: HashtagEntity[];\n cashtags: HashtagEntity[];\n mentions: MentionEntity[];\n };\n };\n verified?: boolean;\n description?: string;\n url?: string;\n profile_image_url?: string;\n protected?: boolean;\n pinned_tweet_id?: string;\n created_at?: string;\n}\n\nexport interface XUserInfo {\n data: XUser;\n includes?: { tweets?: { id: string; text: string }[]; users?: XUser[] };\n}\n\ntype UrlEntity = {\n start: number;\n end: number;\n url: string;\n display_url: string;\n expanded_url: string;\n};\ntype HashtagEntity = { start: number; end: number; tag: string };\ntype MentionEntity = { start: number; end: string; username: string };\n\nexport interface XToken extends OAuth2Token {\n token_type: string;\n expires_in: number;\n access_token: string;\n scope: string;\n refresh_token: string;\n}\n\ntype XErrorResponse = { error: string; error_description: string };\ntype XAPIErrorResponse = {\n errors: { title: string; type: string; detail?: string; status?: number }[];\n};\n"],"mappings":";;;;;AAgBA,MAAM,oBAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,gBAAgB,SAA8B;CAC5D,OAAO;EACL,kBAAkB;EAClB,UAAU;EACV,iBAAiB;EACjB,gBAAgB;EAEhB,aAAa;EACb,cAAc;GAAC;GAAc;GAAc;GAAe;EAAgB;EAC1E,uBAAuB,QAAQ;GAC7B,IAAI,CAAC,OAAO,MAAM,MAAM,IAAI,MAAM,wBAAwB;GAC1D,OAAOA,+BAAAA,uBAAuB;IAC5B,GAAG;IACH,OAAO,OAAO,SAAS,KAAK;IAC5B,kBAAkB,KAAK;GACzB,CAAC;EACH;EACA,MAAM,0BAA0B,QAAQ;GACtC,I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;IACxB;GACF;EACF;EACA,MAAM,mBAAmB,QAAQ;GAC/B,CAAA,GAAA,cAAA,UAAA,CAAU,KAAK,iBAAiB,6BAA6B;GAC7D,MAAM,WAAW,MAAMC,+BAAAA,mBAAmB;IACxC,GAAG;IACH,UAAU,KAAK;IACf,gBAAgB;GAClB,CAAC;GACD,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,OAAO,sBAAuB,MAAM,SAAS,KAAK;IAC1D,MAAM,IAAID,qBAAAA,YAAY,SAAS,QAAQ,OAAO,iBAAiB;GACjE;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,QAAQ;GACxB,CAAA,GAAA,cAAA,UAAA,CAAU,KAAK,gBAAgB,4BAA4B;GAC3D,OAAOE,+BAAAA,YAAY;IACjB,GAAG;IACH,gBAAgB,KAAK;IACrB,gBAAgB;GAClB,CAAC;EACH;CACF;AACF;AAEA,MAAa,IAAI,gBAAgB"}
@@ -1,15 +1,15 @@
1
1
  import { OAuth2Token, Provider } from "../types.cjs";
2
- //#region src/oauth2/provider/x.d.ts
3
2
  export interface XOptions {
4
3
  userFields?: UserField[];
5
4
  }
6
5
  export declare function createXProvider(options?: XOptions): Provider;
7
6
  export declare const x: Provider;
8
- type UserField = 'affiliation' | 'connection_status' | 'created_at' | 'description' | 'entities' | 'id' | 'is_identity_verified' | 'location' | 'most_recent_tweet_id' | 'name' | 'parody' | 'pinned_tweet_id' | 'profile_banner_url' | 'profile_image_url' | 'protected' | 'public_metrics' | 'receives_your_dm' | 'subscription' | 'subscription_type' | 'url' | 'username' | 'verified' | 'verified_followers_count' | 'verified_type' | 'withheld';
7
+ type UserField = 'affiliation' | 'confirmed_email' | 'connection_status' | 'created_at' | 'description' | 'entities' | 'id' | 'is_identity_verified' | 'location' | 'most_recent_tweet_id' | 'name' | 'parody' | 'pinned_tweet_id' | 'profile_banner_url' | 'profile_image_url' | 'protected' | 'public_metrics' | 'receives_your_dm' | 'subscription' | 'subscription_type' | 'url' | 'username' | 'verified' | 'verified_followers_count' | 'verified_type' | 'withheld';
9
8
  export interface XUser {
10
9
  id: string;
11
10
  name: string;
12
- email?: string;
11
+ /** The address X has confirmed; only with the `users.email` scope and `confirmed_email` requested. */
12
+ confirmed_email?: string;
13
13
  username: string;
14
14
  location?: string;
15
15
  entities?: {
@@ -64,6 +64,5 @@ export interface XToken extends OAuth2Token {
64
64
  scope: string;
65
65
  refresh_token: string;
66
66
  }
67
- //#endregion
68
67
  export {};
69
68
  //# sourceMappingURL=x.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"x.d.cts","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"mappings":";;iBAUiB;EACf,aAAa;;wBAaC,gBAAgB,UAAU,WAAW;qBAwFxC,GAAC;KAET;iBA2BY;EACf;EACA;EACA;EACA;EACA;EACA;IACE;MAAO,MAAM;;IACb;MACE,UAAU;MACV,UAAU;MACV,UAAU;;;EAGd;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf,MAAM;EACN;IAAa;MAAW;MAAY;;IAAkB,QAAQ;;;KAG3D;EACH;EACA;EACA;EACA;EACA;;KAEG;EAAkB;EAAe;EAAa;;KAC9C;EAAkB;EAAe;EAAa;;iBAElC,eAAe;EAC9B;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"x.d.cts","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"mappings":";iBAUiB;EACf,aAAa;;wBAgBC,gBAAgB,UAAU,WAAW;qBA0FxC,GAAC;KAET;iBA4BY;EACf;EACA;;EAEA;EACA;EACA;EACA;IACE;MAAO,MAAM;;IACb;MACE,UAAU;MACV,UAAU;MACV,UAAU;;;EAGd;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf,MAAM;EACN;IAAa;MAAW;MAAY;;IAAkB,QAAQ;;;KAG3D;EACH;EACA;EACA;EACA;EACA;;KAEG;EAAkB;EAAe;EAAa;;KAC9C;EAAkB;EAAe;EAAa;;iBAElC,eAAe;EAC9B;EACA;EACA;EACA;EACA"}
@@ -1,15 +1,15 @@
1
1
  import { OAuth2Token, Provider } from "../types.mjs";
2
- //#region src/oauth2/provider/x.d.ts
3
2
  export interface XOptions {
4
3
  userFields?: UserField[];
5
4
  }
6
5
  export declare function createXProvider(options?: XOptions): Provider;
7
6
  export declare const x: Provider;
8
- type UserField = 'affiliation' | 'connection_status' | 'created_at' | 'description' | 'entities' | 'id' | 'is_identity_verified' | 'location' | 'most_recent_tweet_id' | 'name' | 'parody' | 'pinned_tweet_id' | 'profile_banner_url' | 'profile_image_url' | 'protected' | 'public_metrics' | 'receives_your_dm' | 'subscription' | 'subscription_type' | 'url' | 'username' | 'verified' | 'verified_followers_count' | 'verified_type' | 'withheld';
7
+ type UserField = 'affiliation' | 'confirmed_email' | 'connection_status' | 'created_at' | 'description' | 'entities' | 'id' | 'is_identity_verified' | 'location' | 'most_recent_tweet_id' | 'name' | 'parody' | 'pinned_tweet_id' | 'profile_banner_url' | 'profile_image_url' | 'protected' | 'public_metrics' | 'receives_your_dm' | 'subscription' | 'subscription_type' | 'url' | 'username' | 'verified' | 'verified_followers_count' | 'verified_type' | 'withheld';
9
8
  export interface XUser {
10
9
  id: string;
11
10
  name: string;
12
- email?: string;
11
+ /** The address X has confirmed; only with the `users.email` scope and `confirmed_email` requested. */
12
+ confirmed_email?: string;
13
13
  username: string;
14
14
  location?: string;
15
15
  entities?: {
@@ -64,6 +64,5 @@ export interface XToken extends OAuth2Token {
64
64
  scope: string;
65
65
  refresh_token: string;
66
66
  }
67
- //#endregion
68
67
  export {};
69
68
  //# sourceMappingURL=x.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"x.d.mts","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"mappings":";;iBAUiB;EACf,aAAa;;wBAaC,gBAAgB,UAAU,WAAW;qBAwFxC,GAAC;KAET;iBA2BY;EACf;EACA;EACA;EACA;EACA;EACA;IACE;MAAO,MAAM;;IACb;MACE,UAAU;MACV,UAAU;MACV,UAAU;;;EAGd;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf,MAAM;EACN;IAAa;MAAW;MAAY;;IAAkB,QAAQ;;;KAG3D;EACH;EACA;EACA;EACA;EACA;;KAEG;EAAkB;EAAe;EAAa;;KAC9C;EAAkB;EAAe;EAAa;;iBAElC,eAAe;EAC9B;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"x.d.mts","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"mappings":";iBAUiB;EACf,aAAa;;wBAgBC,gBAAgB,UAAU,WAAW;qBA0FxC,GAAC;KAET;iBA4BY;EACf;EACA;;EAEA;EACA;EACA;EACA;IACE;MAAO,MAAM;;IACb;MACE,UAAU;MACV,UAAU;MACV,UAAU;;;EAGd;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf,MAAM;EACN;IAAa;MAAW;MAAY;;IAAkB,QAAQ;;;KAG3D;EACH;EACA;EACA;EACA;EACA;;KAEG;EAAkB;EAAe;EAAa;;KAC9C;EAAkB;EAAe;EAAa;;iBAElC,eAAe;EAC9B;EACA;EACA;EACA;EACA"}
@@ -1,7 +1,7 @@
1
1
  import { OAuth2Error } from "../error.mjs";
2
2
  import { createAuthorizationUri, exchangeAuthorizationCode, refreshAccessToken, revokeToken } from "./common.mjs";
3
3
  import { invariant } from "@shware/utils";
4
- //#region src/oauth2/provider/x.ts
4
+ // src/oauth2/provider/x.ts
5
5
  const defaultUserFields = [
6
6
  "id",
7
7
  "name",
@@ -9,7 +9,8 @@ const defaultUserFields = [
9
9
  "url",
10
10
  "username",
11
11
  "location",
12
- "verified"
12
+ "verified",
13
+ "confirmed_email"
13
14
  ];
14
15
  function createXProvider(options) {
15
16
  return {
@@ -21,6 +22,7 @@ function createXProvider(options) {
21
22
  defaultScope: [
22
23
  "users.read",
23
24
  "tweet.read",
25
+ "users.email",
24
26
  "offline.access"
25
27
  ],
26
28
  createAuthorizationUri(params) {
@@ -54,7 +56,7 @@ function createXProvider(options) {
54
56
  };
55
57
  const url = new URL(this.userInfoUri);
56
58
  userFields.forEach((field) => url.searchParams.append("user.fields", field));
57
- const response = await fetch(this.userInfoUri, { headers });
59
+ const response = await fetch(url, { headers });
58
60
  if (!response.ok) {
59
61
  const { errors } = await response.json();
60
62
  throw new OAuth2Error(response.status, "invalid_request", `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`);
@@ -66,8 +68,8 @@ function createXProvider(options) {
66
68
  sub: profile.data.id,
67
69
  name: profile.data.name,
68
70
  picture: profile.data.profile_image_url,
69
- email: profile.data.email,
70
- email_verified: profile.data.verified ?? false,
71
+ email: profile.data.confirmed_email,
72
+ email_verified: profile.data.confirmed_email ? true : void 0,
71
73
  preferred_username: profile.data.username,
72
74
  profile: `https://x.com/${profile.data.username}`,
73
75
  website: profile.data.url
@@ -98,7 +100,6 @@ function createXProvider(options) {
98
100
  };
99
101
  }
100
102
  const x = createXProvider();
101
- //#endregion
102
103
  export { createXProvider, x };
103
104
 
104
105
  //# sourceMappingURL=x.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"x.mjs","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { OAuth2Token, Provider } from '../types';\nimport {\n createAuthorizationUri,\n exchangeAuthorizationCode,\n refreshAccessToken,\n revokeToken,\n} from './common';\n\nexport interface XOptions {\n userFields?: UserField[];\n}\n\nconst defaultUserFields = [\n 'id',\n 'name',\n 'profile_image_url',\n 'url',\n 'username',\n 'location',\n 'verified',\n];\n\nexport function createXProvider(options?: XOptions): Provider {\n return {\n authorizationUri: 'https://x.com/i/oauth2/authorize',\n tokenUri: 'https://api.x.com/2/oauth2/token',\n tokenRefreshUri: 'https://api.x.com/2/oauth2/token',\n tokenRevokeUri: 'https://api.x.com/2/oauth2/revoke',\n // https://docs.x.com/x-api/users/user-lookup-me\n userInfoUri: 'https://api.x.com/2/users/me',\n defaultScope: ['users.read', 'tweet.read', 'offline.access'],\n createAuthorizationUri(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n const response = await exchangeAuthorizationCode({\n ...params,\n tokenUri: this.tokenUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n\n const userFields = options?.userFields ?? defaultUserFields;\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n\n const url = new URL(this.userInfoUri);\n userFields.forEach((field) => url.searchParams.append('user.fields', field));\n\n const response = await fetch(this.userInfoUri, { headers });\n if (!response.ok) {\n const { errors } = (await response.json()) as XAPIErrorResponse;\n throw new OAuth2Error(\n response.status,\n 'invalid_request',\n `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`\n );\n }\n const profile = (await response.json()) as XUserInfo;\n return {\n data: profile,\n claims: {\n sub: profile.data.id,\n name: profile.data.name,\n picture: profile.data.profile_image_url,\n email: profile.data.email,\n email_verified: profile.data.verified ?? false,\n preferred_username: profile.data.username,\n profile: `https://x.com/${profile.data.username}`,\n website: profile.data.url,\n },\n };\n },\n async refreshAccessToken(params) {\n invariant(this.tokenRefreshUri, 'tokenRefreshUri is required');\n const response = await refreshAccessToken({\n ...params,\n tokenUri: this.tokenRefreshUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async revokeToken(params) {\n invariant(this.tokenRevokeUri, 'tokenRevokeUri is required');\n return revokeToken({\n ...params,\n tokenRevokeUri: this.tokenRevokeUri,\n authentication: 'basic',\n });\n },\n };\n}\n\nexport const x = createXProvider();\n\ntype UserField =\n | 'affiliation'\n | 'connection_status'\n | 'created_at'\n | 'description'\n | 'entities'\n | 'id'\n | 'is_identity_verified'\n | 'location'\n | 'most_recent_tweet_id'\n | 'name'\n | 'parody'\n | 'pinned_tweet_id'\n | 'profile_banner_url'\n | 'profile_image_url'\n | 'protected'\n | 'public_metrics'\n | 'receives_your_dm'\n | 'subscription'\n | 'subscription_type'\n | 'url'\n | 'username'\n | 'verified'\n | 'verified_followers_count'\n | 'verified_type'\n | 'withheld';\n\nexport interface XUser {\n id: string;\n name: string;\n email?: string;\n username: string;\n location?: string;\n entities?: {\n url: { urls: UrlEntity[] };\n description: {\n hashtags: HashtagEntity[];\n cashtags: HashtagEntity[];\n mentions: MentionEntity[];\n };\n };\n verified?: boolean;\n description?: string;\n url?: string;\n profile_image_url?: string;\n protected?: boolean;\n pinned_tweet_id?: string;\n created_at?: string;\n}\n\nexport interface XUserInfo {\n data: XUser;\n includes?: { tweets?: { id: string; text: string }[]; users?: XUser[] };\n}\n\ntype UrlEntity = {\n start: number;\n end: number;\n url: string;\n display_url: string;\n expanded_url: string;\n};\ntype HashtagEntity = { start: number; end: number; tag: string };\ntype MentionEntity = { start: number; end: string; username: string };\n\nexport interface XToken extends OAuth2Token {\n token_type: string;\n expires_in: number;\n access_token: string;\n scope: string;\n refresh_token: string;\n}\n\ntype XErrorResponse = { error: string; error_description: string };\ntype XAPIErrorResponse = {\n errors: { title: string; type: string; detail?: string; status?: number }[];\n};\n"],"mappings":";;;;AAcA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAgB,gBAAgB,SAA8B;CAC5D,OAAO;EACL,kBAAkB;EAClB,UAAU;EACV,iBAAiB;EACjB,gBAAgB;EAEhB,aAAa;EACb,cAAc;GAAC;GAAc;GAAc;EAAgB;EAC3D,uBAAuB,QAAQ;GAC7B,I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,KAAK,YAAY;KACzC,oBAAoB,QAAQ,KAAK;KACjC,SAAS,iBAAiB,QAAQ,KAAK;KACvC,SAAS,QAAQ,KAAK;IACxB;GACF;EACF;EACA,MAAM,mBAAmB,QAAQ;GAC/B,UAAU,KAAK,iBAAiB,6BAA6B;GAC7D,MAAM,WAAW,MAAM,mBAAmB;IACxC,GAAG;IACH,UAAU,KAAK;IACf,gBAAgB;GAClB,CAAC;GACD,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,OAAO,sBAAuB,MAAM,SAAS,KAAK;IAC1D,MAAM,IAAI,YAAY,SAAS,QAAQ,OAAO,iBAAiB;GACjE;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,QAAQ;GACxB,UAAU,KAAK,gBAAgB,4BAA4B;GAC3D,OAAO,YAAY;IACjB,GAAG;IACH,gBAAgB,KAAK;IACrB,gBAAgB;GAClB,CAAC;EACH;CACF;AACF;AAEA,MAAa,IAAI,gBAAgB"}
1
+ {"version":3,"file":"x.mjs","names":[],"sources":["../../../src/oauth2/provider/x.ts"],"sourcesContent":["import { invariant } from '@shware/utils';\nimport { OAuth2Error } from '../error';\nimport type { OAuth2Token, Provider } from '../types';\nimport {\n createAuthorizationUri,\n exchangeAuthorizationCode,\n refreshAccessToken,\n revokeToken,\n} from './common';\n\nexport interface XOptions {\n userFields?: UserField[];\n}\n\n// `confirmed_email` is the address X has confirmed; it needs the `users.email` scope and\n// \"Request email from users\" enabled on the app in the developer console, else it is absent.\nconst defaultUserFields: UserField[] = [\n 'id',\n 'name',\n 'profile_image_url',\n 'url',\n 'username',\n 'location',\n 'verified',\n 'confirmed_email',\n];\n\nexport function createXProvider(options?: XOptions): Provider {\n return {\n authorizationUri: 'https://x.com/i/oauth2/authorize',\n tokenUri: 'https://api.x.com/2/oauth2/token',\n tokenRefreshUri: 'https://api.x.com/2/oauth2/token',\n tokenRevokeUri: 'https://api.x.com/2/oauth2/revoke',\n // https://docs.x.com/x-api/users/user-lookup-me\n userInfoUri: 'https://api.x.com/2/users/me',\n defaultScope: ['users.read', 'tweet.read', 'users.email', 'offline.access'],\n createAuthorizationUri(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n return createAuthorizationUri({\n ...params,\n scope: params.scope ?? this.defaultScope,\n authorizationUri: this.authorizationUri,\n });\n },\n async exchangeAuthorizationCode(params) {\n if (!params.pkce) throw new Error('pkce is required for x');\n const response = await exchangeAuthorizationCode({\n ...params,\n tokenUri: this.tokenUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async getUserInfo({ access_token }) {\n invariant(access_token, 'access_token is required');\n invariant(this.userInfoUri, 'userInfoUri is required');\n\n const userFields = options?.userFields ?? defaultUserFields;\n const headers = { Accept: 'application/json', Authorization: `Bearer ${access_token}` };\n\n const url = new URL(this.userInfoUri);\n userFields.forEach((field) => url.searchParams.append('user.fields', field));\n\n const response = await fetch(url, { headers });\n if (!response.ok) {\n const { errors } = (await response.json()) as XAPIErrorResponse;\n throw new OAuth2Error(\n response.status,\n 'invalid_request',\n `Failed to fetch user info: ${errors.at(0)?.detail ?? errors.at(0)?.title}`\n );\n }\n const profile = (await response.json()) as XUserInfo;\n return {\n data: profile,\n claims: {\n sub: profile.data.id,\n name: profile.data.name,\n picture: profile.data.profile_image_url,\n // X returns only an address it has confirmed, as `confirmed_email`; `verified` /\n // `verified_type` are the blue check and say nothing about the email.\n email: profile.data.confirmed_email,\n email_verified: profile.data.confirmed_email ? true : undefined,\n preferred_username: profile.data.username,\n profile: `https://x.com/${profile.data.username}`,\n website: profile.data.url,\n },\n };\n },\n async refreshAccessToken(params) {\n invariant(this.tokenRefreshUri, 'tokenRefreshUri is required');\n const response = await refreshAccessToken({\n ...params,\n tokenUri: this.tokenRefreshUri,\n authentication: 'basic',\n });\n if (!response.ok) {\n const { error, error_description } = (await response.json()) as XErrorResponse;\n throw new OAuth2Error(response.status, error, error_description);\n }\n return (await response.json()) as XToken;\n },\n async revokeToken(params) {\n invariant(this.tokenRevokeUri, 'tokenRevokeUri is required');\n return revokeToken({\n ...params,\n tokenRevokeUri: this.tokenRevokeUri,\n authentication: 'basic',\n });\n },\n };\n}\n\nexport const x = createXProvider();\n\ntype UserField =\n | 'affiliation'\n | 'confirmed_email'\n | 'connection_status'\n | 'created_at'\n | 'description'\n | 'entities'\n | 'id'\n | 'is_identity_verified'\n | 'location'\n | 'most_recent_tweet_id'\n | 'name'\n | 'parody'\n | 'pinned_tweet_id'\n | 'profile_banner_url'\n | 'profile_image_url'\n | 'protected'\n | 'public_metrics'\n | 'receives_your_dm'\n | 'subscription'\n | 'subscription_type'\n | 'url'\n | 'username'\n | 'verified'\n | 'verified_followers_count'\n | 'verified_type'\n | 'withheld';\n\nexport interface XUser {\n id: string;\n name: string;\n /** The address X has confirmed; only with the `users.email` scope and `confirmed_email` requested. */\n confirmed_email?: string;\n username: string;\n location?: string;\n entities?: {\n url: { urls: UrlEntity[] };\n description: {\n hashtags: HashtagEntity[];\n cashtags: HashtagEntity[];\n mentions: MentionEntity[];\n };\n };\n verified?: boolean;\n description?: string;\n url?: string;\n profile_image_url?: string;\n protected?: boolean;\n pinned_tweet_id?: string;\n created_at?: string;\n}\n\nexport interface XUserInfo {\n data: XUser;\n includes?: { tweets?: { id: string; text: string }[]; users?: XUser[] };\n}\n\ntype UrlEntity = {\n start: number;\n end: number;\n url: string;\n display_url: string;\n expanded_url: string;\n};\ntype HashtagEntity = { start: number; end: number; tag: string };\ntype MentionEntity = { start: number; end: string; username: string };\n\nexport interface XToken extends OAuth2Token {\n token_type: string;\n expires_in: number;\n access_token: string;\n scope: string;\n refresh_token: string;\n}\n\ntype XErrorResponse = { error: string; error_description: string };\ntype XAPIErrorResponse = {\n errors: { title: string; type: string; detail?: string; status?: number }[];\n};\n"],"mappings":";;;;AAgBA,MAAM,oBAAiC;CACrC;CACA;CACA;CAC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,OACtE;GACF;GACA,MAAM,UAAW,MAAM,SAAS,KAAK;GACrC,OAAO;IACL,MAAM;IACN,QAAQ;KACN,KAAK,QAAQ,KAAK;KAClB,MAAM,QAAQ,KAAK;KACnB,SAAS,QAAQ,KAAK;KAGtB,OAAO,QAAQ,KAAK;KACpB,gBAAgB,QAAQ,KAAK,kBAAkB,OAAO,KAAA;KACtD,oBAAoB,QAAQ,KAAK;KACjC,SAAS,iBAAiB,QAAQ,KAAK;KACvC,SAAS,QAAQ,KAAK;IACxB;GACF;EACF;EACA,MAAM,mBAAmB,QAAQ;GAC/B,UAAU,KAAK,iBAAiB,6BAA6B;GAC7D,MAAM,WAAW,MAAM,mBAAmB;IACxC,GAAG;IACH,UAAU,KAAK;IACf,gBAAgB;GAClB,CAAC;GACD,IAAI,CAAC,SAAS,IAAI;IAChB,MAAM,EAAE,OAAO,sBAAuB,MAAM,SAAS,KAAK;IAC1D,MAAM,IAAI,YAAY,SAAS,QAAQ,OAAO,iBAAiB;GACjE;GACA,OAAQ,MAAM,SAAS,KAAK;EAC9B;EACA,MAAM,YAAY,QAAQ;GACxB,UAAU,KAAK,gBAAgB,4BAA4B;GAC3D,OAAO,YAAY;IACjB,GAAG;IACH,gBAAgB,KAAK;IACrB,gBAAgB;GAClB,CAAC;EACH;CACF;AACF;AAEA,MAAa,IAAI,gBAAgB"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/oauth2/types.ts
2
+ // src/oauth2/types.ts
3
3
  const OIDC_SCOPES = [
4
4
  "openid",
5
5
  "profile",
@@ -8,7 +8,6 @@ const OIDC_SCOPES = [
8
8
  "address",
9
9
  "offline_access"
10
10
  ];
11
- //#endregion
12
11
  exports.OIDC_SCOPES = OIDC_SCOPES;
13
12
 
14
13
  //# sourceMappingURL=types.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","names":[],"sources":["../../src/oauth2/types.ts"],"sourcesContent":["// reference: https://datatracker.ietf.org/doc/html/rfc7636\nexport interface PkceParameters {\n code_verifier: string;\n code_challenge: string;\n code_challenge_method: 'S256' | 'plain';\n}\n\nexport interface OAuth2AuthorizationRequest {\n state: string;\n /** Key of the provider in `OAuth2ClientConfig.providers` the flow was started for. */\n provider: string;\n authorizationRequestUri: string;\n additionalParameters: PkceParameters;\n /**\n * What the host attached when the flow started (`oauth2Authorization` options), kept on the\n * server and handed back to `onAuthorized` once the callback checks out. Never sent to the\n * provider, unlike `additionalParameters`. Absent on requests stored before this field existed.\n */\n attributes?: Record<string, string>;\n}\n\ninterface CreateAuthorizationUriParams {\n state: string;\n clientId: string;\n redirectUri: string;\n scope: string[] | undefined;\n pkce?: Omit<PkceParameters, 'code_verifier'>;\n}\n\nexport interface ExchangeCodeParams {\n code: string;\n clientId: string;\n /** Absent for public clients (Google's installed-app clients, PKCE-only clients). */\n clientSecret?: string;\n redirectUri: string;\n pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;\n}\n\nexport interface RefreshTokenParams {\n clientId: string;\n clientSecret?: string;\n refreshToken: string;\n}\n\nexport interface RevokeTokenParams {\n token: string;\n clientId: string;\n clientSecret?: string;\n}\n\nexport interface LoginOAuth2NativeParams {\n /**\n * The configured client the app signs in as (its `client_id`, or the provider's default native\n * client). Id tokens must be issued to it: it is the only audience accepted.\n */\n clientId: string;\n clientSecret?: string;\n redirectUri: string;\n /**\n * The PKCE verifier for the code exchange, taken from `credentials.code_verifier`: the app made\n * the challenge and keeps the verifier, so the server only ever has the verifier. Providers\n * whose token endpoint takes `code_verifier` send it; the others ignore it.\n */\n pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;\n /** What the app posted, without `code_verifier`, which arrives as `pkce`. */\n credentials: NativeCredential;\n}\n\n// reference: https://datatracker.ietf.org/doc/html/rfc6749#section-5.1\nexport interface OAuth2Token {\n /**\n * REQUIRED.\n * The access token issued by the authorization server.\n */\n access_token: string;\n\n /**\n * REQUIRED.\n * The type of the token issued as described in Section 7.1. Value is case insensitive.\n */\n token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});\n\n /**\n * RECOMMENDED.\n * The lifetime in seconds of the access token. For example, the value \"3600\" denotes that the\n * access token will expire in one hour from the time the response was generated. If omitted, the\n * authorization server SHOULD provide the expiration time via other means or document the default\n * value.\n */\n expires_in?: number;\n\n /**\n * OPTIONAL.\n * The refresh token, which can be used to obtain new access tokens using the same authorization\n * grant as described in Section 6.\n */\n refresh_token?: string;\n\n /**\n * OPTIONAL.\n * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the\n * access token as described by Section 3.3.\n */\n scope?: string;\n\n id_token?: string;\n\n [key: string]: unknown;\n}\n\nexport interface OidcToken extends OAuth2Token {\n id_token: string;\n}\n\nexport type NativeCredential = {\n state?: string;\n code?: string;\n client_id?: string;\n redirect_uri?: string;\n /**\n * The PKCE verifier (RFC 7636) for `code`, when the app sent a `code_challenge` with the\n * authorization request: 43-128 characters from `[A-Za-z0-9-._~]`. Sent on to the provider's\n * token endpoint, which refuses the code unless the verifier matches its challenge, so a code\n * intercepted on the redirect (a custom-scheme redirect any app can claim) is useless alone.\n * RFC 8252 §8.1 requires it for native apps, whose installed-app clients have no secret.\n */\n code_verifier?: string;\n id_token?: string;\n access_token?: string;\n /**\n * The user's name as the platform hands it to the app, for providers whose id token carries none\n * (Apple sends it on the first authorization only): iOS\n * `ASAuthorizationAppleIDCredential.fullName`, expo-apple-authentication's `credential.fullName`.\n * The snake_case fields above are OAuth / OIDC protocol parameters; this one is not, it is the\n * platform's object passed through unchanged, so it keeps the platform's own name and apps send\n * `fullName: credential.fullName` as is. Unsigned client input: the provider cleans each part and\n * ignores anything that is not a string. Parts with a standard claim become `given_name`,\n * `family_name`, `middle_name` and `nickname`; `namePrefix` / `nameSuffix` have none and are kept\n * in `userInfo.data.fullName` only.\n */\n fullName?: PersonNameComponents;\n};\n\n/** iOS `PersonNameComponents` as JSON; every part may be missing or `null`. */\nexport interface PersonNameComponents {\n givenName?: string | null;\n familyName?: string | null;\n middleName?: string | null;\n namePrefix?: string | null;\n nameSuffix?: string | null;\n nickname?: string | null;\n}\n\n/**\n * Fields of the authorization response besides `code` and `state` that a provider uses to fill in\n * the user info: Apple posts the user's name as `user` (JSON) with the first authorization only,\n * since its id token never carries one. Unsigned, so treated as untrusted input.\n */\nexport interface AuthorizationResponse {\n user?: string;\n}\n\nexport const OIDC_SCOPES = [\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'offline_access',\n] as const;\n\nexport type OidcScope = (typeof OIDC_SCOPES)[number];\n\n// https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims\nexport interface StandardClaims {\n sub: string;\n name?: string;\n given_name?: string;\n family_name?: string;\n middle_name?: string;\n nickname?: string;\n preferred_username?: string;\n profile?: string;\n picture?: string;\n website?: string;\n email?: string;\n email_verified?: boolean;\n gender?: 'female' | 'male' | (string & {});\n birthdate?: string; // ISO 8601-1 [ISO8601‑1] YYYY-MM-DD format.\n zoneinfo?: string; // IANA Time Zone Database [IANA.time‑zones]\n locale?: string; // BCP47 [RFC5646] language tag.\n phone_number?: string; // E.164\n phone_number_verified?: boolean;\n address?: {\n formatted: string;\n street_address: string;\n locality: string;\n region: string;\n postal_code: string;\n country: string;\n }; // [RFC8259] JSON object\n updated_at?: number;\n}\n\nexport interface UserInfo<T = unknown> {\n claims: StandardClaims;\n data: T;\n}\n\nexport interface Provider {\n /** Authorization URI for the provider. */\n authorizationUri: string;\n\n /** Token URI for the provider. */\n tokenUri: string;\n\n /** Token revoke URI for the provider. */\n tokenRevokeUri?: string;\n\n /** Token refresh URI for the provider. */\n tokenRefreshUri?: string;\n\n /** User info URI for the provider. */\n userInfoUri?: string;\n\n /** User info authentication method for the provider. */\n userInfoAuthenticationMethod?: string;\n\n /**\n * Name of the attribute that will be used to extract the username from the call to 'userInfoUri'.\n * */\n userNameAttribute?: string;\n\n /** JWK set URI for the provider */\n jwkSetUri?: string;\n\n /**\n * URI that can either be an OpenID Connect discovery endpoint or an OAuth 2.0 Authorization\n * Server Metadata endpoint defined by RFC 8414.\n * */\n issuerUri?: string;\n\n /** Default scopes for the provider. */\n defaultScope: string[];\n\n /** step 1: generate authorization uri and redirect user to it */\n createAuthorizationUri: (params: CreateAuthorizationUriParams) => URL;\n\n /** step 2: exchange code for token */\n exchangeAuthorizationCode: (params: ExchangeCodeParams) => Promise<OAuth2Token>;\n\n /**\n * step 3: get user info. `context.clientId` is the client the token was issued to, the only\n * audience an id token may carry; `context.response` holds what the authorization response\n * carried besides the code, for the providers that send user data there (Apple).\n */\n getUserInfo: (token: OAuth2Token, context: UserInfoContext) => Promise<UserInfo>;\n\n /** others: refresh access token */\n refreshAccessToken?: (params: RefreshTokenParams) => Promise<OAuth2Token>;\n\n /** others: revoke token */\n revokeToken?: (params: RevokeTokenParams) => Promise<void>;\n\n loginOAuth2Native?: (\n params: LoginOAuth2NativeParams\n ) => Promise<{ token: OAuth2Token; userInfo: UserInfo }>;\n}\n\nexport interface UserInfoContext {\n clientId: string;\n response?: AuthorizationResponse;\n}\n\nexport interface OneTapProvider extends Provider {\n /** Verifies a One Tap / FedCM credential, which must be issued to `clientId` (the web client). */\n getTokenInfo: (\n id_token: string,\n clientId: string\n ) => Promise<{ token: OAuth2Token; userInfo: UserInfo }>;\n}\n\n/**\n * A client secret: a fixed string, or a function minting one for the client id it is called with\n * (Sign in with Apple's signed JWT, see `createAppleClientSecret`), called on every use so it can\n * cache and renew on its own.\n */\nexport type ClientSecret = string | ((clientId: string) => string | Promise<string>);\n\n/** The client a provider's server-side flows sign in as: the redirect flow and Google One Tap. */\nexport interface WebClient {\n clientId: string;\n /** Absent for a public client. */\n clientSecret?: ClientSecret;\n /** Default: `${baseUri}/login/oauth2/code/<provider key>`. */\n redirectUri?: string;\n /** Authorization scopes. Default: the provider's `defaultScope`. */\n scope?: string[];\n}\n\n/**\n * A client an app signs in as on the device (an iOS bundle id, a Google iOS / Android client) and\n * whose code or id token it posts to the native login route.\n */\nexport interface NativeClient {\n clientId: string;\n /** Absent for a public client (Google's installed-app clients have none). */\n clientSecret?: ClientSecret;\n /**\n * Redirect URI sent with the code exchange when the app sends no `redirect_uri` of its own.\n * Default: `${baseUri}/login/oauth2/code/<provider key>`.\n */\n redirectUri?: string;\n}\n\n/**\n * One identity source: every user it signs in has a `sub` unique within it, whichever client they\n * came through. The key in `OAuth2ClientConfig.providers` names it in the routes and in\n * `onAuthorized`. Two keys may share an implementation (two Google Cloud projects, one Okta per\n * tenant) when their subjects are separate namespaces.\n */\nexport interface ProviderConfig {\n /** The implementation: `apple`, `google`, `github`, ... from `@shware/security/oauth2/provider`. */\n provider: Provider;\n /** The redirect flow's and One Tap's client. Required by those flows. */\n web?: WebClient;\n /**\n * Clients the native login accepts besides `web`. An app names its client with `client_id`;\n * without one, the only native client is used, or `web` when there is none.\n */\n native?: NativeClient[];\n}\n\nexport type ProvidersConfig = { [key: string]: ProviderConfig | undefined };\n\nexport interface OAuth2ClientConfig {\n baseUri: string;\n errorUri: string;\n successUri: string;\n /** Providers by key; a function is called per request, for secrets read at request time. */\n providers: ProvidersConfig | (() => Promise<ProvidersConfig>);\n}\n"],"mappings":";;AAkKA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../../src/oauth2/types.ts"],"sourcesContent":["// reference: https://datatracker.ietf.org/doc/html/rfc7636\nexport interface PkceParameters {\n code_verifier: string;\n code_challenge: string;\n code_challenge_method: 'S256' | 'plain';\n}\n\nexport interface OAuth2AuthorizationRequest {\n state: string;\n /** Key of the provider in `OAuth2ClientConfig.providers` the flow was started for. */\n provider: string;\n authorizationRequestUri: string;\n additionalParameters: PkceParameters;\n /**\n * What the host attached when the flow started (`oauth2Authorization` options), kept on the\n * server and handed back to `onAuthorized` once the callback checks out. Never sent to the\n * provider, unlike `additionalParameters`. Absent on requests stored before this field existed.\n */\n attributes?: Record<string, string>;\n}\n\ninterface CreateAuthorizationUriParams {\n state: string;\n clientId: string;\n redirectUri: string;\n scope: string[] | undefined;\n pkce?: Omit<PkceParameters, 'code_verifier'>;\n}\n\nexport interface ExchangeCodeParams {\n code: string;\n clientId: string;\n /** Absent for public clients (Google's installed-app clients, PKCE-only clients). */\n clientSecret?: string;\n redirectUri: string;\n pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;\n}\n\nexport interface RefreshTokenParams {\n clientId: string;\n clientSecret?: string;\n refreshToken: string;\n}\n\nexport interface RevokeTokenParams {\n token: string;\n clientId: string;\n clientSecret?: string;\n}\n\nexport interface LoginOAuth2NativeParams {\n /**\n * The configured client the app signs in as (its `client_id`, or the provider's default native\n * client). Id tokens must be issued to it: it is the only audience accepted.\n */\n clientId: string;\n clientSecret?: string;\n redirectUri: string;\n /**\n * The PKCE verifier for the code exchange, taken from `credentials.code_verifier`: the app made\n * the challenge and keeps the verifier, so the server only ever has the verifier. Providers\n * whose token endpoint takes `code_verifier` send it; the others ignore it.\n */\n pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;\n /** What the app posted, without `code_verifier`, which arrives as `pkce`. */\n credentials: NativeCredential;\n}\n\n// reference: https://datatracker.ietf.org/doc/html/rfc6749#section-5.1\nexport interface OAuth2Token {\n /**\n * REQUIRED.\n * The access token issued by the authorization server.\n */\n access_token: string;\n\n /**\n * REQUIRED.\n * The type of the token issued as described in Section 7.1. Value is case insensitive.\n */\n token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});\n\n /**\n * RECOMMENDED.\n * The lifetime in seconds of the access token. For example, the value \"3600\" denotes that the\n * access token will expire in one hour from the time the response was generated. If omitted, the\n * authorization server SHOULD provide the expiration time via other means or document the default\n * value.\n */\n expires_in?: number;\n\n /**\n * OPTIONAL.\n * The refresh token, which can be used to obtain new access tokens using the same authorization\n * grant as described in Section 6.\n */\n refresh_token?: string;\n\n /**\n * OPTIONAL.\n * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the\n * access token as described by Section 3.3.\n */\n scope?: string;\n\n id_token?: string;\n\n [key: string]: unknown;\n}\n\nexport interface OidcToken extends OAuth2Token {\n id_token: string;\n}\n\nexport type NativeCredential = {\n state?: string;\n code?: string;\n client_id?: string;\n redirect_uri?: string;\n /**\n * The PKCE verifier (RFC 7636) for `code`, when the app sent a `code_challenge` with the\n * authorization request: 43-128 characters from `[A-Za-z0-9-._~]`. Sent on to the provider's\n * token endpoint, which refuses the code unless the verifier matches its challenge, so a code\n * intercepted on the redirect (a custom-scheme redirect any app can claim) is useless alone.\n * RFC 8252 §8.1 requires it for native apps, whose installed-app clients have no secret.\n */\n code_verifier?: string;\n id_token?: string;\n access_token?: string;\n /**\n * The user's name as the platform hands it to the app, for providers whose id token carries none\n * (Apple sends it on the first authorization only): iOS\n * `ASAuthorizationAppleIDCredential.fullName`, expo-apple-authentication's `credential.fullName`.\n * The snake_case fields above are OAuth / OIDC protocol parameters; this one is not, it is the\n * platform's object passed through unchanged, so it keeps the platform's own name and apps send\n * `fullName: credential.fullName` as is. Unsigned client input: the provider cleans each part and\n * ignores anything that is not a string. Parts with a standard claim become `given_name`,\n * `family_name`, `middle_name` and `nickname`; `namePrefix` / `nameSuffix` have none and are kept\n * in `userInfo.data.fullName` only.\n */\n fullName?: PersonNameComponents;\n};\n\n/** iOS `PersonNameComponents` as JSON; every part may be missing or `null`. */\nexport interface PersonNameComponents {\n givenName?: string | null;\n familyName?: string | null;\n middleName?: string | null;\n namePrefix?: string | null;\n nameSuffix?: string | null;\n nickname?: string | null;\n}\n\n/**\n * Fields of the authorization response besides `code` and `state` that a provider uses to fill in\n * the user info: Apple posts the user's name as `user` (JSON) with the first authorization only,\n * since its id token never carries one. Unsigned, so treated as untrusted input.\n */\nexport interface AuthorizationResponse {\n user?: string;\n}\n\nexport const OIDC_SCOPES = [\n 'openid',\n 'profile',\n 'email',\n 'phone',\n 'address',\n 'offline_access',\n] as const;\n\nexport type OidcScope = (typeof OIDC_SCOPES)[number];\n\n// https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims\nexport interface StandardClaims {\n sub: string;\n name?: string;\n given_name?: string;\n family_name?: string;\n middle_name?: string;\n nickname?: string;\n preferred_username?: string;\n profile?: string;\n picture?: string;\n website?: string;\n email?: string;\n /**\n * Set only by providers that state it (Google, Apple, GitHub from the primary address's\n * `verified` flag, X when it returns `confirmed_email`); Facebook leaves it unset. Trust the\n * address only when this is `true`.\n */\n email_verified?: boolean;\n gender?: 'female' | 'male' | (string & {});\n birthdate?: string; // ISO 8601-1 [ISO8601‑1] YYYY-MM-DD format.\n zoneinfo?: string; // IANA Time Zone Database [IANA.time‑zones]\n locale?: string; // BCP47 [RFC5646] language tag.\n phone_number?: string; // E.164\n phone_number_verified?: boolean;\n address?: {\n formatted: string;\n street_address: string;\n locality: string;\n region: string;\n postal_code: string;\n country: string;\n }; // [RFC8259] JSON object\n updated_at?: number;\n}\n\nexport interface UserInfo<T = unknown> {\n claims: StandardClaims;\n data: T;\n}\n\nexport interface Provider {\n /** Authorization URI for the provider. */\n authorizationUri: string;\n\n /** Token URI for the provider. */\n tokenUri: string;\n\n /** Token revoke URI for the provider. */\n tokenRevokeUri?: string;\n\n /** Token refresh URI for the provider. */\n tokenRefreshUri?: string;\n\n /** User info URI for the provider. */\n userInfoUri?: string;\n\n /** User info authentication method for the provider. */\n userInfoAuthenticationMethod?: string;\n\n /**\n * Name of the attribute that will be used to extract the username from the call to 'userInfoUri'.\n * */\n userNameAttribute?: string;\n\n /** JWK set URI for the provider */\n jwkSetUri?: string;\n\n /**\n * URI that can either be an OpenID Connect discovery endpoint or an OAuth 2.0 Authorization\n * Server Metadata endpoint defined by RFC 8414.\n * */\n issuerUri?: string;\n\n /** Default scopes for the provider. */\n defaultScope: string[];\n\n /** step 1: generate authorization uri and redirect user to it */\n createAuthorizationUri: (params: CreateAuthorizationUriParams) => URL;\n\n /** step 2: exchange code for token */\n exchangeAuthorizationCode: (params: ExchangeCodeParams) => Promise<OAuth2Token>;\n\n /**\n * step 3: get user info. `context.clientId` is the client the token was issued to, the only\n * audience an id token may carry; `context.response` holds what the authorization response\n * carried besides the code, for the providers that send user data there (Apple).\n */\n getUserInfo: (token: OAuth2Token, context: UserInfoContext) => Promise<UserInfo>;\n\n /** others: refresh access token */\n refreshAccessToken?: (params: RefreshTokenParams) => Promise<OAuth2Token>;\n\n /** others: revoke token */\n revokeToken?: (params: RevokeTokenParams) => Promise<void>;\n\n loginOAuth2Native?: (\n params: LoginOAuth2NativeParams\n ) => Promise<{ token: OAuth2Token; userInfo: UserInfo }>;\n}\n\nexport interface UserInfoContext {\n clientId: string;\n response?: AuthorizationResponse;\n}\n\nexport interface OneTapProvider extends Provider {\n /** Verifies a One Tap / FedCM credential, which must be issued to `clientId` (the web client). */\n getTokenInfo: (\n id_token: string,\n clientId: string\n ) => Promise<{ token: OAuth2Token; userInfo: UserInfo }>;\n}\n\n/**\n * A client secret: a fixed string, or a function minting one for the client id it is called with\n * (Sign in with Apple's signed JWT, see `createAppleClientSecret`), called on every use so it can\n * cache and renew on its own.\n */\nexport type ClientSecret = string | ((clientId: string) => string | Promise<string>);\n\n/** The client a provider's server-side flows sign in as: the redirect flow and Google One Tap. */\nexport interface WebClient {\n clientId: string;\n /** Absent for a public client. */\n clientSecret?: ClientSecret;\n /** Default: `${baseUri}/login/oauth2/code/<provider key>`. */\n redirectUri?: string;\n /** Authorization scopes. Default: the provider's `defaultScope`. */\n scope?: string[];\n}\n\n/**\n * A client an app signs in as on the device (an iOS bundle id, a Google iOS / Android client) and\n * whose code or id token it posts to the native login route.\n */\nexport interface NativeClient {\n clientId: string;\n /** Absent for a public client (Google's installed-app clients have none). */\n clientSecret?: ClientSecret;\n /**\n * Redirect URI sent with the code exchange when the app sends no `redirect_uri` of its own.\n * Default: `${baseUri}/login/oauth2/code/<provider key>`.\n */\n redirectUri?: string;\n}\n\n/**\n * One identity source: every user it signs in has a `sub` unique within it, whichever client they\n * came through. The key in `OAuth2ClientConfig.providers` names it in the routes and in\n * `onAuthorized`. Two keys may share an implementation (two Google Cloud projects, one Okta per\n * tenant) when their subjects are separate namespaces.\n */\nexport interface ProviderConfig {\n /** The implementation: `apple`, `google`, `github`, ... from `@shware/security/oauth2/provider`. */\n provider: Provider;\n /** The redirect flow's and One Tap's client. Required by those flows. */\n web?: WebClient;\n /**\n * Clients the native login accepts besides `web`. An app names its client with `client_id`;\n * without one, the only native client is used, or `web` when there is none.\n */\n native?: NativeClient[];\n}\n\nexport type ProvidersConfig = { [key: string]: ProviderConfig | undefined };\n\nexport interface OAuth2ClientConfig {\n baseUri: string;\n errorUri: string;\n successUri: string;\n /** Providers by key; a function is called per request, for secrets read at request time. */\n providers: ProvidersConfig | (() => Promise<ProvidersConfig>);\n}\n"],"mappings":";;AAkKA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -1,4 +1,3 @@
1
- //#region src/oauth2/types.d.ts
2
1
  export interface PkceParameters {
3
2
  code_verifier: string;
4
3
  code_challenge: string;
@@ -155,6 +154,11 @@ export interface StandardClaims {
155
154
  picture?: string;
156
155
  website?: string;
157
156
  email?: string;
157
+ /**
158
+ * Set only by providers that state it (Google, Apple, GitHub from the primary address's
159
+ * `verified` flag, X when it returns `confirmed_email`); Facebook leaves it unset. Trust the
160
+ * address only when this is `true`.
161
+ */
158
162
  email_verified?: boolean;
159
163
  gender?: 'female' | 'male' | (string & {});
160
164
  birthdate?: string;
@@ -289,6 +293,5 @@ export interface OAuth2ClientConfig {
289
293
  /** Providers by key; a function is called per request, for secrets read at request time. */
290
294
  providers: ProvidersConfig | (() => Promise<ProvidersConfig>);
291
295
  }
292
- //#endregion
293
296
  export {};
294
297
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/oauth2/types.ts"],"mappings":";iBACiB;EACf;EACA;EACA;;iBAGe;EACf;;EAEA;EACA;EACA,sBAAsB;;;;;;EAMtB,aAAa;;UAGL;EACR;EACA;EACA;EACA;E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;EACf;EACA;EACA;;EAEA,WAAW,yBAAyB,QAAQ"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/oauth2/types.ts"],"mappings":"A,iBACiB;EACf;EACA;EACA;;iBAGe;EACf;;EAEA;EACA;EACA,sBAAsB;;;;;;EAMtB,aAAa;;UAGL;EACR;EACA;EACA;EACA;EACA,OAAO,KAAK;;iBAGG;EACf;EACA;;EAEA;EACA;EACA,OAAO,KAAK;;iBAGG;EACf;EACA;EACA;;iBAGe;EACf;EACA;EACA;;iBAGe;;;;;EAKf;EACA;EACA;;;;;;EAMA,OAAO,KAAK;;EAEZ,aAAa;;iBAIE;;;;;EAKf;;;;;EAMA;;;;;;;;EASA;;;;;;EAOA;;;;;;EAOA;EAEA;GAEC;;iBAGc,kBAAkB;EACjC;;YAGU;EACV;EACA;EACA;EACA;;;;;;;;EAQA;EACA;EACA;;;;;;;;;;;;EAYA,WAAW;;;iBAII;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;iBAQe;EACf;;qBAGW;YASD,oBAAoB;iBAGf;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;EAMA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;IACA;IACA;IACA;;EAEF;;iBAGe,SAAS;EACxB,QAAQ;EACR,MAAM;;iBAGS;;EAEf;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;;;EAKA;;EAGA;;;;;EAMA;;EAGA;;EAGA,yBAAyB,QAAQ,iCAAiC;;EAGlE,4BAA4B,QAAQ,uBAAuB,QAAQ;;;;;;EAOnE,cAAc,OAAO,aAAa,SAAS,oBAAoB,QAAQ;;EAGvE,sBAAsB,QAAQ,uBAAuB,QAAQ;;EAG7D,eAAe,QAAQ,sBAAsB;EAE7C,qBACE,QAAQ,4BACL;IAAU,OAAO;IAAa,UAAU;;;iBAG9B;EACf;EACA,WAAW;;iBAGI,uBAAuB;;EAEtC,eACE,kBACA,qBACG;IAAU,OAAO;IAAa,UAAU;;;;;;;;YAQnC,0BAA0B,8BAA8B;;iBAGnD;EACf;;EAEA,eAAe;;EAEf;;EAEA;;;;;;iBAOe;EACf;;EAEA,eAAe;;;;;EAKf;;;;;;;;iBASe;;EAEf,UAAU;;EAEV,MAAM;;;;;EAKN,SAAS;;YAGC;GAAqB,cAAc;;iBAE9B;EACf;EACA;EACA;;EAEA,WAAW,yBAAyB,QAAQ"}
@@ -1,4 +1,3 @@
1
- //#region src/oauth2/types.d.ts
2
1
  export interface PkceParameters {
3
2
  code_verifier: string;
4
3
  code_challenge: string;
@@ -155,6 +154,11 @@ export interface StandardClaims {
155
154
  picture?: string;
156
155
  website?: string;
157
156
  email?: string;
157
+ /**
158
+ * Set only by providers that state it (Google, Apple, GitHub from the primary address's
159
+ * `verified` flag, X when it returns `confirmed_email`); Facebook leaves it unset. Trust the
160
+ * address only when this is `true`.
161
+ */
158
162
  email_verified?: boolean;
159
163
  gender?: 'female' | 'male' | (string & {});
160
164
  birthdate?: string;
@@ -289,6 +293,5 @@ export interface OAuth2ClientConfig {
289
293
  /** Providers by key; a function is called per request, for secrets read at request time. */
290
294
  providers: ProvidersConfig | (() => Promise<ProvidersConfig>);
291
295
  }
292
- //#endregion
293
296
  export {};
294
297
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/oauth2/types.ts"],"mappings":";iBACiB;EACf;EACA;EACA;;iBAGe;EACf;;EAEA;EACA;EACA,sBAAsB;;;;;;EAMtB,aAAa;;UAGL;EACR;EACA;EACA;EACA;EACA,OAAO,KAAK;;iBAGG;EACf;EACA;;EAEA;EACA;EACA,OAAO,KAAK;;iBAGG;EACf;EACA;EACA;;iBAGe;EACf;EACA;EACA;;iBAGe;;;;;EAKf;EACA;EACA;;;;;;EAMA,OAAO,KAAK;;EAEZ,aAAa;;iBAIE;;;;;EAKf;;;;;EAMA;;;;;;;;EASA;;;;;;EAOA;;;;;;EAOA;EAEA;GAEC;;iBAGc,kBAAkB;EACjC;;YAGU;EACV;EACA;EACA;EACA;;;;;;;;EAQA;EACA;EACA;;;;;;;;;;;;EAYA,WAAW;;;iBAII;EACf;EACA;EACA;EACA;EACA;EACA;;;;;;;iBAQe;EACf;;qBAGW;YASD,oBAAoB;iBAGf;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IACE;IACA;IACA;IACA;IACA;IACA;;EAEF;;iBAGe,SAAS;EACxB,QAAQ;EACR,MAAM;;iBAGS;;EAEf;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;;;EAKA;;EAGA;;;;;EAMA;;EAGA;;EAGA,yBAAyB,QAAQ,iCAAiC;;EAGlE,4BAA4B,QAAQ,uBAAuB,QAAQ;;;;;;EAOnE,cAAc,OAAO,aAAa,SAAS,oBAAoB,QAAQ;;EAGvE,sBAAsB,QAAQ,uBAAuB,QAAQ;;EAG7D,eAAe,QAAQ,sBAAsB;EAE7C,qBACE,QAAQ,4BACL;IAAU,OAAO;IAAa,UAAU;;;iBAG9B;EACf;EACA,WAAW;;iBAGI,uBAAuB;;EAEtC,eACE,kBACA,qBACG;IAAU,OAAO;IAAa,UAAU;;;;;;;;YAQnC,0BAA0B,8BAA8B;;iBAGnD;EACf;;EAEA,eAAe;;EAEf;;EAEA;;;;;;iBAOe;EACf;;EAEA,eAAe;;;;;EAKf;;;;;;;;iBASe;;EAEf,UAAU;;EAEV,MAAM;;;;;EAKN,SAAS;;YAGC;GAAqB,cAAc;;iBAE9B;EACf;EACA;EACA;;EAEA,WAAW,yBAAyB,QAAQ"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/oauth2/types.ts"],"mappings":"A,iBACiB;EACf;EACA;EACA;;iBAGe;EACf;;EAEA;EACA;EACA,sBAAsB;;;;;;EAMtB,aAAa;;UAGL;EACR;EACA;EACA;EACA;EACA,OAAO,KAAK;;iBAGG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;EAEA,WAAW,yBAAyB,QAAQ"}
@@ -1,4 +1,4 @@
1
- //#region src/oauth2/types.ts
1
+ // src/oauth2/types.ts
2
2
  const OIDC_SCOPES = [
3
3
  "openid",
4
4
  "profile",
@@ -7,7 +7,6 @@ const OIDC_SCOPES = [
7
7
  "address",
8
8
  "offline_access"
9
9
  ];
10
- //#endregion
11
10
  export { OIDC_SCOPES };
12
11
 
13
12
  //# sourceMappingURL=types.mjs.map