@shware/security 2.5.3 → 2.6.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 (225) hide show
  1. package/dist/auth/index.cjs +520 -561
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +104 -106
  4. package/dist/auth/index.d.cts.map +1 -0
  5. package/dist/auth/index.d.mts +109 -0
  6. package/dist/auth/index.d.mts.map +1 -0
  7. package/dist/auth/index.mjs +513 -536
  8. package/dist/auth/index.mjs.map +1 -1
  9. package/dist/auth/types.cjs +0 -19
  10. package/dist/auth/types.d.cts +44 -44
  11. package/dist/auth/types.d.cts.map +1 -0
  12. package/dist/auth/types.d.mts +50 -0
  13. package/dist/auth/types.d.mts.map +1 -0
  14. package/dist/auth/types.mjs +1 -1
  15. package/dist/core/index.cjs +34 -59
  16. package/dist/core/index.cjs.map +1 -1
  17. package/dist/core/index.d.cts +23 -21
  18. package/dist/core/index.d.cts.map +1 -0
  19. package/dist/core/index.d.mts +34 -0
  20. package/dist/core/index.d.mts.map +1 -0
  21. package/dist/core/index.mjs +32 -33
  22. package/dist/core/index.mjs.map +1 -1
  23. package/dist/email/schema.cjs +13 -38
  24. package/dist/email/schema.cjs.map +1 -1
  25. package/dist/email/schema.d.cts +11 -12
  26. package/dist/email/schema.d.cts.map +1 -0
  27. package/dist/email/schema.d.mts +12 -0
  28. package/dist/email/schema.d.mts.map +1 -0
  29. package/dist/email/schema.mjs +10 -11
  30. package/dist/email/schema.mjs.map +1 -1
  31. package/dist/index.cjs +17 -54
  32. package/dist/index.d.cts +10 -15
  33. package/dist/index.d.mts +10 -0
  34. package/dist/index.mjs +4 -17
  35. package/dist/oauth2/client.cjs +109 -145
  36. package/dist/oauth2/client.cjs.map +1 -1
  37. package/dist/oauth2/client.d.cts +55 -56
  38. package/dist/oauth2/client.d.cts.map +1 -0
  39. package/dist/oauth2/client.d.mts +58 -0
  40. package/dist/oauth2/client.d.mts.map +1 -0
  41. package/dist/oauth2/client.mjs +104 -116
  42. package/dist/oauth2/client.mjs.map +1 -1
  43. package/dist/oauth2/error.cjs +19 -44
  44. package/dist/oauth2/error.cjs.map +1 -1
  45. package/dist/oauth2/error.d.cts +8 -6
  46. package/dist/oauth2/error.d.cts.map +1 -0
  47. package/dist/oauth2/{error.d.ts → error.d.mts} +8 -6
  48. package/dist/oauth2/error.d.mts.map +1 -0
  49. package/dist/oauth2/error.mjs +18 -19
  50. package/dist/oauth2/error.mjs.map +1 -1
  51. package/dist/oauth2/provider/apple.cjs +75 -88
  52. package/dist/oauth2/provider/apple.cjs.map +1 -1
  53. package/dist/oauth2/provider/apple.d.cts +31 -30
  54. package/dist/oauth2/provider/apple.d.cts.map +1 -0
  55. package/dist/oauth2/provider/apple.d.mts +42 -0
  56. package/dist/oauth2/provider/apple.d.mts.map +1 -0
  57. package/dist/oauth2/provider/apple.mjs +71 -60
  58. package/dist/oauth2/provider/apple.mjs.map +1 -1
  59. package/dist/oauth2/provider/common.cjs +86 -109
  60. package/dist/oauth2/provider/common.cjs.map +1 -1
  61. package/dist/oauth2/provider/common.d.cts +19 -18
  62. package/dist/oauth2/provider/common.d.cts.map +1 -0
  63. package/dist/oauth2/provider/common.d.mts +30 -0
  64. package/dist/oauth2/provider/common.d.mts.map +1 -0
  65. package/dist/oauth2/provider/common.mjs +80 -79
  66. package/dist/oauth2/provider/common.mjs.map +1 -1
  67. package/dist/oauth2/provider/facebook.cjs +93 -109
  68. package/dist/oauth2/provider/facebook.cjs.map +1 -1
  69. package/dist/oauth2/provider/facebook.d.cts +29 -28
  70. package/dist/oauth2/provider/facebook.d.cts.map +1 -0
  71. package/dist/oauth2/provider/facebook.d.mts +45 -0
  72. package/dist/oauth2/provider/facebook.d.mts.map +1 -0
  73. package/dist/oauth2/provider/facebook.mjs +89 -81
  74. package/dist/oauth2/provider/facebook.mjs.map +1 -1
  75. package/dist/oauth2/provider/github.cjs +64 -91
  76. package/dist/oauth2/provider/github.cjs.map +1 -1
  77. package/dist/oauth2/provider/github.d.cts +52 -51
  78. package/dist/oauth2/provider/github.d.cts.map +1 -0
  79. package/dist/oauth2/provider/github.d.mts +60 -0
  80. package/dist/oauth2/provider/github.d.mts.map +1 -0
  81. package/dist/oauth2/provider/github.mjs +60 -63
  82. package/dist/oauth2/provider/github.mjs.map +1 -1
  83. package/dist/oauth2/provider/google.cjs +105 -122
  84. package/dist/oauth2/provider/google.cjs.map +1 -1
  85. package/dist/oauth2/provider/google.d.cts +34 -33
  86. package/dist/oauth2/provider/google.d.cts.map +1 -0
  87. package/dist/oauth2/provider/google.d.mts +44 -0
  88. package/dist/oauth2/provider/google.d.mts.map +1 -0
  89. package/dist/oauth2/provider/google.mjs +101 -94
  90. package/dist/oauth2/provider/google.mjs.map +1 -1
  91. package/dist/oauth2/provider/index.cjs +13 -46
  92. package/dist/oauth2/provider/index.d.cts +7 -7
  93. package/dist/oauth2/provider/index.d.mts +7 -0
  94. package/dist/oauth2/provider/index.mjs +1 -10
  95. package/dist/oauth2/provider/wechat.cjs +77 -99
  96. package/dist/oauth2/provider/wechat.cjs.map +1 -1
  97. package/dist/oauth2/provider/wechat.d.cts +28 -27
  98. package/dist/oauth2/provider/wechat.d.cts.map +1 -0
  99. package/dist/oauth2/provider/wechat.d.mts +39 -0
  100. package/dist/oauth2/provider/wechat.d.mts.map +1 -0
  101. package/dist/oauth2/provider/wechat.mjs +74 -72
  102. package/dist/oauth2/provider/wechat.mjs.map +1 -1
  103. package/dist/oauth2/provider/x.cjs +102 -125
  104. package/dist/oauth2/provider/x.cjs.map +1 -1
  105. package/dist/oauth2/provider/x.d.cts +51 -50
  106. package/dist/oauth2/provider/x.d.cts.map +1 -0
  107. package/dist/oauth2/provider/x.d.mts +69 -0
  108. package/dist/oauth2/provider/x.d.mts.map +1 -0
  109. package/dist/oauth2/provider/x.mjs +99 -103
  110. package/dist/oauth2/provider/x.mjs.map +1 -1
  111. package/dist/oauth2/types.cjs +13 -37
  112. package/dist/oauth2/types.cjs.map +1 -1
  113. package/dist/oauth2/types.d.cts +180 -178
  114. package/dist/oauth2/types.d.cts.map +1 -0
  115. package/dist/oauth2/types.d.mts +213 -0
  116. package/dist/oauth2/types.d.mts.map +1 -0
  117. package/dist/oauth2/types.mjs +13 -13
  118. package/dist/oauth2/types.mjs.map +1 -1
  119. package/dist/session/common.cjs +17 -43
  120. package/dist/session/common.cjs.map +1 -1
  121. package/dist/session/common.d.cts +4 -4
  122. package/dist/session/common.d.cts.map +1 -0
  123. package/dist/session/{common.d.ts → common.d.mts} +4 -4
  124. package/dist/session/common.d.mts.map +1 -0
  125. package/dist/session/common.mjs +14 -16
  126. package/dist/session/common.mjs.map +1 -1
  127. package/dist/session/db.cjs +88 -123
  128. package/dist/session/db.cjs.map +1 -1
  129. package/dist/session/db.d.cts +36 -36
  130. package/dist/session/db.d.cts.map +1 -0
  131. package/dist/session/db.d.mts +44 -0
  132. package/dist/session/db.d.mts.map +1 -0
  133. package/dist/session/db.mjs +84 -95
  134. package/dist/session/db.mjs.map +1 -1
  135. package/dist/session/map-session.cjs +71 -103
  136. package/dist/session/map-session.cjs.map +1 -1
  137. package/dist/session/map-session.d.cts +24 -24
  138. package/dist/session/map-session.d.cts.map +1 -0
  139. package/dist/session/map-session.d.mts +27 -0
  140. package/dist/session/map-session.d.mts.map +1 -0
  141. package/dist/session/map-session.mjs +70 -78
  142. package/dist/session/map-session.mjs.map +1 -1
  143. package/dist/session/redis.cjs +270 -319
  144. package/dist/session/redis.cjs.map +1 -1
  145. package/dist/session/redis.d.cts +51 -51
  146. package/dist/session/redis.d.cts.map +1 -0
  147. package/dist/session/redis.d.mts +58 -0
  148. package/dist/session/redis.d.mts.map +1 -0
  149. package/dist/session/redis.mjs +266 -291
  150. package/dist/session/redis.mjs.map +1 -1
  151. package/dist/session/types.cjs +0 -19
  152. package/dist/session/types.d.cts +34 -33
  153. package/dist/session/types.d.cts.map +1 -0
  154. package/dist/session/types.d.mts +45 -0
  155. package/dist/session/types.d.mts.map +1 -0
  156. package/dist/session/types.mjs +1 -1
  157. package/dist/utils/http.cjs +31 -55
  158. package/dist/utils/http.cjs.map +1 -1
  159. package/dist/utils/http.d.cts +7 -10
  160. package/dist/utils/http.d.cts.map +1 -0
  161. package/dist/utils/{http.d.ts → http.d.mts} +7 -10
  162. package/dist/utils/http.d.mts.map +1 -0
  163. package/dist/utils/http.mjs +24 -24
  164. package/dist/utils/http.mjs.map +1 -1
  165. package/dist/utils/oauth2.cjs +6 -30
  166. package/dist/utils/oauth2.cjs.map +1 -1
  167. package/dist/utils/oauth2.d.cts +3 -1
  168. package/dist/utils/oauth2.d.cts.map +1 -0
  169. package/dist/utils/oauth2.d.mts +5 -0
  170. package/dist/utils/oauth2.d.mts.map +1 -0
  171. package/dist/utils/oauth2.mjs +5 -5
  172. package/dist/utils/oauth2.mjs.map +1 -1
  173. package/dist/utils/timing.cjs +49 -70
  174. package/dist/utils/timing.cjs.map +1 -1
  175. package/dist/utils/timing.d.cts +10 -8
  176. package/dist/utils/timing.d.cts.map +1 -0
  177. package/dist/utils/timing.d.mts +15 -0
  178. package/dist/utils/timing.d.mts.map +1 -0
  179. package/dist/utils/timing.mjs +48 -45
  180. package/dist/utils/timing.mjs.map +1 -1
  181. package/dist/utils/valid.cjs +50 -71
  182. package/dist/utils/valid.cjs.map +1 -1
  183. package/dist/utils/valid.d.cts +17 -16
  184. package/dist/utils/valid.d.cts.map +1 -0
  185. package/dist/utils/valid.d.mts +28 -0
  186. package/dist/utils/valid.d.mts.map +1 -0
  187. package/dist/utils/valid.mjs +47 -44
  188. package/dist/utils/valid.mjs.map +1 -1
  189. package/package.json +22 -12
  190. package/dist/auth/index.d.ts +0 -111
  191. package/dist/auth/types.cjs.map +0 -1
  192. package/dist/auth/types.d.ts +0 -50
  193. package/dist/auth/types.mjs.map +0 -1
  194. package/dist/core/index.d.ts +0 -32
  195. package/dist/email/schema.d.ts +0 -13
  196. package/dist/index.cjs.map +0 -1
  197. package/dist/index.d.ts +0 -15
  198. package/dist/index.mjs.map +0 -1
  199. package/dist/oauth2/client.d.ts +0 -59
  200. package/dist/oauth2/provider/apple.d.ts +0 -41
  201. package/dist/oauth2/provider/common.d.ts +0 -29
  202. package/dist/oauth2/provider/facebook.d.ts +0 -44
  203. package/dist/oauth2/provider/github.d.ts +0 -59
  204. package/dist/oauth2/provider/google.d.ts +0 -43
  205. package/dist/oauth2/provider/index.cjs.map +0 -1
  206. package/dist/oauth2/provider/index.d.ts +0 -7
  207. package/dist/oauth2/provider/index.mjs.map +0 -1
  208. package/dist/oauth2/provider/wechat.d.ts +0 -38
  209. package/dist/oauth2/provider/x.d.ts +0 -68
  210. package/dist/oauth2/types.d.ts +0 -211
  211. package/dist/session/__tests__/redis.test.cjs +0 -247
  212. package/dist/session/__tests__/redis.test.cjs.map +0 -1
  213. package/dist/session/__tests__/redis.test.d.cts +0 -2
  214. package/dist/session/__tests__/redis.test.d.ts +0 -2
  215. package/dist/session/__tests__/redis.test.mjs +0 -252
  216. package/dist/session/__tests__/redis.test.mjs.map +0 -1
  217. package/dist/session/db.d.ts +0 -44
  218. package/dist/session/map-session.d.ts +0 -27
  219. package/dist/session/redis.d.ts +0 -58
  220. package/dist/session/types.cjs.map +0 -1
  221. package/dist/session/types.d.ts +0 -44
  222. package/dist/session/types.mjs.map +0 -1
  223. package/dist/utils/oauth2.d.ts +0 -3
  224. package/dist/utils/timing.d.ts +0 -13
  225. package/dist/utils/valid.d.ts +0 -27
