@absolutejs/auth 0.11.3 → 0.13.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.
package/dist/index.js CHANGED
@@ -128,6 +128,113 @@ var createRandomBase64UrlGenerator = (length) => () => {
128
128
  var generateCodeVerifier = createRandomBase64UrlGenerator(NUM_GENERATOR_BYTES);
129
129
  var generateState = createRandomBase64UrlGenerator(NUM_GENERATOR_BYTES);
130
130
  var base64Url = (input) => encodeBase64(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
131
+ var anilistProfileQuery = `query {
132
+ Viewer {
133
+ id
134
+ name
135
+ about
136
+ avatar {
137
+ large
138
+ medium
139
+ }
140
+ bannerImage
141
+ siteUrl
142
+ createdAt
143
+ updatedAt
144
+ donatorTier
145
+ donatorBadge
146
+ unreadNotificationCount
147
+ options {
148
+ titleLanguage
149
+ displayAdultContent
150
+ airingNotifications
151
+ profileColor
152
+ activityMergeTime
153
+ staffNameLanguage
154
+ }
155
+ mediaListOptions {
156
+ scoreFormat
157
+ rowOrder
158
+ animeList {
159
+ sectionOrder
160
+ customLists
161
+ advancedScoringEnabled
162
+ }
163
+ mangaList {
164
+ sectionOrder
165
+ customLists
166
+ advancedScoringEnabled
167
+ }
168
+ }
169
+ statistics {
170
+ anime {
171
+ count
172
+ meanScore
173
+ minutesWatched
174
+ episodesWatched
175
+ }
176
+ manga {
177
+ count
178
+ meanScore
179
+ chaptersRead
180
+ volumesRead
181
+ }
182
+ }
183
+ favourites {
184
+ anime {
185
+ nodes {
186
+ id
187
+ title {
188
+ romaji
189
+ english
190
+ }
191
+ siteUrl
192
+ }
193
+ }
194
+ manga {
195
+ nodes {
196
+ id
197
+ title {
198
+ romaji
199
+ english
200
+ }
201
+ siteUrl
202
+ }
203
+ }
204
+ characters {
205
+ nodes {
206
+ id
207
+ name {
208
+ full
209
+ }
210
+ image {
211
+ large
212
+ }
213
+ }
214
+ }
215
+ staff {
216
+ nodes {
217
+ id
218
+ name {
219
+ full
220
+ }
221
+ image {
222
+ large
223
+ }
224
+ }
225
+ }
226
+ studios {
227
+ nodes {
228
+ id
229
+ name
230
+ siteUrl
231
+ }
232
+ }
233
+ }
234
+ isFollower
235
+ isFollowing
236
+ }
237
+ }`;
131
238
  var isValidProviderOption = (option) => Object.hasOwn(providers, option);
132
239
  var isRefreshableProviderOption = (option) => {
133
240
  if (!isValidProviderOption(option))
@@ -167,10 +274,29 @@ var hasClientSecret = (credentials) => {
167
274
  const secret = Reflect.get(credentials, "clientSecret");
168
275
  return typeof secret === "string";
169
276
  };
277
+ var isObject = (x) => x !== null && typeof x === "object" && !Array.isArray(x) && Object.prototype.toString.call(x) === "[object Object]";
278
+ var extractPropFromIdentity = (identity, keys) => {
279
+ let value = identity;
280
+ for (const key of keys) {
281
+ if (!isObject(value)) {
282
+ throw new Error(`Invalid identity data shape: expected object, got ${typeof value}`);
283
+ }
284
+ value = value[key];
285
+ }
286
+ return value;
287
+ };
288
+ var extractSubFromOIDCIdentity = (identity) => {
289
+ const sub = extractPropFromIdentity(identity, ["sub"]);
290
+ if (typeof sub !== "string") {
291
+ throw new Error("Invalid identity data shape");
292
+ }
293
+ return sub;
294
+ };
170
295
  var defineProviders = (providers2) => providers2;
171
296
  var providers = defineProviders({
172
297
  "42": {
173
298
  authorizationUrl: "https://api.intra.42.fr/oauth/authorize",
299
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
174
300
  isOIDC: false,
175
301
  isRefreshable: true,
176
302
  profileRequest: {
@@ -188,6 +314,7 @@ var providers = defineProviders({
188
314
  },
189
315
  amazoncognito: {
190
316
  authorizationUrl: "https://${domain}/oauth2/authorize",
317
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
191
318
  isOIDC: true,
192
319
  isRefreshable: true,
193
320
  PKCEMethod: "S256",
@@ -212,12 +339,23 @@ var providers = defineProviders({
212
339
  },
213
340
  anilist: {
214
341
  authorizationUrl: "https://anilist.co/api/v2/oauth/authorize",
342
+ extractSubjectFromIdentity(identity) {
343
+ const subject = extractPropFromIdentity(identity, [
344
+ "data",
345
+ "Viewer",
346
+ "id"
347
+ ]);
348
+ if (typeof subject !== "number") {
349
+ throw new Error("Invalid identity data shape");
350
+ }
351
+ return subject;
352
+ },
215
353
  isOIDC: false,
216
354
  isRefreshable: true,
217
355
  profileRequest: {
218
356
  authIn: "header",
219
357
  body: {
220
- query: `query { Viewer { id name } }`
358
+ query: anilistProfileQuery
221
359
  },
222
360
  encoding: "application/json",
223
361
  headers: {
@@ -236,6 +374,7 @@ var providers = defineProviders({
236
374
  },
237
375
  apple: {
238
376
  authorizationUrl: "https://appleid.apple.com/auth/authorize",
377
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
239
378
  isOIDC: true,
240
379
  isRefreshable: true,
241
380
  PKCEMethod: "S256",
@@ -257,6 +396,13 @@ var providers = defineProviders({
257
396
  createAuthorizationURLSearchParams: {
258
397
  audience: "api.atlassian.com"
259
398
  },
399
+ extractSubjectFromIdentity(identity) {
400
+ const subject = extractPropFromIdentity(identity, ["account_id"]);
401
+ if (typeof subject !== "string") {
402
+ throw new Error("Invalid identity data shape");
403
+ }
404
+ return subject;
405
+ },
260
406
  isOIDC: false,
261
407
  isRefreshable: true,
262
408
  profileRequest: {
@@ -274,6 +420,7 @@ var providers = defineProviders({
274
420
  },
275
421
  auth0: {
276
422
  authorizationUrl: (config) => `https://${config.domain}/authorize`,
423
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
277
424
  isOIDC: true,
278
425
  isRefreshable: true,
279
426
  PKCEMethod: "S256",
@@ -301,6 +448,7 @@ var providers = defineProviders({
301
448
  },
302
449
  authentik: {
303
450
  authorizationUrl: (config) => `https://${config.baseURL}/oauth/authorize`,
451
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
304
452
  isOIDC: true,
305
453
  isRefreshable: true,
306
454
  PKCEMethod: "S256",
@@ -319,6 +467,7 @@ var providers = defineProviders({
319
467
  },
320
468
  autodesk: {
321
469
  authorizationUrl: "https://developer.api.autodesk.com/authentication/v2/authorize",
470
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
322
471
  isOIDC: true,
323
472
  isRefreshable: true,
324
473
  PKCEMethod: "S256",
@@ -337,6 +486,7 @@ var providers = defineProviders({
337
486
  },
338
487
  battlenet: {
339
488
  authorizationUrl: "https://oauth.battle.net/authorize",
489
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
340
490
  isOIDC: true,
341
491
  isRefreshable: false,
342
492
  profileRequest: {
@@ -354,6 +504,13 @@ var providers = defineProviders({
354
504
  },
355
505
  bitbucket: {
356
506
  authorizationUrl: "https://bitbucket.org/site/oauth2/authorize",
507
+ extractSubjectFromIdentity(identity) {
508
+ const subject = extractPropFromIdentity(identity, ["uuid"]);
509
+ if (typeof subject !== "string") {
510
+ throw new Error("Invalid identity data shape");
511
+ }
512
+ return subject;
513
+ },
357
514
  isOIDC: false,
358
515
  isRefreshable: true,
359
516
  profileRequest: {
@@ -371,6 +528,13 @@ var providers = defineProviders({
371
528
  },
372
529
  box: {
373
530
  authorizationUrl: "https://account.box.com/api/oauth2/authorize",
531
+ extractSubjectFromIdentity(identity) {
532
+ const subject = extractPropFromIdentity(identity, ["id"]);
533
+ if (typeof subject !== "string") {
534
+ throw new Error("Invalid identity data shape");
535
+ }
536
+ return subject;
537
+ },
374
538
  isOIDC: false,
375
539
  isRefreshable: true,
376
540
  profileRequest: {
@@ -394,6 +558,16 @@ var providers = defineProviders({
394
558
  },
395
559
  bungie: {
396
560
  authorizationUrl: "https://www.bungie.net/en/OAuth/Authorize",
561
+ extractSubjectFromIdentity(identity) {
562
+ const subject = extractPropFromIdentity(identity, [
563
+ "Response",
564
+ "membershipId"
565
+ ]);
566
+ if (typeof subject !== "string") {
567
+ throw new Error("Invalid identity data shape");
568
+ }
569
+ return subject;
570
+ },
397
571
  isOIDC: false,
398
572
  isRefreshable: true,
399
573
  profileRequest: {
@@ -414,6 +588,13 @@ var providers = defineProviders({
414
588
  },
415
589
  coinbase: {
416
590
  authorizationUrl: "https://www.coinbase.com/oauth/authorize",
591
+ extractSubjectFromIdentity(identity) {
592
+ const subject = extractPropFromIdentity(identity, ["data", "id"]);
593
+ if (typeof subject !== "string") {
594
+ throw new Error("Invalid identity data shape");
595
+ }
596
+ return subject;
597
+ },
417
598
  isOIDC: false,
418
599
  isRefreshable: true,
419
600
  profileRequest: {
@@ -431,7 +612,8 @@ var providers = defineProviders({
431
612
  },
432
613
  discord: {
433
614
  authorizationUrl: "https://discord.com/api/oauth2/authorize",
434
- isOIDC: false,
615
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
616
+ isOIDC: true,
435
617
  isRefreshable: true,
436
618
  PKCEMethod: "S256",
437
619
  profileRequest: {
@@ -449,6 +631,13 @@ var providers = defineProviders({
449
631
  },
450
632
  donationalerts: {
451
633
  authorizationUrl: "https://www.donationalerts.com/oauth/authorize",
634
+ extractSubjectFromIdentity(identity) {
635
+ const subject = extractPropFromIdentity(identity, ["data", "id"]);
636
+ if (typeof subject !== "number") {
637
+ throw new Error("Invalid identity data shape");
638
+ }
639
+ return subject;
640
+ },
452
641
  isOIDC: false,
453
642
  isRefreshable: true,
454
643
  profileRequest: {
@@ -466,6 +655,13 @@ var providers = defineProviders({
466
655
  },
467
656
  dribbble: {
468
657
  authorizationUrl: "https://dribbble.com/oauth/authorize",
658
+ extractSubjectFromIdentity(identity) {
659
+ const subject = extractPropFromIdentity(identity, ["id"]);
660
+ if (typeof subject !== "number") {
661
+ throw new Error("Invalid identity data shape");
662
+ }
663
+ return subject;
664
+ },
469
665
  isOIDC: false,
470
666
  isRefreshable: false,
471
667
  profileRequest: {
@@ -483,6 +679,13 @@ var providers = defineProviders({
483
679
  },
484
680
  dropbox: {
485
681
  authorizationUrl: "https://www.dropbox.com/oauth2/authorize",
682
+ extractSubjectFromIdentity(identity) {
683
+ const subject = extractPropFromIdentity(identity, ["account_id"]);
684
+ if (typeof subject !== "string") {
685
+ throw new Error("Invalid identity data shape");
686
+ }
687
+ return subject;
688
+ },
486
689
  isOIDC: false,
487
690
  isRefreshable: true,
488
691
  profileRequest: {
@@ -505,6 +708,13 @@ var providers = defineProviders({
505
708
  },
506
709
  epicgames: {
507
710
  authorizationUrl: "https://www.epicgames.com/id/authorize",
711
+ extractSubjectFromIdentity(identity) {
712
+ const subject = extractPropFromIdentity(identity, ["account_id"]);
713
+ if (typeof subject !== "string") {
714
+ throw new Error("Invalid identity data shape");
715
+ }
716
+ return subject;
717
+ },
508
718
  isOIDC: false,
509
719
  isRefreshable: true,
510
720
  profileRequest: {
@@ -522,6 +732,17 @@ var providers = defineProviders({
522
732
  },
523
733
  etsy: {
524
734
  authorizationUrl: "https://www.etsy.com/oauth/connect",
735
+ extractSubjectFromIdentity(identity) {
736
+ const subject = extractPropFromIdentity(identity, [
737
+ "results",
738
+ "0",
739
+ "user_id"
740
+ ]);
741
+ if (typeof subject !== "number") {
742
+ throw new Error("Invalid identity data shape");
743
+ }
744
+ return subject;
745
+ },
525
746
  isOIDC: false,
526
747
  isRefreshable: true,
527
748
  profileRequest: {
@@ -539,6 +760,7 @@ var providers = defineProviders({
539
760
  },
540
761
  facebook: {
541
762
  authorizationUrl: "https://www.facebook.com/v16.0/dialog/oauth",
763
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
542
764
  isOIDC: true,
543
765
  isRefreshable: false,
544
766
  PKCEMethod: "S256",
@@ -558,6 +780,15 @@ var providers = defineProviders({
558
780
  },
559
781
  figma: {
560
782
  authorizationUrl: "https://www.figma.com/oauth",
783
+ extractSubjectFromIdentity(identity) {
784
+ const subject = extractPropFromIdentity(identity, [
785
+ "user_id_string"
786
+ ]);
787
+ if (typeof subject !== "string") {
788
+ throw new Error("Invalid identity data shape");
789
+ }
790
+ return subject;
791
+ },
561
792
  isOIDC: false,
562
793
  isRefreshable: true,
563
794
  PKCEMethod: "S256",
@@ -576,6 +807,7 @@ var providers = defineProviders({
576
807
  },
577
808
  gitea: {
578
809
  authorizationUrl: (config) => `${config.baseURL}/login/oauth/authorize`,
810
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
579
811
  isOIDC: true,
580
812
  isRefreshable: true,
581
813
  PKCEMethod: "S256",
@@ -594,6 +826,13 @@ var providers = defineProviders({
594
826
  },
595
827
  github: {
596
828
  authorizationUrl: "https://github.com/login/oauth/authorize",
829
+ extractSubjectFromIdentity(identity) {
830
+ const subject = extractPropFromIdentity(identity, ["id"]);
831
+ if (typeof subject !== "number") {
832
+ throw new Error("Invalid identity data shape");
833
+ }
834
+ return subject;
835
+ },
597
836
  isOIDC: false,
598
837
  isRefreshable: false,
599
838
  profileRequest: {
@@ -611,6 +850,7 @@ var providers = defineProviders({
611
850
  },
612
851
  gitlab: {
613
852
  authorizationUrl: (config) => `${config.baseURL}/oauth/authorize`,
853
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
614
854
  isOIDC: true,
615
855
  isRefreshable: true,
616
856
  PKCEMethod: "S256",
@@ -635,6 +875,7 @@ var providers = defineProviders({
635
875
  },
636
876
  google: {
637
877
  authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
878
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
638
879
  isOIDC: true,
639
880
  isRefreshable: true,
640
881
  PKCEMethod: "S256",
@@ -660,6 +901,7 @@ var providers = defineProviders({
660
901
  },
661
902
  intuit: {
662
903
  authorizationUrl: "https://appcenter.intuit.com/connect/oauth2",
904
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
663
905
  isOIDC: true,
664
906
  isRefreshable: true,
665
907
  profileRequest: {
@@ -686,6 +928,7 @@ var providers = defineProviders({
686
928
  },
687
929
  kakao: {
688
930
  authorizationUrl: "https://kauth.kakao.com/oauth/authorize",
931
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
689
932
  isOIDC: true,
690
933
  isRefreshable: true,
691
934
  PKCEMethod: "S256",
@@ -704,6 +947,7 @@ var providers = defineProviders({
704
947
  },
705
948
  keycloak: {
706
949
  authorizationUrl: (config) => `${config.realmURL}/protocol/openid-connect/auth`,
950
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
707
951
  isOIDC: true,
708
952
  isRefreshable: true,
709
953
  PKCEMethod: "S256",
@@ -728,6 +972,16 @@ var providers = defineProviders({
728
972
  },
729
973
  kick: {
730
974
  authorizationUrl: "https://id.kick.com/oauth/authorize",
975
+ extractSubjectFromIdentity(identity) {
976
+ const subject = extractPropFromIdentity(identity, [
977
+ "data",
978
+ "user_id"
979
+ ]);
980
+ if (typeof subject !== "number") {
981
+ throw new Error("Invalid identity data shape");
982
+ }
983
+ return subject;
984
+ },
731
985
  isOIDC: false,
732
986
  isRefreshable: true,
733
987
  PKCEMethod: "S256",
@@ -735,7 +989,7 @@ var providers = defineProviders({
735
989
  authIn: "header",
736
990
  encoding: "application/json",
737
991
  method: "GET",
738
- url: "https://id.kick.com/v1/user"
992
+ url: "https://api.kick.com/public/v1/users"
739
993
  },
740
994
  revocationRequest: {
741
995
  authIn: "body",
@@ -743,7 +997,7 @@ var providers = defineProviders({
743
997
  tokenParamName: "token",
744
998
  url: "https://id.kick.com/oauth/revoke"
745
999
  },
746
- scopeRequired: false,
1000
+ scopeRequired: true,
747
1001
  tokenRequest: {
748
1002
  authIn: "body",
749
1003
  encoding: "application/x-www-form-urlencoded",
@@ -752,6 +1006,13 @@ var providers = defineProviders({
752
1006
  },
753
1007
  lichess: {
754
1008
  authorizationUrl: "https://lichess.org/oauth/authorize",
1009
+ extractSubjectFromIdentity(identity) {
1010
+ const subject = extractPropFromIdentity(identity, ["id"]);
1011
+ if (typeof subject !== "string") {
1012
+ throw new Error("Invalid identity data shape");
1013
+ }
1014
+ return subject;
1015
+ },
755
1016
  isOIDC: false,
756
1017
  isRefreshable: false,
757
1018
  PKCEMethod: "S256",
@@ -770,6 +1031,7 @@ var providers = defineProviders({
770
1031
  },
771
1032
  line: {
772
1033
  authorizationUrl: "https://access.line.me/oauth2/v2.1/authorize",
1034
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
773
1035
  isOIDC: true,
774
1036
  isRefreshable: true,
775
1037
  PKCEMethod: "S256",
@@ -788,6 +1050,17 @@ var providers = defineProviders({
788
1050
  },
789
1051
  linear: {
790
1052
  authorizationUrl: "https://linear.app/oauth/authorize",
1053
+ extractSubjectFromIdentity(identity) {
1054
+ const subject = extractPropFromIdentity(identity, [
1055
+ "data",
1056
+ "viewer",
1057
+ "id"
1058
+ ]);
1059
+ if (typeof subject !== "string") {
1060
+ throw new Error("Invalid identity data shape");
1061
+ }
1062
+ return subject;
1063
+ },
791
1064
  isOIDC: false,
792
1065
  isRefreshable: false,
793
1066
  profileRequest: {
@@ -817,6 +1090,7 @@ var providers = defineProviders({
817
1090
  },
818
1091
  linkedin: {
819
1092
  authorizationUrl: "https://www.linkedin.com/oauth/v2/authorization",
1093
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
820
1094
  isOIDC: true,
821
1095
  isRefreshable: true,
822
1096
  PKCEMethod: "S256",
@@ -835,6 +1109,13 @@ var providers = defineProviders({
835
1109
  },
836
1110
  mastodon: {
837
1111
  authorizationUrl: (config) => `${config.baseURL}/oauth/authorize`,
1112
+ extractSubjectFromIdentity(identity) {
1113
+ const subject = extractPropFromIdentity(identity, ["id"]);
1114
+ if (typeof subject !== "string") {
1115
+ throw new Error("Invalid identity data shape");
1116
+ }
1117
+ return subject;
1118
+ },
838
1119
  isOIDC: false,
839
1120
  isRefreshable: false,
840
1121
  PKCEMethod: "S256",
@@ -859,6 +1140,13 @@ var providers = defineProviders({
859
1140
  },
860
1141
  mercadolibre: {
861
1142
  authorizationUrl: "https://auth.mercadolibre.com/authorization",
1143
+ extractSubjectFromIdentity(identity) {
1144
+ const subject = extractPropFromIdentity(identity, ["id"]);
1145
+ if (typeof subject !== "string") {
1146
+ throw new Error("Invalid identity data shape");
1147
+ }
1148
+ return subject;
1149
+ },
862
1150
  isOIDC: false,
863
1151
  isRefreshable: true,
864
1152
  PKCEMethod: "S256",
@@ -877,6 +1165,13 @@ var providers = defineProviders({
877
1165
  },
878
1166
  mercadopago: {
879
1167
  authorizationUrl: "https://auth.mercadopago.com/authorization",
1168
+ extractSubjectFromIdentity(identity) {
1169
+ const subject = extractPropFromIdentity(identity, ["id"]);
1170
+ if (typeof subject !== "string") {
1171
+ throw new Error("Invalid identity data shape");
1172
+ }
1173
+ return subject;
1174
+ },
880
1175
  isOIDC: false,
881
1176
  isRefreshable: true,
882
1177
  profileRequest: {
@@ -894,6 +1189,7 @@ var providers = defineProviders({
894
1189
  },
895
1190
  microsoftentraid: {
896
1191
  authorizationUrl: (config) => `https://${config.tenantId}.b2clogin.com/${config.tenantId}/oauth2/v2.0/authorize`,
1192
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
897
1193
  isOIDC: true,
898
1194
  isRefreshable: true,
899
1195
  PKCEMethod: "S256",
@@ -912,6 +1208,13 @@ var providers = defineProviders({
912
1208
  },
913
1209
  myanimelist: {
914
1210
  authorizationUrl: "https://myanimelist.net/v1/oauth2/authorize",
1211
+ extractSubjectFromIdentity(identity) {
1212
+ const subject = extractPropFromIdentity(identity, ["id"]);
1213
+ if (typeof subject !== "number") {
1214
+ throw new Error("Invalid identity data shape");
1215
+ }
1216
+ return subject;
1217
+ },
915
1218
  isOIDC: false,
916
1219
  isRefreshable: true,
917
1220
  PKCEMethod: "plain",
@@ -930,6 +1233,16 @@ var providers = defineProviders({
930
1233
  },
931
1234
  naver: {
932
1235
  authorizationUrl: "https://nid.naver.com/oauth2.0/authorize",
1236
+ extractSubjectFromIdentity(identity) {
1237
+ const subject = extractPropFromIdentity(identity, [
1238
+ "response",
1239
+ "id"
1240
+ ]);
1241
+ if (typeof subject !== "string") {
1242
+ throw new Error("Invalid identity data shape");
1243
+ }
1244
+ return subject;
1245
+ },
933
1246
  isOIDC: false,
934
1247
  isRefreshable: true,
935
1248
  profileRequest: {
@@ -947,6 +1260,13 @@ var providers = defineProviders({
947
1260
  },
948
1261
  notion: {
949
1262
  authorizationUrl: "https://api.notion.com/v1/oauth/authorize",
1263
+ extractSubjectFromIdentity(identity) {
1264
+ const subject = extractPropFromIdentity(identity, ["id"]);
1265
+ if (typeof subject !== "string") {
1266
+ throw new Error("Invalid identity data shape");
1267
+ }
1268
+ return subject;
1269
+ },
950
1270
  isOIDC: false,
951
1271
  isRefreshable: false,
952
1272
  profileRequest: {
@@ -967,6 +1287,7 @@ var providers = defineProviders({
967
1287
  },
968
1288
  okta: {
969
1289
  authorizationUrl: (config) => `https://${config.domain}/oauth2/default/v1/authorize`,
1290
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
970
1291
  isOIDC: true,
971
1292
  isRefreshable: true,
972
1293
  PKCEMethod: "S256",
@@ -991,6 +1312,13 @@ var providers = defineProviders({
991
1312
  },
992
1313
  osu: {
993
1314
  authorizationUrl: "https://osu.ppy.sh/oauth/authorize",
1315
+ extractSubjectFromIdentity(identity) {
1316
+ const subject = extractPropFromIdentity(identity, ["id"]);
1317
+ if (typeof subject !== "number") {
1318
+ throw new Error("Invalid identity data shape");
1319
+ }
1320
+ return subject;
1321
+ },
994
1322
  isOIDC: false,
995
1323
  isRefreshable: true,
996
1324
  profileRequest: {
@@ -1008,6 +1336,13 @@ var providers = defineProviders({
1008
1336
  },
1009
1337
  patreon: {
1010
1338
  authorizationUrl: "https://www.patreon.com/oauth2/authorize",
1339
+ extractSubjectFromIdentity(identity) {
1340
+ const subject = extractPropFromIdentity(identity, ["data", "id"]);
1341
+ if (typeof subject !== "string") {
1342
+ throw new Error("Invalid identity data shape");
1343
+ }
1344
+ return subject;
1345
+ },
1011
1346
  isOIDC: false,
1012
1347
  isRefreshable: true,
1013
1348
  profileRequest: {
@@ -1025,6 +1360,7 @@ var providers = defineProviders({
1025
1360
  },
1026
1361
  polar: {
1027
1362
  authorizationUrl: "https://polar.sh/oauth2/authorize",
1363
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1028
1364
  isOIDC: true,
1029
1365
  isRefreshable: true,
1030
1366
  PKCEMethod: "S256",
@@ -1049,6 +1385,13 @@ var providers = defineProviders({
1049
1385
  },
1050
1386
  polaraccesslink: {
1051
1387
  authorizationUrl: "https://flow.polar.com/oauth2/authorization",
1388
+ extractSubjectFromIdentity(identity) {
1389
+ const subject = extractPropFromIdentity(identity, ["x_user_id"]);
1390
+ if (typeof subject !== "number") {
1391
+ throw new Error("Invalid identity data shape");
1392
+ }
1393
+ return subject;
1394
+ },
1052
1395
  isOIDC: false,
1053
1396
  isRefreshable: false,
1054
1397
  PKCEMethod: "S256",
@@ -1067,6 +1410,13 @@ var providers = defineProviders({
1067
1410
  },
1068
1411
  polarteampro: {
1069
1412
  authorizationUrl: "https://auth.polar.com/oauth/authorize",
1413
+ extractSubjectFromIdentity(identity) {
1414
+ const subject = extractPropFromIdentity(identity, ["x_user_id"]);
1415
+ if (typeof subject !== "number") {
1416
+ throw new Error("Invalid identity data shape");
1417
+ }
1418
+ return subject;
1419
+ },
1070
1420
  isOIDC: false,
1071
1421
  isRefreshable: true,
1072
1422
  PKCEMethod: "S256",
@@ -1085,6 +1435,13 @@ var providers = defineProviders({
1085
1435
  },
1086
1436
  reddit: {
1087
1437
  authorizationUrl: "https://www.reddit.com/api/v1/authorize",
1438
+ extractSubjectFromIdentity(identity) {
1439
+ const subject = extractPropFromIdentity(identity, ["id"]);
1440
+ if (typeof subject !== "string") {
1441
+ throw new Error("Invalid identity data shape");
1442
+ }
1443
+ return subject;
1444
+ },
1088
1445
  isOIDC: false,
1089
1446
  isRefreshable: true,
1090
1447
  profileRequest: {
@@ -1110,6 +1467,7 @@ var providers = defineProviders({
1110
1467
  },
1111
1468
  roblox: {
1112
1469
  authorizationUrl: "https://apis.roblox.com/oauth/v1/authorize",
1470
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1113
1471
  isOIDC: true,
1114
1472
  isRefreshable: true,
1115
1473
  PKCEMethod: "S256",
@@ -1128,6 +1486,7 @@ var providers = defineProviders({
1128
1486
  },
1129
1487
  salesforce: {
1130
1488
  authorizationUrl: "https://login.salesforce.com/services/oauth2/authorize",
1489
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1131
1490
  isOIDC: true,
1132
1491
  isRefreshable: true,
1133
1492
  PKCEMethod: "S256",
@@ -1151,6 +1510,13 @@ var providers = defineProviders({
1151
1510
  },
1152
1511
  shikimori: {
1153
1512
  authorizationUrl: "https://shikimori.org/oauth/authorize",
1513
+ extractSubjectFromIdentity(identity) {
1514
+ const subject = extractPropFromIdentity(identity, ["id"]);
1515
+ if (typeof subject !== "number") {
1516
+ throw new Error("Invalid identity data shape");
1517
+ }
1518
+ return subject;
1519
+ },
1154
1520
  isOIDC: false,
1155
1521
  isRefreshable: true,
1156
1522
  profileRequest: {
@@ -1168,6 +1534,7 @@ var providers = defineProviders({
1168
1534
  },
1169
1535
  slack: {
1170
1536
  authorizationUrl: "https://slack.com/openid/connect/authorize",
1537
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1171
1538
  isOIDC: true,
1172
1539
  isRefreshable: true,
1173
1540
  profileRequest: {
@@ -1191,6 +1558,13 @@ var providers = defineProviders({
1191
1558
  },
1192
1559
  spotify: {
1193
1560
  authorizationUrl: "https://accounts.spotify.com/authorize",
1561
+ extractSubjectFromIdentity(identity) {
1562
+ const subject = extractPropFromIdentity(identity, ["id"]);
1563
+ if (typeof subject !== "string") {
1564
+ throw new Error("Invalid identity data shape");
1565
+ }
1566
+ return subject;
1567
+ },
1194
1568
  isOIDC: false,
1195
1569
  isRefreshable: true,
1196
1570
  PKCEMethod: "S256",
@@ -1209,6 +1583,17 @@ var providers = defineProviders({
1209
1583
  },
1210
1584
  startgg: {
1211
1585
  authorizationUrl: "https://start.gg/oauth/authorize",
1586
+ extractSubjectFromIdentity(identity) {
1587
+ const subject = extractPropFromIdentity(identity, [
1588
+ "data",
1589
+ "currentUser",
1590
+ "id"
1591
+ ]);
1592
+ if (typeof subject !== "string") {
1593
+ throw new Error("Invalid identity data shape");
1594
+ }
1595
+ return subject;
1596
+ },
1212
1597
  isOIDC: false,
1213
1598
  isRefreshable: true,
1214
1599
  profileRequest: {
@@ -1233,6 +1618,13 @@ var providers = defineProviders({
1233
1618
  },
1234
1619
  strava: {
1235
1620
  authorizationUrl: "https://www.strava.com/oauth/authorize",
1621
+ extractSubjectFromIdentity(identity) {
1622
+ const subject = extractPropFromIdentity(identity, ["id"]);
1623
+ if (typeof subject !== "number") {
1624
+ throw new Error("Invalid identity data shape");
1625
+ }
1626
+ return subject;
1627
+ },
1236
1628
  isOIDC: false,
1237
1629
  isRefreshable: true,
1238
1630
  PKCEMethod: "S256",
@@ -1260,6 +1652,13 @@ var providers = defineProviders({
1260
1652
  },
1261
1653
  synology: {
1262
1654
  authorizationUrl: (config) => `${config.baseURL}/webman/sso/SSOOauth.cgi?client_id=${config.clientId}&response_type=code&redirect_uri=${config.redirectUri}`,
1655
+ extractSubjectFromIdentity(identity) {
1656
+ const subject = extractPropFromIdentity(identity, ["data", "id"]);
1657
+ if (typeof subject !== "string") {
1658
+ throw new Error("Invalid identity data shape");
1659
+ }
1660
+ return subject;
1661
+ },
1263
1662
  isOIDC: false,
1264
1663
  isRefreshable: false,
1265
1664
  profileRequest: {
@@ -1280,6 +1679,16 @@ var providers = defineProviders({
1280
1679
  createAuthorizationURLSearchParams: (config) => ({
1281
1680
  client_key: config.clientId
1282
1681
  }),
1682
+ extractSubjectFromIdentity(identity) {
1683
+ const subject = extractPropFromIdentity(identity, [
1684
+ "data",
1685
+ "open_id"
1686
+ ]);
1687
+ if (typeof subject !== "string") {
1688
+ throw new Error("Invalid identity data shape");
1689
+ }
1690
+ return subject;
1691
+ },
1283
1692
  isOIDC: false,
1284
1693
  isRefreshable: true,
1285
1694
  PKCEMethod: "S256",
@@ -1304,6 +1713,13 @@ var providers = defineProviders({
1304
1713
  },
1305
1714
  tiltify: {
1306
1715
  authorizationUrl: "https://v5api.tiltify.com/oauth/authorize",
1716
+ extractSubjectFromIdentity(identity) {
1717
+ const subject = extractPropFromIdentity(identity, ["data", "id"]);
1718
+ if (typeof subject !== "string") {
1719
+ throw new Error("Invalid identity data shape");
1720
+ }
1721
+ return subject;
1722
+ },
1307
1723
  isOIDC: false,
1308
1724
  isRefreshable: true,
1309
1725
  profileRequest: {
@@ -1321,6 +1737,17 @@ var providers = defineProviders({
1321
1737
  },
1322
1738
  tumblr: {
1323
1739
  authorizationUrl: "https://www.tumblr.com/oauth2/authorize",
1740
+ extractSubjectFromIdentity(identity) {
1741
+ const subject = extractPropFromIdentity(identity, [
1742
+ "response",
1743
+ "user",
1744
+ "name"
1745
+ ]);
1746
+ if (typeof subject !== "string") {
1747
+ throw new Error("Invalid identity data shape");
1748
+ }
1749
+ return subject;
1750
+ },
1324
1751
  isOIDC: false,
1325
1752
  isRefreshable: true,
1326
1753
  profileRequest: {
@@ -1338,6 +1765,7 @@ var providers = defineProviders({
1338
1765
  },
1339
1766
  twitch: {
1340
1767
  authorizationUrl: "https://id.twitch.tv/oauth2/authorize",
1768
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1341
1769
  isOIDC: true,
1342
1770
  isRefreshable: true,
1343
1771
  profileRequest: {
@@ -1367,6 +1795,13 @@ var providers = defineProviders({
1367
1795
  },
1368
1796
  twitter: {
1369
1797
  authorizationUrl: "https://twitter.com/i/oauth2/authorize",
1798
+ extractSubjectFromIdentity(identity) {
1799
+ const subject = extractPropFromIdentity(identity, ["data", "id"]);
1800
+ if (typeof subject !== "string") {
1801
+ throw new Error("Invalid identity data shape");
1802
+ }
1803
+ return subject;
1804
+ },
1370
1805
  isOIDC: false,
1371
1806
  isRefreshable: true,
1372
1807
  PKCEMethod: "S256",
@@ -1390,6 +1825,17 @@ var providers = defineProviders({
1390
1825
  },
1391
1826
  vk: {
1392
1827
  authorizationUrl: "https://oauth.vk.com/authorize",
1828
+ extractSubjectFromIdentity(identity) {
1829
+ const subject = extractPropFromIdentity(identity, [
1830
+ "response",
1831
+ "0",
1832
+ "id"
1833
+ ]);
1834
+ if (typeof subject !== "number") {
1835
+ throw new Error("Invalid identity data shape");
1836
+ }
1837
+ return subject;
1838
+ },
1393
1839
  isOIDC: false,
1394
1840
  isRefreshable: false,
1395
1841
  profileRequest: {
@@ -1407,6 +1853,16 @@ var providers = defineProviders({
1407
1853
  },
1408
1854
  withings: {
1409
1855
  authorizationUrl: "https://account.withings.com/oauth2_user/authorize2",
1856
+ extractSubjectFromIdentity(identity) {
1857
+ const subject = extractPropFromIdentity(identity, [
1858
+ "body",
1859
+ "userid"
1860
+ ]);
1861
+ if (typeof subject !== "number") {
1862
+ throw new Error("Invalid identity data shape");
1863
+ }
1864
+ return subject;
1865
+ },
1410
1866
  isOIDC: false,
1411
1867
  isRefreshable: true,
1412
1868
  profileRequest: {
@@ -1460,6 +1916,7 @@ var providers = defineProviders({
1460
1916
  },
1461
1917
  workos: {
1462
1918
  authorizationUrl: "https://api.workos.com/sso/authorize",
1919
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1463
1920
  isOIDC: true,
1464
1921
  isRefreshable: true,
1465
1922
  PKCEMethod: "S256",
@@ -1478,6 +1935,7 @@ var providers = defineProviders({
1478
1935
  },
1479
1936
  yahoo: {
1480
1937
  authorizationUrl: "https://api.login.yahoo.com/oauth2/request_auth",
1938
+ extractSubjectFromIdentity: extractSubFromOIDCIdentity,
1481
1939
  isOIDC: true,
1482
1940
  isRefreshable: true,
1483
1941
  PKCEMethod: "S256",
@@ -1505,6 +1963,13 @@ var providers = defineProviders({
1505
1963
  device_id: crypto.randomUUID(),
1506
1964
  device_name: `${navigator.platform ?? "Unknown"} \u2014 ${(navigator.userAgent.split(")")[0] || "").split("(").pop() || "Unknown"}`
1507
1965
  },
1966
+ extractSubjectFromIdentity(identity) {
1967
+ const subject = extractPropFromIdentity(identity, ["id"]);
1968
+ if (typeof subject !== "string") {
1969
+ throw new Error("Invalid identity data shape");
1970
+ }
1971
+ return subject;
1972
+ },
1508
1973
  isOIDC: false,
1509
1974
  isRefreshable: true,
1510
1975
  PKCEMethod: "S256",
@@ -1529,6 +1994,13 @@ var providers = defineProviders({
1529
1994
  },
1530
1995
  zoom: {
1531
1996
  authorizationUrl: "https://zoom.us/oauth/authorize",
1997
+ extractSubjectFromIdentity(identity) {
1998
+ const subject = extractPropFromIdentity(identity, ["id"]);
1999
+ if (typeof subject !== "string") {
2000
+ throw new Error("Invalid identity data shape");
2001
+ }
2002
+ return subject;
2003
+ },
1532
2004
  isOIDC: false,
1533
2005
  isRefreshable: true,
1534
2006
  PKCEMethod: "S256",
@@ -1768,7 +2240,8 @@ var COOKIE_DURATION = SECONDS_IN_A_MINUTE * COOKIE_MINUTES;
1768
2240
  var authorize = ({
1769
2241
  clientProviders,
1770
2242
  authorizeRoute = "/oauth2/:provider/authorization",
1771
- onAuthorizeSuccess
2243
+ onAuthorizeSuccess,
2244
+ onAuthorizeError
1772
2245
  }) => new Elysia().get(authorizeRoute, async ({
1773
2246
  error,
1774
2247
  redirect,
@@ -1786,7 +2259,6 @@ var authorize = ({
1786
2259
  if (!providerConfig)
1787
2260
  return error("Unauthorized", "Client provider not found");
1788
2261
  const { providerInstance, scope, searchParams } = providerConfig;
1789
- const normalizedProvider = provider.toLowerCase();
1790
2262
  const referer = headers["referer"] ?? "/";
1791
2263
  origin_url.set({
1792
2264
  httpOnly: true,
@@ -1802,7 +2274,7 @@ var authorize = ({
1802
2274
  path: "/",
1803
2275
  sameSite: "lax",
1804
2276
  secure: true,
1805
- value: normalizedProvider
2277
+ value: provider
1806
2278
  });
1807
2279
  const currentState = generateState();
1808
2280
  state.set({
@@ -1827,12 +2299,16 @@ var authorize = ({
1827
2299
  try {
1828
2300
  const authorizationURL = await providerInstance.createAuthorizationUrl(codeVerifier ? { codeVerifier, scope, state: currentState } : { scope, state: currentState });
1829
2301
  searchParams?.forEach(([key, value]) => authorizationURL.searchParams.set(key, value));
1830
- onAuthorizeSuccess?.({
2302
+ await onAuthorizeSuccess?.({
1831
2303
  authorizationUrl: authorizationURL,
1832
- authProvider: normalizedProvider
2304
+ authProvider: provider
1833
2305
  });
1834
2306
  return redirect(authorizationURL.toString());
1835
2307
  } catch (err) {
2308
+ await onAuthorizeError?.({
2309
+ authProvider: provider,
2310
+ error: err
2311
+ });
1836
2312
  if (err instanceof Error) {
1837
2313
  return error("Internal Server Error", `${err.message} - ${err.stack ?? ""}`);
1838
2314
  }
@@ -1860,7 +2336,8 @@ var isNonEmptyString = (str) => str !== null && str !== undefined && str.trim()
1860
2336
  var callback = ({
1861
2337
  clientProviders,
1862
2338
  callbackRoute = "/oauth2/callback",
1863
- onCallbackSuccess
2339
+ onCallbackSuccess,
2340
+ onCallbackError
1864
2341
  }) => new Elysia3().use(sessionStore()).get(callbackRoute, async ({
1865
2342
  error,
1866
2343
  redirect,
@@ -1921,6 +2398,11 @@ var callback = ({
1921
2398
  });
1922
2399
  return redirect(originUrl);
1923
2400
  } catch (err) {
2401
+ await onCallbackError?.({
2402
+ authProvider,
2403
+ error: err,
2404
+ originUrl
2405
+ });
1924
2406
  return err instanceof Error ? error("Internal Server Error", `${err.message} - ${err.stack ?? ""}`) : error("Internal Server Error", `Failed to validate authorization code: Unknown error: ${err}`);
1925
2407
  }
1926
2408
  }, {
@@ -1934,7 +2416,8 @@ import { Elysia as Elysia4 } from "elysia";
1934
2416
  var profile = ({
1935
2417
  clientProviders,
1936
2418
  profileRoute = "/oauth2/profile",
1937
- onProfileSuccess
2419
+ onProfileSuccess,
2420
+ onProfileError
1938
2421
  }) => new Elysia4().use(sessionStore()).get(profileRoute, async ({
1939
2422
  error,
1940
2423
  store: { session },
@@ -1969,6 +2452,10 @@ var profile = ({
1969
2452
  });
1970
2453
  return new Response(JSON.stringify(userProfile));
1971
2454
  } catch (err) {
2455
+ await onProfileError?.({
2456
+ authProvider: auth_provider.value,
2457
+ error: err
2458
+ });
1972
2459
  return err instanceof Error ? error("Internal Server Error", `${err.message} - ${err.stack ?? ""}`) : error("Internal Server Error", `Failed to validate authorization code: Unknown error: ${err}`);
1973
2460
  }
1974
2461
  });
@@ -1995,7 +2482,8 @@ import { Elysia as Elysia6 } from "elysia";
1995
2482
  var refresh = ({
1996
2483
  clientProviders,
1997
2484
  refreshRoute = "/oauth2/tokens",
1998
- onRefreshSuccess
2485
+ onRefreshSuccess,
2486
+ onRefreshError
1999
2487
  }) => new Elysia6().use(sessionStore()).post(refreshRoute, async ({
2000
2488
  error,
2001
2489
  store: { session },
@@ -2030,7 +2518,7 @@ var refresh = ({
2030
2518
  }
2031
2519
  try {
2032
2520
  const tokenResponse = await providerInstance.refreshAccessToken(refreshToken);
2033
- onRefreshSuccess?.({
2521
+ await onRefreshSuccess?.({
2034
2522
  authProvider: auth_provider.value,
2035
2523
  tokenResponse
2036
2524
  });
@@ -2038,6 +2526,10 @@ var refresh = ({
2038
2526
  status: 204
2039
2527
  });
2040
2528
  } catch (err) {
2529
+ await onRefreshError?.({
2530
+ authProvider: auth_provider.value,
2531
+ error: err
2532
+ });
2041
2533
  if (err instanceof Error) {
2042
2534
  return error("Internal Server Error", `Failed to refresh token: ${err.message}`);
2043
2535
  }
@@ -2050,7 +2542,8 @@ import { Elysia as Elysia7 } from "elysia";
2050
2542
  var revoke = ({
2051
2543
  clientProviders,
2052
2544
  revokeRoute = "/oauth2/revocation",
2053
- onRevocationSuccess
2545
+ onRevocationSuccess,
2546
+ onRevocationError
2054
2547
  }) => new Elysia7().use(sessionStore()).post(revokeRoute, async ({
2055
2548
  error,
2056
2549
  store: { session },
@@ -2082,7 +2575,7 @@ var revoke = ({
2082
2575
  const { accessToken } = userSession;
2083
2576
  try {
2084
2577
  await providerInstance.revokeToken(accessToken);
2085
- onRevocationSuccess?.({
2578
+ await onRevocationSuccess?.({
2086
2579
  authProvider: auth_provider.value,
2087
2580
  tokenToRevoke: accessToken
2088
2581
  });
@@ -2090,6 +2583,10 @@ var revoke = ({
2090
2583
  status: 204
2091
2584
  });
2092
2585
  } catch (err) {
2586
+ await onRevocationError?.({
2587
+ authProvider: auth_provider.value,
2588
+ error: err
2589
+ });
2093
2590
  if (err instanceof Error) {
2094
2591
  return error("Internal Server Error", `Failed to revoke token: ${err.message}`);
2095
2592
  }
@@ -2117,7 +2614,7 @@ var signout = ({
2117
2614
  return error("Unauthorized", "No user session id found");
2118
2615
  }
2119
2616
  try {
2120
- onSignOut?.({
2617
+ await onSignOut?.({
2121
2618
  authProvider: auth_provider.value,
2122
2619
  session,
2123
2620
  userSessionId: user_session_id.value
@@ -2172,16 +2669,16 @@ var instantiateUserSession = async ({
2172
2669
  getUser,
2173
2670
  createUser
2174
2671
  }) => {
2175
- let userProfile;
2672
+ let userIdentity;
2176
2673
  if (tokenResponse.id_token) {
2177
- userProfile = decodeJWT(tokenResponse.id_token);
2674
+ userIdentity = decodeJWT(tokenResponse.id_token);
2178
2675
  } else if (authProvider === "withings") {
2179
- userProfile = tokenResponse.body;
2676
+ userIdentity = tokenResponse.body;
2180
2677
  } else {
2181
- userProfile = await providerInstance.fetchUserProfile(tokenResponse.access_token);
2678
+ userIdentity = await providerInstance.fetchUserProfile(tokenResponse.access_token);
2182
2679
  }
2183
- let user = await getUser(userProfile);
2184
- user = user ?? await createUser(userProfile);
2680
+ let user = await getUser(userIdentity);
2681
+ user = user ?? await createUser(userIdentity);
2185
2682
  if (!isValidUser(user))
2186
2683
  throw new Error("Internal Server Error - Invalid user schema");
2187
2684
  session[userSessionId] = {
@@ -2258,5 +2755,5 @@ export {
2258
2755
  absoluteAuth
2259
2756
  };
2260
2757
 
2261
- //# debugId=B486F3D0FFE798E364756E2164756E21
2758
+ //# debugId=2E7A925803CF255964756E2164756E21
2262
2759
  //# sourceMappingURL=index.js.map