@@ -1,211 +1,213 @@
1
+ //#region src/oauth2/types.d.ts
1
2
  interface PkceParameters {
2
- code_verifier: string;
3
- code_challenge: string;
4
- code_challenge_method: 'S256' | 'plain';
3
+ code_verifier: string;
4
+ code_challenge: string;
5
+ code_challenge_method: 'S256' | 'plain';
5
6
  }
6
7
  interface OAuth2AuthorizationRequest {
7
- state: string;
8
- registrationId: string;
9
- authorizationRequestUri: string;
10
- additionalParameters: PkceParameters;
8
+ state: string;
9
+ registrationId: string;
10
+ authorizationRequestUri: string;
11
+ additionalParameters: PkceParameters;
11
12
  }
12
13
  interface CreateAuthorizationUriParams {
13
- state: string;
14
- clientId: string;
15
- redirectUri: string;
16
- scope: string[] | undefined;
17
- pkce?: Omit<PkceParameters, 'code_verifier'>;
14
+ state: string;
15
+ clientId: string;
16
+ redirectUri: string;
17
+ scope: string[] | undefined;
18
+ pkce?: Omit<PkceParameters, 'code_verifier'>;
18
19
  }
19
20
  interface ExchangeCodeParams {
20
- code: string;
21
- clientId: string;
22
- clientSecret: string;
23
- redirectUri: string;
24
- pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;
21
+ code: string;
22
+ clientId: string;
23
+ clientSecret: string;
24
+ redirectUri: string;
25
+ pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;
25
26
  }
26
27
  interface RefreshTokenParams {
27
- clientId: string;
28
- clientSecret: string;
29
- refreshToken: string;
28
+ clientId: string;
29
+ clientSecret: string;
30
+ refreshToken: string;
30
31
  }
31
32
  interface RevokeTokenParams {
32
- token: string;
33
- clientId: string;
34
- clientSecret: string;
33
+ token: string;
34
+ clientId: string;
35
+ clientSecret: string;
35
36
  }
36
37
  interface LoginOAuth2NativeParams {
37
- clientId: string;
38
- clientSecret: string;
39
- redirectUri: string;
40
- pkce?: PkceParameters;
41
- credentials: NativeCredential;
38
+ clientId: string;
39
+ clientSecret: string;
40
+ redirectUri: string;
41
+ pkce?: PkceParameters;
42
+ credentials: NativeCredential;
42
43
  }
43
44
  interface OAuth2Token {
44
- /**
45
- * REQUIRED.
46
- * The access token issued by the authorization server.
47
- */
48
- access_token: string;
49
- /**
50
- * REQUIRED.
51
- * The type of the token issued as described in Section 7.1. Value is case insensitive.
52
- */
53
- token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});
54
- /**
55
- * RECOMMENDED.
56
- * The lifetime in seconds of the access token. For example, the value "3600" denotes that the
57
- * access token will expire in one hour from the time the response was generated. If omitted, the
58
- * authorization server SHOULD provide the expiration time via other means or document the default
59
- * value.
60
- */
61
- expires_in?: number;
62
- /**
63
- * OPTIONAL.
64
- * The refresh token, which can be used to obtain new access tokens using the same authorization
65
- * grant as described in Section 6.
66
- */
67
- refresh_token?: string;
68
- /**
69
- * OPTIONAL.
70
- * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the
71
- * access token as described by Section 3.3.
72
- */
73
- scope?: string;
74
- id_token?: string;
75
- [key: string]: unknown;
45
+ /**
46
+ * REQUIRED.
47
+ * The access token issued by the authorization server.
48
+ */
49
+ access_token: string;
50
+ /**
51
+ * REQUIRED.
52
+ * The type of the token issued as described in Section 7.1. Value is case insensitive.
53
+ */
54
+ token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});
55
+ /**
56
+ * RECOMMENDED.
57
+ * The lifetime in seconds of the access token. For example, the value "3600" denotes that the
58
+ * access token will expire in one hour from the time the response was generated. If omitted, the
59
+ * authorization server SHOULD provide the expiration time via other means or document the default
60
+ * value.
61
+ */
62
+ expires_in?: number;
63
+ /**
64
+ * OPTIONAL.
65
+ * The refresh token, which can be used to obtain new access tokens using the same authorization
66
+ * grant as described in Section 6.
67
+ */
68
+ refresh_token?: string;
69
+ /**
70
+ * OPTIONAL.
71
+ * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the
72
+ * access token as described by Section 3.3.
73
+ */
74
+ scope?: string;
75
+ id_token?: string;
76
+ [key: string]: unknown;
76
77
  }
77
78
  interface OidcToken extends OAuth2Token {
78
- id_token: string;
79
+ id_token: string;
79
80
  }
80
81
  type NativeCredential = {
81
- state?: string;
82
- code?: string;
83
- client_id?: string;
84
- redirect_uri?: string;
85
- id_token?: string;
86
- access_token?: string;
82
+ state?: string;
83
+ code?: string;
84
+ client_id?: string;
85
+ redirect_uri?: string;
86
+ id_token?: string;
87
+ access_token?: string;
87
88
  };
88
89
  declare enum OidcScopes {
89
- openid = "openid",
90
- profile = "profile",
91
- email = "email",
92
- phone = "phone",
93
- address = "address",
94
- offline_access = "offline_access"
90
+ openid = "openid",
91
+ profile = "profile",
92
+ email = "email",
93
+ phone = "phone",
94
+ address = "address",
95
+ offline_access = "offline_access"
95
96
  }
96
97
  interface StandardClaims {
97
- sub: string;
98
- name?: string;
99
- given_name?: string;
100
- family_name?: string;
101
- middle_name?: string;
102
- nickname?: string;
103
- preferred_username?: string;
104
- profile?: string;
105
- picture?: string;
106
- website?: string;
107
- email?: string;
108
- email_verified?: boolean;
109
- gender?: 'female' | 'male' | (string & {});
110
- birthdate?: string;
111
- zoneinfo?: string;
112
- locale?: string;
113
- phone_number?: string;
114
- phone_number_verified?: boolean;
115
- address?: {
116
- formatted: string;
117
- street_address: string;
118
- locality: string;
119
- region: string;
120
- postal_code: string;
121
- country: string;
122
- };
123
- updated_at?: number;
98
+ sub: string;
99
+ name?: string;
100
+ given_name?: string;
101
+ family_name?: string;
102
+ middle_name?: string;
103
+ nickname?: string;
104
+ preferred_username?: string;
105
+ profile?: string;
106
+ picture?: string;
107
+ website?: string;
108
+ email?: string;
109
+ email_verified?: boolean;
110
+ gender?: 'female' | 'male' | (string & {});
111
+ birthdate?: string;
112
+ zoneinfo?: string;
113
+ locale?: string;
114
+ phone_number?: string;
115
+ phone_number_verified?: boolean;
116
+ address?: {
117
+ formatted: string;
118
+ street_address: string;
119
+ locality: string;
120
+ region: string;
121
+ postal_code: string;
122
+ country: string;
123
+ };
124
+ updated_at?: number;
124
125
  }
125
126
  interface UserInfo<T = unknown> {
126
- claims: StandardClaims;
127
- data: T;
127
+ claims: StandardClaims;
128
+ data: T;
128
129
  }
129
130
  interface Provider {
130
- /** Authorization URI for the provider. */
131
- authorizationUri: string;
132
- /** Token URI for the provider. */
133
- tokenUri: string;
134
- /** Token revoke URI for the provider. */
135
- tokenRevokeUri?: string;
136
- /** Token refresh URI for the provider. */
137
- tokenRefreshUri?: string;
138
- /** User info URI for the provider. */
139
- userInfoUri?: string;
140
- /** User info authentication method for the provider. */
141
- userInfoAuthenticationMethod?: string;
142
- /**
143
- * Name of the attribute that will be used to extract the username from the call to 'userInfoUri'.
144
- * */
145
- userNameAttribute?: string;
146
- /** JWK set URI for the provider */
147
- jwkSetUri?: string;
148
- /**
149
- * URI that can either be an OpenID Connect discovery endpoint or an OAuth 2.0 Authorization
150
- * Server Metadata endpoint defined by RFC 8414.
151
- * */
152
- issuerUri?: string;
153
- /** Default scopes for the provider. */
154
- defaultScope: string[];
155
- /** step 1: generate authorization uri and redirect user to it */
156
- createAuthorizationUri: (params: CreateAuthorizationUriParams) => URL;
157
- /** step 2: exchange code for token */
158
- exchangeAuthorizationCode: (params: ExchangeCodeParams) => Promise<OAuth2Token>;
159
- /** step 3: get user info */
160
- getUserInfo: (token: OAuth2Token) => Promise<UserInfo>;
161
- /** others: refresh access token */
162
- refreshAccessToken?: (params: RefreshTokenParams) => Promise<OAuth2Token>;
163
- /** others: revoke token */
164
- revokeToken?: (params: RevokeTokenParams) => Promise<void>;
165
- loginOAuth2Native?: (params: LoginOAuth2NativeParams) => Promise<{
166
- token: OAuth2Token;
167
- userInfo: UserInfo;
168
- }>;
131
+ /** Authorization URI for the provider. */
132
+ authorizationUri: string;
133
+ /** Token URI for the provider. */
134
+ tokenUri: string;
135
+ /** Token revoke URI for the provider. */
136
+ tokenRevokeUri?: string;
137
+ /** Token refresh URI for the provider. */
138
+ tokenRefreshUri?: string;
139
+ /** User info URI for the provider. */
140
+ userInfoUri?: string;
141
+ /** User info authentication method for the provider. */
142
+ userInfoAuthenticationMethod?: string;
143
+ /**
144
+ * Name of the attribute that will be used to extract the username from the call to 'userInfoUri'.
145
+ * */
146
+ userNameAttribute?: string;
147
+ /** JWK set URI for the provider */
148
+ jwkSetUri?: string;
149
+ /**
150
+ * URI that can either be an OpenID Connect discovery endpoint or an OAuth 2.0 Authorization
151
+ * Server Metadata endpoint defined by RFC 8414.
152
+ * */
153
+ issuerUri?: string;
154
+ /** Default scopes for the provider. */
155
+ defaultScope: string[];
156
+ /** step 1: generate authorization uri and redirect user to it */
157
+ createAuthorizationUri: (params: CreateAuthorizationUriParams) => URL;
158
+ /** step 2: exchange code for token */
159
+ exchangeAuthorizationCode: (params: ExchangeCodeParams) => Promise<OAuth2Token>;
160
+ /** step 3: get user info */
161
+ getUserInfo: (token: OAuth2Token) => Promise<UserInfo>;
162
+ /** others: refresh access token */
163
+ refreshAccessToken?: (params: RefreshTokenParams) => Promise<OAuth2Token>;
164
+ /** others: revoke token */
165
+ revokeToken?: (params: RevokeTokenParams) => Promise<void>;
166
+ loginOAuth2Native?: (params: LoginOAuth2NativeParams) => Promise<{
167
+ token: OAuth2Token;
168
+ userInfo: UserInfo;
169
+ }>;
169
170
  }
170
171
  interface OneTapProvider extends Provider {
171
- getTokenInfo: (id_token: string) => Promise<{
172
- token: OAuth2Token;
173
- userInfo: UserInfo;
174
- }>;
172
+ getTokenInfo: (id_token: string) => Promise<{
173
+ token: OAuth2Token;
174
+ userInfo: UserInfo;
175
+ }>;
175
176
  }
176
177
  interface Registration {
177
- /**
178
- * Reference to the OAuth 2.0 provider to use. May reference an element from the 'provider'
179
- * property or used one of the commonly used providers (google, github, facebook, okta).
180
- * */
181
- provider?: string;
182
- /** Client ID for the registration. */
183
- clientId: string;
184
- /** Client secret of the registration. */
185
- clientSecret: string;
186
- /** Client authentication method. May be left blank when using a pre-defined provider. */
187
- clientAuthenticationMethod?: string;
188
- /** Authorization grant type. May be left blank when using a pre-defined provider. */
189
- authorizationGrantType?: 'authorization_code' | 'client_credentials' | 'device_code' | 'jwt_bearer' | 'password' | 'refresh_token' | 'token_exchange';
190
- /** Redirect URI. May be left blank when using a pre-defined provider. */
191
- redirectUri?: string;
192
- /** Authorization scopes. When left blank the provider's default scopes, if any, will be used. */
193
- scope?: string[];
194
- /** Client name. May be left blank when using a pre-defined provider. */
195
- clientName?: string;
178
+ /**
179
+ * Reference to the OAuth 2.0 provider to use. May reference an element from the 'provider'
180
+ * property or used one of the commonly used providers (google, github, facebook, okta).
181
+ * */
182
+ provider?: string;
183
+ /** Client ID for the registration. */
184
+ clientId: string;
185
+ /** Client secret of the registration. */
186
+ clientSecret: string;
187
+ /** Client authentication method. May be left blank when using a pre-defined provider. */
188
+ clientAuthenticationMethod?: string;
189
+ /** Authorization grant type. May be left blank when using a pre-defined provider. */
190
+ authorizationGrantType?: 'authorization_code' | 'client_credentials' | 'device_code' | 'jwt_bearer' | 'password' | 'refresh_token' | 'token_exchange';
191
+ /** Redirect URI. May be left blank when using a pre-defined provider. */
192
+ redirectUri?: string;
193
+ /** Authorization scopes. When left blank the provider's default scopes, if any, will be used. */
194
+ scope?: string[];
195
+ /** Client name. May be left blank when using a pre-defined provider. */
196
+ clientName?: string;
196
197
  }
197
198
  interface OAuth2ClientConfig {
198
- baseUri: string;
199
- errorUri: string;
200
- successUri: string;
201
- provider: {
202
- [name: string]: Provider | undefined;
203
- };
204
- registration: {
205
- [name: string]: Registration | undefined;
206
- } | (() => Promise<{
207
- [name: string]: Registration | undefined;
208
- }>);
209
- }
210
-
211
- export { type ExchangeCodeParams, type LoginOAuth2NativeParams, type NativeCredential, type OAuth2AuthorizationRequest, type OAuth2ClientConfig, type OAuth2Token, OidcScopes, type OidcToken, type OneTapProvider, type PkceParameters, type Provider, type RefreshTokenParams, type Registration, type RevokeTokenParams, type StandardClaims, type UserInfo };
199
+ baseUri: string;
200
+ errorUri: string;
201
+ successUri: string;
202
+ provider: {
203
+ [name: string]: Provider | undefined;
204
+ };
205
+ registration: {
206
+ [name: string]: Registration | undefined;
207
+ } | (() => Promise<{
208
+ [name: string]: Registration | undefined;
209
+ }>);
210
+ }
211
+ //#endregion
212
+ export { ExchangeCodeParams, LoginOAuth2NativeParams, NativeCredential, OAuth2AuthorizationRequest, OAuth2ClientConfig, OAuth2Token, OidcScopes, OidcToken, OneTapProvider, PkceParameters, Provider, RefreshTokenParams, Registration, RevokeTokenParams, StandardClaims, UserInfo };
213
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../../src/oauth2/types.ts"],"mappings":";UACiB;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA,sBAAsB;;UAGd;EACR;EACA;EACA;EACA;EACA,OAAO,KAAK;;UAGG;EACf;EACA;EACA;EACA;EACA,OAAO,KAAK;;UAGG;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA,OAAO;EACP,aAAa;;UAIE;;;;;EAKf;;;;;EAMA;;;;;;;;EASA;;;;;;EAOA;;;;;;EAOA;EAEA;GAEC;;UAGc,kBAAkB;EACjC;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;;aAGU;EACV;EACA;EACA;EACA;EACA;EACA;;UAIe;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;;UAGe,SAAS;EACxB,QAAQ;EACR,MAAM;;UAGS;;EAEf;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;;;EAKA;;EAGA;;;;;EAMA;;EAGA;;EAGA,yBAAyB,QAAQ,iCAAiC;;EAGlE,4BAA4B,QAAQ,uBAAuB,QAAQ;;EAGnE,cAAc,OAAO,gBAAgB,QAAQ;;EAG7C,sBAAsB,QAAQ,uBAAuB,QAAQ;;EAG7D,eAAe,QAAQ,sBAAsB;EAE7C,qBACE,QAAQ,4BACL;IAAU,OAAO;IAAa,UAAU;;;UAG9B,uBAAuB;EACtC,eAAe,qBAAqB;IAAU,OAAO;IAAa,UAAU;;;UAG7D;;;;;EAKf;;EAGA;;EAGA;;EAGA;;EAGA;;EAYA;;EAGA;;EAGA;;UAGe;EACf;EACA;EACA;EACA;KAAa,eAAe;;EAC5B;KACO,eAAe;aACX;KAAW,eAAe"}
@@ -0,0 +1,213 @@
1
+ //#region src/oauth2/types.d.ts
2
+ interface PkceParameters {
3
+ code_verifier: string;
4
+ code_challenge: string;
5
+ code_challenge_method: 'S256' | 'plain';
6
+ }
7
+ interface OAuth2AuthorizationRequest {
8
+ state: string;
9
+ registrationId: string;
10
+ authorizationRequestUri: string;
11
+ additionalParameters: PkceParameters;
12
+ }
13
+ interface CreateAuthorizationUriParams {
14
+ state: string;
15
+ clientId: string;
16
+ redirectUri: string;
17
+ scope: string[] | undefined;
18
+ pkce?: Omit<PkceParameters, 'code_verifier'>;
19
+ }
20
+ interface ExchangeCodeParams {
21
+ code: string;
22
+ clientId: string;
23
+ clientSecret: string;
24
+ redirectUri: string;
25
+ pkce?: Omit<PkceParameters, 'code_challenge' | 'code_challenge_method'>;
26
+ }
27
+ interface RefreshTokenParams {
28
+ clientId: string;
29
+ clientSecret: string;
30
+ refreshToken: string;
31
+ }
32
+ interface RevokeTokenParams {
33
+ token: string;
34
+ clientId: string;
35
+ clientSecret: string;
36
+ }
37
+ interface LoginOAuth2NativeParams {
38
+ clientId: string;
39
+ clientSecret: string;
40
+ redirectUri: string;
41
+ pkce?: PkceParameters;
42
+ credentials: NativeCredential;
43
+ }
44
+ interface OAuth2Token {
45
+ /**
46
+ * REQUIRED.
47
+ * The access token issued by the authorization server.
48
+ */
49
+ access_token: string;
50
+ /**
51
+ * REQUIRED.
52
+ * The type of the token issued as described in Section 7.1. Value is case insensitive.
53
+ */
54
+ token_type: 'Bearer' | 'bearer' | 'mac' | (string & {});
55
+ /**
56
+ * RECOMMENDED.
57
+ * The lifetime in seconds of the access token. For example, the value "3600" denotes that the
58
+ * access token will expire in one hour from the time the response was generated. If omitted, the
59
+ * authorization server SHOULD provide the expiration time via other means or document the default
60
+ * value.
61
+ */
62
+ expires_in?: number;
63
+ /**
64
+ * OPTIONAL.
65
+ * The refresh token, which can be used to obtain new access tokens using the same authorization
66
+ * grant as described in Section 6.
67
+ */
68
+ refresh_token?: string;
69
+ /**
70
+ * OPTIONAL.
71
+ * If identical to the scope requested by the client; otherwise, REQUIRED. The scope of the
72
+ * access token as described by Section 3.3.
73
+ */
74
+ scope?: string;
75
+ id_token?: string;
76
+ [key: string]: unknown;
77
+ }
78
+ interface OidcToken extends OAuth2Token {
79
+ id_token: string;
80
+ }
81
+ type NativeCredential = {
82
+ state?: string;
83
+ code?: string;
84
+ client_id?: string;
85
+ redirect_uri?: string;
86
+ id_token?: string;
87
+ access_token?: string;
88
+ };
89
+ declare enum OidcScopes {
90
+ openid = "openid",
91
+ profile = "profile",
92
+ email = "email",
93
+ phone = "phone",
94
+ address = "address",
95
+ offline_access = "offline_access"
96
+ }
97
+ interface StandardClaims {
98
+ sub: string;
99
+ name?: string;
100
+ given_name?: string;
101
+ family_name?: string;
102
+ middle_name?: string;
103
+ nickname?: string;
104
+ preferred_username?: string;
105
+ profile?: string;
106
+ picture?: string;
107
+ website?: string;
108
+ email?: string;
109
+ email_verified?: boolean;
110
+ gender?: 'female' | 'male' | (string & {});
111
+ birthdate?: string;
112
+ zoneinfo?: string;
113
+ locale?: string;
114
+ phone_number?: string;
115
+ phone_number_verified?: boolean;
116
+ address?: {
117
+ formatted: string;
118
+ street_address: string;
119
+ locality: string;
120
+ region: string;
121
+ postal_code: string;
122
+ country: string;
123
+ };
124
+ updated_at?: number;
125
+ }
126
+ interface UserInfo<T = unknown> {
127
+ claims: StandardClaims;
128
+ data: T;
129
+ }
130
+ interface Provider {
131
+ /** Authorization URI for the provider. */
132
+ authorizationUri: string;
133
+ /** Token URI for the provider. */
134
+ tokenUri: string;
135
+ /** Token revoke URI for the provider. */
136
+ tokenRevokeUri?: string;
137
+ /** Token refresh URI for the provider. */
138
+ tokenRefreshUri?: string;
139
+ /** User info URI for the provider. */
140
+ userInfoUri?: string;
141
+ /** User info authentication method for the provider. */
142
+ userInfoAuthenticationMethod?: string;
143
+ /**
144
+ * Name of the attribute that will be used to extract the username from the call to 'userInfoUri'.
145
+ * */
146
+ userNameAttribute?: string;
147
+ /** JWK set URI for the provider */
148
+ jwkSetUri?: string;
149
+ /**
150
+ * URI that can either be an OpenID Connect discovery endpoint or an OAuth 2.0 Authorization
151
+ * Server Metadata endpoint defined by RFC 8414.
152
+ * */
153
+ issuerUri?: string;
154
+ /** Default scopes for the provider. */
155
+ defaultScope: string[];
156
+ /** step 1: generate authorization uri and redirect user to it */
157
+ createAuthorizationUri: (params: CreateAuthorizationUriParams) => URL;
158
+ /** step 2: exchange code for token */
159
+ exchangeAuthorizationCode: (params: ExchangeCodeParams) => Promise<OAuth2Token>;
160
+ /** step 3: get user info */
161
+ getUserInfo: (token: OAuth2Token) => Promise<UserInfo>;
162
+ /** others: refresh access token */
163
+ refreshAccessToken?: (params: RefreshTokenParams) => Promise<OAuth2Token>;
164
+ /** others: revoke token */
165
+ revokeToken?: (params: RevokeTokenParams) => Promise<void>;
166
+ loginOAuth2Native?: (params: LoginOAuth2NativeParams) => Promise<{
167
+ token: OAuth2Token;
168
+ userInfo: UserInfo;
169
+ }>;
170
+ }
171
+ interface OneTapProvider extends Provider {
172
+ getTokenInfo: (id_token: string) => Promise<{
173
+ token: OAuth2Token;
174
+ userInfo: UserInfo;
175
+ }>;
176
+ }
177
+ interface Registration {
178
+ /**
179
+ * Reference to the OAuth 2.0 provider to use. May reference an element from the 'provider'
180
+ * property or used one of the commonly used providers (google, github, facebook, okta).
181
+ * */
182
+ provider?: string;
183
+ /** Client ID for the registration. */
184
+ clientId: string;
185
+ /** Client secret of the registration. */
186
+ clientSecret: string;
187
+ /** Client authentication method. May be left blank when using a pre-defined provider. */
188
+ clientAuthenticationMethod?: string;
189
+ /** Authorization grant type. May be left blank when using a pre-defined provider. */
190
+ authorizationGrantType?: 'authorization_code' | 'client_credentials' | 'device_code' | 'jwt_bearer' | 'password' | 'refresh_token' | 'token_exchange';
191
+ /** Redirect URI. May be left blank when using a pre-defined provider. */
192
+ redirectUri?: string;
193
+ /** Authorization scopes. When left blank the provider's default scopes, if any, will be used. */
194
+ scope?: string[];
195
+ /** Client name. May be left blank when using a pre-defined provider. */
196
+ clientName?: string;
197
+ }
198
+ interface OAuth2ClientConfig {
199
+ baseUri: string;
200
+ errorUri: string;
201
+ successUri: string;
202
+ provider: {
203
+ [name: string]: Provider | undefined;
204
+ };
205
+ registration: {
206
+ [name: string]: Registration | undefined;
207
+ } | (() => Promise<{
208
+ [name: string]: Registration | undefined;
209
+ }>);
210
+ }
211
+ //#endregion
212
+ export { ExchangeCodeParams, LoginOAuth2NativeParams, NativeCredential, OAuth2AuthorizationRequest, OAuth2ClientConfig, OAuth2Token, OidcScopes, OidcToken, OneTapProvider, PkceParameters, Provider, RefreshTokenParams, Registration, RevokeTokenParams, StandardClaims, UserInfo };
213
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/oauth2/types.ts"],"mappings":";UACiB;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA,sBAAsB;;UAGd;EACR;EACA;EACA;EACA;EACA,OAAO,KAAK;;UAGG;EACf;EACA;EACA;EACA;EACA,OAAO,KAAK;;UAGG;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;;UAGe;EACf;EACA;EACA;EACA,OAAO;EACP,aAAa;;UAIE;;;;;EAKf;;;;;EAMA;;;;;;;;EASA;;;;;;EAOA;;;;;;EAOA;EAEA;GAEC;;UAGc,kBAAkB;EACjC;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;;aAGU;EACV;EACA;EACA;EACA;EACA;EACA;;UAIe;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;;UAGe,SAAS;EACxB,QAAQ;EACR,MAAM;;UAGS;;EAEf;;EAGA;;EAGA;;EAGA;;EAGA;;EAGA;;;;EAKA;;EAGA;;;;;EAMA;;EAGA;;EAGA,yBAAyB,QAAQ,iCAAiC;;EAGlE,4BAA4B,QAAQ,uBAAuB,QAAQ;;EAGnE,cAAc,OAAO,gBAAgB,QAAQ;;EAG7C,sBAAsB,QAAQ,uBAAuB,QAAQ;;EAG7D,eAAe,QAAQ,sBAAsB;EAE7C,qBACE,QAAQ,4BACL;IAAU,OAAO;IAAa,UAAU;;;UAG9B,uBAAuB;EACtC,eAAe,qBAAqB;IAAU,OAAO;IAAa,UAAU;;;UAG7D;;;;;EAKf;;EAGA;;EAGA;;EAGA;;EAGA;;EAYA;;EAGA;;EAGA;;UAGe;EACf;EACA;EACA;EACA;KAAa,eAAe;;EAC5B;KACO,eAAe;aACX;KAAW,eAAe"}
@@ -1,14 +1,14 @@
1
- // src/oauth2/types.ts
2
- var OidcScopes = /* @__PURE__ */ ((OidcScopes2) => {
3
- OidcScopes2["openid"] = "openid";
4
- OidcScopes2["profile"] = "profile";
5
- OidcScopes2["email"] = "email";
6
- OidcScopes2["phone"] = "phone";
7
- OidcScopes2["address"] = "address";
8
- OidcScopes2["offline_access"] = "offline_access";
9
- return OidcScopes2;
10
- })(OidcScopes || {});
11
- export {
12
- OidcScopes
13
- };
1
+ //#region src/oauth2/types.ts
2
+ let OidcScopes = /* @__PURE__ */ function(OidcScopes) {
3
+ OidcScopes["openid"] = "openid";
4
+ OidcScopes["profile"] = "profile";
5
+ OidcScopes["email"] = "email";
6
+ OidcScopes["phone"] = "phone";
7
+ OidcScopes["address"] = "address";
8
+ OidcScopes["offline_access"] = "offline_access";
9
+ return OidcScopes;
10
+ }({});
11
+ //#endregion
12
+ export { OidcScopes };
13
+
14
14
  //# sourceMappingURL=types.mjs.map