@absolutejs/auth 0.5.1 → 0.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.
package/dist/index.js CHANGED
@@ -101,21 +101,33 @@ var createRandomBase64UrlGenerator = (length) => () => {
101
101
  var generateCodeVerifier = createRandomBase64UrlGenerator(NUM_GENERATOR_BYTES);
102
102
  var generateState = createRandomBase64UrlGenerator(NUM_GENERATOR_BYTES);
103
103
  var base64Url = (input) => encodeBase64(input).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
104
- var isValidProviderOption = (option) => {
105
- const normalizedOption = option.toLowerCase();
106
- return Object.keys(normalizedProviders).includes(normalizedOption);
104
+ var isValidProviderOption = (option) => Object.hasOwn(providers, option);
105
+ var isRefreshableProviderOption = (option) => {
106
+ if (!isValidProviderOption(option))
107
+ return false;
108
+ const provider = providers[option];
109
+ return provider.isRefreshable;
110
+ };
111
+ var isRevocableProviderOption = (option) => {
112
+ if (!isValidProviderOption(option))
113
+ return false;
114
+ const provider = providers[option];
115
+ return provider.revocationRequest !== undefined;
107
116
  };
108
- var isPKCEProviderOption = (option) => normalizedProviders[option.toLowerCase()]?.PKCEMethod !== undefined;
109
- var isRefreshableOAuth2Client = (providerName, client) => {
110
- const normalizedOption = providerName.toLowerCase();
111
- const provider = normalizedProviders[normalizedOption];
112
- return isValidProviderOption(providerName) && provider?.isRefreshable === true;
117
+ var isPKCEProviderOption = (option) => {
118
+ if (!isValidProviderOption(option))
119
+ return false;
120
+ const provider = providers[option];
121
+ return provider.PKCEMethod !== undefined;
113
122
  };
114
- var isRevocableOAuth2Client = (providerName, client) => {
115
- const normalizedOption = providerName.toLowerCase();
116
- const provider = normalizedProviders[normalizedOption];
117
- return isValidProviderOption(providerName) && provider?.revocationRequest !== undefined;
123
+ var isOIDCProviderOption = (option) => {
124
+ if (!isValidProviderOption(option))
125
+ return false;
126
+ const provider = providers[option];
127
+ return provider.isOIDC;
118
128
  };
129
+ var isRefreshableOAuth2Client = (providerName, client) => isRefreshableProviderOption(providerName);
130
+ var isRevocableOAuth2Client = (providerName, client) => isRevocableProviderOption(providerName);
119
131
  var hasClientSecret = (credentials) => {
120
132
  if (typeof credentials !== "object" || credentials === null)
121
133
  return false;
@@ -140,7 +152,7 @@ var providers = defineProviders({
140
152
  url: "https://api.intra.42.fr/oauth/token"
141
153
  }
142
154
  },
143
- AmazonCognito: {
155
+ amazoncognito: {
144
156
  authorizationUrl: "https://${domain}/oauth2/authorize",
145
157
  isOIDC: true,
146
158
  isRefreshable: true,
@@ -162,7 +174,7 @@ var providers = defineProviders({
162
174
  url: (config) => `https://${config.domain}/oauth2/token`
163
175
  }
164
176
  },
165
- AniList: {
177
+ anilist: {
166
178
  authorizationUrl: "https://anilist.co/api/v2/oauth/authorize",
167
179
  isOIDC: false,
168
180
  isRefreshable: true,
@@ -185,7 +197,7 @@ var providers = defineProviders({
185
197
  url: "https://anilist.co/api/v2/oauth/token"
186
198
  }
187
199
  },
188
- Apple: {
200
+ apple: {
189
201
  authorizationUrl: "https://appleid.apple.com/auth/authorize",
190
202
  isOIDC: true,
191
203
  isRefreshable: true,
@@ -202,7 +214,7 @@ var providers = defineProviders({
202
214
  url: "https://appleid.apple.com/auth/token"
203
215
  }
204
216
  },
205
- Atlassian: {
217
+ atlassian: {
206
218
  authorizationUrl: "https://auth.atlassian.com/authorize",
207
219
  createAuthorizationURLSearchParams: {
208
220
  audience: "api.atlassian.com"
@@ -221,7 +233,7 @@ var providers = defineProviders({
221
233
  url: "https://auth.atlassian.com/oauth/token"
222
234
  }
223
235
  },
224
- Auth0: {
236
+ auth0: {
225
237
  authorizationUrl: (config) => `https://${config.domain}/authorize`,
226
238
  isOIDC: true,
227
239
  isRefreshable: true,
@@ -246,7 +258,7 @@ var providers = defineProviders({
246
258
  url: (config) => `https://${config.domain}/oauth/token`
247
259
  }
248
260
  },
249
- Authentik: {
261
+ authentik: {
250
262
  authorizationUrl: (config) => `https://${config.baseURL}/oauth/authorize`,
251
263
  isOIDC: true,
252
264
  isRefreshable: true,
@@ -263,7 +275,7 @@ var providers = defineProviders({
263
275
  url: (config) => `https://${config.baseURL}/oauth/token`
264
276
  }
265
277
  },
266
- Autodesk: {
278
+ autodesk: {
267
279
  authorizationUrl: "https://developer.api.autodesk.com/authentication/v2/authorize",
268
280
  isOIDC: true,
269
281
  isRefreshable: true,
@@ -280,7 +292,7 @@ var providers = defineProviders({
280
292
  url: "https://developer.api.autodesk.com/authentication/v2/token"
281
293
  }
282
294
  },
283
- Battlenet: {
295
+ battlenet: {
284
296
  authorizationUrl: "https://oauth.battle.net/authorize",
285
297
  isOIDC: true,
286
298
  isRefreshable: false,
@@ -296,7 +308,7 @@ var providers = defineProviders({
296
308
  url: "https://oauth.battle.net/token"
297
309
  }
298
310
  },
299
- Bitbucket: {
311
+ bitbucket: {
300
312
  authorizationUrl: "https://bitbucket.org/site/oauth2/authorize",
301
313
  isOIDC: false,
302
314
  isRefreshable: true,
@@ -312,7 +324,7 @@ var providers = defineProviders({
312
324
  url: "https://bitbucket.org/site/oauth2/access_token"
313
325
  }
314
326
  },
315
- Box: {
327
+ box: {
316
328
  authorizationUrl: "https://account.box.com/api/oauth2/authorize",
317
329
  isOIDC: false,
318
330
  isRefreshable: true,
@@ -333,7 +345,7 @@ var providers = defineProviders({
333
345
  url: "https://api.box.com/oauth2/token"
334
346
  }
335
347
  },
336
- Bungie: {
348
+ bungie: {
337
349
  authorizationUrl: "https://www.bungie.net/en/OAuth/Authorize",
338
350
  isOIDC: false,
339
351
  isRefreshable: true,
@@ -352,7 +364,7 @@ var providers = defineProviders({
352
364
  url: "https://www.bungie.net/Platform/App/OAuth/token"
353
365
  }
354
366
  },
355
- Coinbase: {
367
+ coinbase: {
356
368
  authorizationUrl: "https://www.coinbase.com/oauth/authorize",
357
369
  isOIDC: false,
358
370
  isRefreshable: true,
@@ -368,7 +380,7 @@ var providers = defineProviders({
368
380
  url: "https://api.coinbase.com/oauth/token"
369
381
  }
370
382
  },
371
- Discord: {
383
+ discord: {
372
384
  authorizationUrl: "https://discord.com/api/oauth2/authorize",
373
385
  isOIDC: false,
374
386
  isRefreshable: true,
@@ -385,7 +397,7 @@ var providers = defineProviders({
385
397
  url: "https://discord.com/api/oauth2/token"
386
398
  }
387
399
  },
388
- DonationAlerts: {
400
+ donationalerts: {
389
401
  authorizationUrl: "https://www.donationalerts.com/oauth/authorize",
390
402
  isOIDC: false,
391
403
  isRefreshable: true,
@@ -401,7 +413,7 @@ var providers = defineProviders({
401
413
  url: "https://www.donationalerts.com/oauth/token"
402
414
  }
403
415
  },
404
- Dribbble: {
416
+ dribbble: {
405
417
  authorizationUrl: "https://dribbble.com/oauth/authorize",
406
418
  isOIDC: false,
407
419
  isRefreshable: false,
@@ -417,7 +429,7 @@ var providers = defineProviders({
417
429
  url: "https://dribbble.com/oauth/token"
418
430
  }
419
431
  },
420
- Dropbox: {
432
+ dropbox: {
421
433
  authorizationUrl: "https://www.dropbox.com/oauth2/authorize",
422
434
  isOIDC: false,
423
435
  isRefreshable: true,
@@ -437,7 +449,7 @@ var providers = defineProviders({
437
449
  url: "https://api.dropboxapi.com/oauth2/token"
438
450
  }
439
451
  },
440
- EpicGames: {
452
+ epicgames: {
441
453
  authorizationUrl: "https://www.epicgames.com/id/authorize",
442
454
  isOIDC: false,
443
455
  isRefreshable: true,
@@ -453,7 +465,7 @@ var providers = defineProviders({
453
465
  url: "https://api.epicgames.dev/epic/oauth/v1/token"
454
466
  }
455
467
  },
456
- Etsy: {
468
+ etsy: {
457
469
  authorizationUrl: "https://www.etsy.com/oauth/connect",
458
470
  isOIDC: false,
459
471
  isRefreshable: true,
@@ -469,7 +481,7 @@ var providers = defineProviders({
469
481
  url: "https://api.etsy.com/v3/public/oauth/token"
470
482
  }
471
483
  },
472
- Facebook: {
484
+ facebook: {
473
485
  authorizationUrl: "https://www.facebook.com/v16.0/dialog/oauth",
474
486
  isOIDC: true,
475
487
  isRefreshable: false,
@@ -487,7 +499,7 @@ var providers = defineProviders({
487
499
  url: "https://graph.facebook.com/v16.0/oauth/access_token"
488
500
  }
489
501
  },
490
- Figma: {
502
+ figma: {
491
503
  authorizationUrl: "https://www.figma.com/oauth",
492
504
  isOIDC: false,
493
505
  isRefreshable: true,
@@ -504,7 +516,7 @@ var providers = defineProviders({
504
516
  url: "https://api.figma.com/v1/oauth/token"
505
517
  }
506
518
  },
507
- Gitea: {
519
+ gitea: {
508
520
  authorizationUrl: (config) => `${config.baseURL}/login/oauth/authorize`,
509
521
  isOIDC: true,
510
522
  isRefreshable: true,
@@ -521,7 +533,7 @@ var providers = defineProviders({
521
533
  url: (config) => `${config.baseURL}/login/oauth/access_token`
522
534
  }
523
535
  },
524
- GitHub: {
536
+ github: {
525
537
  authorizationUrl: "https://github.com/login/oauth/authorize",
526
538
  isOIDC: false,
527
539
  isRefreshable: false,
@@ -537,7 +549,7 @@ var providers = defineProviders({
537
549
  url: "https://github.com/login/oauth/access_token"
538
550
  }
539
551
  },
540
- GitLab: {
552
+ gitlab: {
541
553
  authorizationUrl: (config) => `${config.baseURL}/oauth/authorize`,
542
554
  isOIDC: true,
543
555
  isRefreshable: true,
@@ -559,7 +571,7 @@ var providers = defineProviders({
559
571
  url: (config) => `${config.baseURL}/oauth/token`
560
572
  }
561
573
  },
562
- Google: {
574
+ google: {
563
575
  authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
564
576
  isOIDC: true,
565
577
  isRefreshable: true,
@@ -582,7 +594,7 @@ var providers = defineProviders({
582
594
  url: "https://oauth2.googleapis.com/token"
583
595
  }
584
596
  },
585
- Intuit: {
597
+ intuit: {
586
598
  authorizationUrl: "https://appcenter.intuit.com/connect/oauth2",
587
599
  isOIDC: true,
588
600
  isRefreshable: true,
@@ -606,7 +618,7 @@ var providers = defineProviders({
606
618
  url: "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"
607
619
  }
608
620
  },
609
- Kakao: {
621
+ kakao: {
610
622
  authorizationUrl: "https://kauth.kakao.com/oauth/authorize",
611
623
  isOIDC: true,
612
624
  isRefreshable: true,
@@ -623,7 +635,7 @@ var providers = defineProviders({
623
635
  url: "https://kauth.kakao.com/oauth/token"
624
636
  }
625
637
  },
626
- Keycloak: {
638
+ keycloak: {
627
639
  authorizationUrl: (config) => `${config.realmURL}/protocol/openid-connect/auth`,
628
640
  isOIDC: true,
629
641
  isRefreshable: true,
@@ -645,7 +657,7 @@ var providers = defineProviders({
645
657
  url: (config) => `${config.realmURL}/protocol/openid-connect/token`
646
658
  }
647
659
  },
648
- Kick: {
660
+ kick: {
649
661
  authorizationUrl: "https://id.kick.com/oauth/authorize",
650
662
  isOIDC: false,
651
663
  isRefreshable: true,
@@ -667,7 +679,7 @@ var providers = defineProviders({
667
679
  url: "https://id.kick.com/oauth/token"
668
680
  }
669
681
  },
670
- Lichess: {
682
+ lichess: {
671
683
  authorizationUrl: "https://lichess.org/oauth/authorize",
672
684
  isOIDC: false,
673
685
  isRefreshable: false,
@@ -684,7 +696,7 @@ var providers = defineProviders({
684
696
  url: "https://lichess.org/api/token"
685
697
  }
686
698
  },
687
- LINE: {
699
+ line: {
688
700
  authorizationUrl: "https://access.line.me/oauth2/v2.1/authorize",
689
701
  isOIDC: true,
690
702
  isRefreshable: true,
@@ -701,7 +713,7 @@ var providers = defineProviders({
701
713
  url: "https://api.line.me/oauth2/v2.1/token"
702
714
  }
703
715
  },
704
- Linear: {
716
+ linear: {
705
717
  authorizationUrl: "https://linear.app/oauth/authorize",
706
718
  isOIDC: false,
707
719
  isRefreshable: false,
@@ -728,7 +740,7 @@ var providers = defineProviders({
728
740
  url: "https://api.linear.app/oauth/token"
729
741
  }
730
742
  },
731
- LinkedIn: {
743
+ linkedin: {
732
744
  authorizationUrl: "https://www.linkedin.com/oauth/v2/authorization",
733
745
  isOIDC: true,
734
746
  isRefreshable: true,
@@ -745,7 +757,7 @@ var providers = defineProviders({
745
757
  url: "https://www.linkedin.com/oauth/v2/accessToken"
746
758
  }
747
759
  },
748
- Mastodon: {
760
+ mastodon: {
749
761
  authorizationUrl: (config) => `${config.baseURL}/oauth/authorize`,
750
762
  isOIDC: false,
751
763
  isRefreshable: false,
@@ -767,7 +779,7 @@ var providers = defineProviders({
767
779
  url: (config) => `${config.baseURL}/oauth/token`
768
780
  }
769
781
  },
770
- MercadoLibre: {
782
+ mercadolibre: {
771
783
  authorizationUrl: "https://auth.mercadolibre.com/authorization",
772
784
  isOIDC: false,
773
785
  isRefreshable: true,
@@ -784,7 +796,7 @@ var providers = defineProviders({
784
796
  url: "https://api.mercadolibre.com/oauth/token"
785
797
  }
786
798
  },
787
- MercadoPago: {
799
+ mercadopago: {
788
800
  authorizationUrl: "https://auth.mercadopago.com/authorization",
789
801
  isOIDC: false,
790
802
  isRefreshable: true,
@@ -800,7 +812,7 @@ var providers = defineProviders({
800
812
  url: "https://api.mercadopago.com/oauth/token"
801
813
  }
802
814
  },
803
- MicrosoftEntraId: {
815
+ microsoftentraid: {
804
816
  authorizationUrl: (config) => `https://${config.tenantId}.b2clogin.com/${config.tenantId}/oauth2/v2.0/authorize`,
805
817
  isOIDC: true,
806
818
  isRefreshable: true,
@@ -817,7 +829,7 @@ var providers = defineProviders({
817
829
  url: (config) => `https://${config.tenantId}.b2clogin.com/${config.tenantId}/oauth2/v2.0/token`
818
830
  }
819
831
  },
820
- MyAnimeList: {
832
+ myanimelist: {
821
833
  authorizationUrl: "https://myanimelist.net/v1/oauth2/authorize",
822
834
  isOIDC: false,
823
835
  isRefreshable: true,
@@ -834,7 +846,7 @@ var providers = defineProviders({
834
846
  url: "https://myanimelist.net/v1/oauth2/token"
835
847
  }
836
848
  },
837
- Naver: {
849
+ naver: {
838
850
  authorizationUrl: "https://nid.naver.com/oauth2.0/authorize",
839
851
  isOIDC: false,
840
852
  isRefreshable: true,
@@ -850,7 +862,7 @@ var providers = defineProviders({
850
862
  url: "https://nid.naver.com/oauth2.0/token"
851
863
  }
852
864
  },
853
- Notion: {
865
+ notion: {
854
866
  authorizationUrl: "https://api.notion.com/v1/oauth/authorize",
855
867
  isOIDC: false,
856
868
  isRefreshable: false,
@@ -869,7 +881,7 @@ var providers = defineProviders({
869
881
  url: "https://api.notion.com/v1/oauth/token"
870
882
  }
871
883
  },
872
- Okta: {
884
+ okta: {
873
885
  authorizationUrl: (config) => `https://${config.domain}/oauth2/default/v1/authorize`,
874
886
  isOIDC: true,
875
887
  isRefreshable: true,
@@ -891,7 +903,7 @@ var providers = defineProviders({
891
903
  url: (config) => `https://${config.domain}/oauth2/default/v1/token`
892
904
  }
893
905
  },
894
- Osu: {
906
+ osu: {
895
907
  authorizationUrl: "https://osu.ppy.sh/oauth/authorize",
896
908
  isOIDC: false,
897
909
  isRefreshable: true,
@@ -907,7 +919,7 @@ var providers = defineProviders({
907
919
  url: "https://osu.ppy.sh/oauth/token"
908
920
  }
909
921
  },
910
- Patreon: {
922
+ patreon: {
911
923
  authorizationUrl: "https://www.patreon.com/oauth2/authorize",
912
924
  isOIDC: false,
913
925
  isRefreshable: true,
@@ -923,7 +935,7 @@ var providers = defineProviders({
923
935
  url: "https://www.patreon.com/api/oauth2/token"
924
936
  }
925
937
  },
926
- Polar: {
938
+ polar: {
927
939
  authorizationUrl: "https://polar.sh/oauth2/authorize",
928
940
  isOIDC: true,
929
941
  isRefreshable: true,
@@ -945,7 +957,7 @@ var providers = defineProviders({
945
957
  url: "https://api.polar.sh/v1/oauth2/token"
946
958
  }
947
959
  },
948
- PolarAccessLink: {
960
+ polaraccesslink: {
949
961
  authorizationUrl: "https://flow.polar.com/oauth2/authorization",
950
962
  isOIDC: false,
951
963
  isRefreshable: false,
@@ -962,7 +974,7 @@ var providers = defineProviders({
962
974
  url: "https://polarremote.com/v2/oauth2/token"
963
975
  }
964
976
  },
965
- PolarTeamPro: {
977
+ polarteampro: {
966
978
  authorizationUrl: "https://auth.polar.com/oauth/authorize",
967
979
  isOIDC: false,
968
980
  isRefreshable: true,
@@ -979,7 +991,7 @@ var providers = defineProviders({
979
991
  url: "https://auth.polar.com/oauth/token"
980
992
  }
981
993
  },
982
- Reddit: {
994
+ reddit: {
983
995
  authorizationUrl: "https://www.reddit.com/api/v1/authorize",
984
996
  isOIDC: false,
985
997
  isRefreshable: true,
@@ -1002,7 +1014,7 @@ var providers = defineProviders({
1002
1014
  url: "https://www.reddit.com/api/v1/access_token"
1003
1015
  }
1004
1016
  },
1005
- Roblox: {
1017
+ roblox: {
1006
1018
  authorizationUrl: "https://apis.roblox.com/oauth/v1/authorize",
1007
1019
  isOIDC: true,
1008
1020
  isRefreshable: true,
@@ -1019,7 +1031,7 @@ var providers = defineProviders({
1019
1031
  url: "https://apis.roblox.com/oauth/v1/token"
1020
1032
  }
1021
1033
  },
1022
- Salesforce: {
1034
+ salesforce: {
1023
1035
  authorizationUrl: "https://login.salesforce.com/services/oauth2/authorize",
1024
1036
  isOIDC: true,
1025
1037
  isRefreshable: true,
@@ -1040,7 +1052,7 @@ var providers = defineProviders({
1040
1052
  url: "https://login.salesforce.com/services/oauth2/token"
1041
1053
  }
1042
1054
  },
1043
- Shikimori: {
1055
+ shikimori: {
1044
1056
  authorizationUrl: "https://shikimori.org/oauth/authorize",
1045
1057
  isOIDC: false,
1046
1058
  isRefreshable: true,
@@ -1056,7 +1068,7 @@ var providers = defineProviders({
1056
1068
  url: "https://shikimori.org/oauth/token"
1057
1069
  }
1058
1070
  },
1059
- Slack: {
1071
+ slack: {
1060
1072
  authorizationUrl: "https://slack.com/openid/connect/authorize",
1061
1073
  isOIDC: true,
1062
1074
  isRefreshable: true,
@@ -1077,7 +1089,7 @@ var providers = defineProviders({
1077
1089
  url: "https://slack.com/api/openid.connect.token"
1078
1090
  }
1079
1091
  },
1080
- Spotify: {
1092
+ spotify: {
1081
1093
  authorizationUrl: "https://accounts.spotify.com/authorize",
1082
1094
  isOIDC: false,
1083
1095
  isRefreshable: true,
@@ -1094,7 +1106,7 @@ var providers = defineProviders({
1094
1106
  url: "https://accounts.spotify.com/api/token"
1095
1107
  }
1096
1108
  },
1097
- StartGG: {
1109
+ startgg: {
1098
1110
  authorizationUrl: "https://start.gg/oauth/authorize",
1099
1111
  isOIDC: false,
1100
1112
  isRefreshable: true,
@@ -1117,7 +1129,7 @@ var providers = defineProviders({
1117
1129
  url: "https://api.start.gg/oauth/access_token"
1118
1130
  }
1119
1131
  },
1120
- Strava: {
1132
+ strava: {
1121
1133
  authorizationUrl: "https://www.strava.com/oauth/authorize",
1122
1134
  isOIDC: false,
1123
1135
  isRefreshable: true,
@@ -1142,7 +1154,7 @@ var providers = defineProviders({
1142
1154
  url: "https://www.strava.com/oauth/token"
1143
1155
  }
1144
1156
  },
1145
- Synology: {
1157
+ synology: {
1146
1158
  authorizationUrl: (config) => `${config.baseURL}/webman/sso/SSOOauth.cgi?client_id=${config.clientId}&response_type=code&redirect_uri=${config.redirectUri}`,
1147
1159
  isOIDC: false,
1148
1160
  isRefreshable: false,
@@ -1158,7 +1170,7 @@ var providers = defineProviders({
1158
1170
  url: (config) => `${config.baseURL}/webman/sso/SSOAccessToken.cgi?client_id=${config.clientId}&client_secret=${config.clientSecret}`
1159
1171
  }
1160
1172
  },
1161
- TikTok: {
1173
+ tiktok: {
1162
1174
  authorizationUrl: "https://www.tiktok.com/v2/auth/authorize",
1163
1175
  createAuthorizationURLSearchParams: (config) => ({
1164
1176
  client_key: config.clientId
@@ -1183,7 +1195,7 @@ var providers = defineProviders({
1183
1195
  url: "https://open.tiktokapis.com/v2/oauth/token/"
1184
1196
  }
1185
1197
  },
1186
- Tiltify: {
1198
+ tiltify: {
1187
1199
  authorizationUrl: "https://v5api.tiltify.com/oauth/authorize",
1188
1200
  isOIDC: false,
1189
1201
  isRefreshable: true,
@@ -1199,7 +1211,7 @@ var providers = defineProviders({
1199
1211
  url: "https://v5api.tiltify.com/oauth/token"
1200
1212
  }
1201
1213
  },
1202
- Tumblr: {
1214
+ tumblr: {
1203
1215
  authorizationUrl: "https://www.tumblr.com/oauth2/authorize",
1204
1216
  isOIDC: false,
1205
1217
  isRefreshable: true,
@@ -1215,7 +1227,7 @@ var providers = defineProviders({
1215
1227
  url: "https://api.tumblr.com/v2/oauth2/token"
1216
1228
  }
1217
1229
  },
1218
- Twitch: {
1230
+ twitch: {
1219
1231
  authorizationUrl: "https://id.twitch.tv/oauth2/authorize",
1220
1232
  isOIDC: true,
1221
1233
  isRefreshable: true,
@@ -1242,7 +1254,7 @@ var providers = defineProviders({
1242
1254
  url: "https://id.twitch.tv/oauth2/token"
1243
1255
  }
1244
1256
  },
1245
- Twitter: {
1257
+ twitter: {
1246
1258
  authorizationUrl: "https://twitter.com/i/oauth2/authorize",
1247
1259
  isOIDC: false,
1248
1260
  isRefreshable: true,
@@ -1263,7 +1275,7 @@ var providers = defineProviders({
1263
1275
  url: "https://api.twitter.com/2/oauth2/token"
1264
1276
  }
1265
1277
  },
1266
- VK: {
1278
+ vk: {
1267
1279
  authorizationUrl: "https://oauth.vk.com/authorize",
1268
1280
  isOIDC: false,
1269
1281
  isRefreshable: false,
@@ -1279,7 +1291,7 @@ var providers = defineProviders({
1279
1291
  url: "https://oauth.vk.com/access_token"
1280
1292
  }
1281
1293
  },
1282
- WorkOS: {
1294
+ workos: {
1283
1295
  authorizationUrl: "https://api.workos.com/sso/authorize",
1284
1296
  isOIDC: true,
1285
1297
  isRefreshable: true,
@@ -1296,7 +1308,7 @@ var providers = defineProviders({
1296
1308
  url: "https://api.workos.com/sso/token"
1297
1309
  }
1298
1310
  },
1299
- Yahoo: {
1311
+ yahoo: {
1300
1312
  authorizationUrl: "https://api.login.yahoo.com/oauth2/request_auth",
1301
1313
  isOIDC: true,
1302
1314
  isRefreshable: true,
@@ -1317,7 +1329,7 @@ var providers = defineProviders({
1317
1329
  url: "https://api.login.yahoo.com/oauth2/get_token"
1318
1330
  }
1319
1331
  },
1320
- Yandex: {
1332
+ yandex: {
1321
1333
  authorizationUrl: "https://oauth.yandex.com/authorize",
1322
1334
  createAuthorizationURLSearchParams: {
1323
1335
  device_id: crypto.randomUUID(),
@@ -1343,7 +1355,7 @@ var providers = defineProviders({
1343
1355
  url: "https://oauth.yandex.com/token"
1344
1356
  }
1345
1357
  },
1346
- Zoom: {
1358
+ zoom: {
1347
1359
  authorizationUrl: "https://zoom.us/oauth/authorize",
1348
1360
  isOIDC: false,
1349
1361
  isRefreshable: true,
@@ -1369,8 +1381,10 @@ var providers = defineProviders({
1369
1381
  }
1370
1382
  }
1371
1383
  });
1372
- var normalizedProviders = Object.fromEntries(Object.entries(providers).map(([key, def]) => [key.toLowerCase(), def]));
1373
1384
  var providerOptions = Object.keys(providers).filter(isValidProviderOption);
1385
+ var refreshableProviderOptions = Object.keys(providers).filter(isRefreshableProviderOption);
1386
+ var oidcProviderOptions = Object.keys(providers).filter(isOIDCProviderOption);
1387
+ var revocableProviderOptions = Object.keys(providers).filter(isRevocableProviderOption);
1374
1388
  var createOAuth2Client = (providerName, config) => {
1375
1389
  const meta = providers[providerName];
1376
1390
  const isConfigPropertyFunction = (cfgProp) => typeof cfgProp === "function";
@@ -1582,44 +1596,42 @@ var authorize = ({
1582
1596
  return error("Bad Request", "Cookies are missing");
1583
1597
  if (provider === undefined)
1584
1598
  return error("Bad Request", "Provider is required");
1585
- if (!isValidProviderOption(provider)) {
1599
+ if (!isValidProviderOption(provider))
1586
1600
  return error("Bad Request", "Invalid provider");
1587
- }
1588
1601
  const providerConfig = clientProviders[provider];
1589
- if (!providerConfig) {
1590
- return error("Unauthorized", "Invalid provider");
1591
- }
1602
+ if (!providerConfig)
1603
+ return error("Unauthorized", "Client provider not found");
1592
1604
  const { providerInstance, scope, searchParams } = providerConfig;
1593
1605
  const normalizedProvider = provider.toLowerCase();
1594
- try {
1595
- const redirectUrl = headers["referer"] ?? "/";
1596
- redirect_url.set({
1597
- httpOnly: true,
1598
- maxAge: COOKIE_DURATION,
1599
- path: "/",
1600
- sameSite: "lax",
1601
- secure: true,
1602
- value: redirectUrl
1603
- });
1604
- auth_provider.set({
1605
- httpOnly: true,
1606
- maxAge: COOKIE_DURATION,
1607
- path: "/",
1608
- sameSite: "lax",
1609
- secure: true,
1610
- value: normalizedProvider
1611
- });
1612
- const currentState = generateState();
1613
- state.set({
1614
- httpOnly: true,
1615
- maxAge: COOKIE_DURATION,
1616
- path: "/",
1617
- sameSite: "lax",
1618
- secure: true,
1619
- value: currentState
1620
- });
1621
- const codeVerifier = isPKCEProviderOption(provider) ? generateCodeVerifier() : undefined;
1622
- codeVerifier && code_verifier.set({
1606
+ const referer = headers["referer"] ?? "/";
1607
+ redirect_url.set({
1608
+ httpOnly: true,
1609
+ maxAge: COOKIE_DURATION,
1610
+ path: "/",
1611
+ sameSite: "lax",
1612
+ secure: true,
1613
+ value: referer
1614
+ });
1615
+ auth_provider.set({
1616
+ httpOnly: true,
1617
+ maxAge: COOKIE_DURATION,
1618
+ path: "/",
1619
+ sameSite: "lax",
1620
+ secure: true,
1621
+ value: normalizedProvider
1622
+ });
1623
+ const currentState = generateState();
1624
+ state.set({
1625
+ httpOnly: true,
1626
+ maxAge: COOKIE_DURATION,
1627
+ path: "/",
1628
+ sameSite: "lax",
1629
+ secure: true,
1630
+ value: currentState
1631
+ });
1632
+ const codeVerifier = isPKCEProviderOption(provider) ? generateCodeVerifier() : undefined;
1633
+ if (codeVerifier) {
1634
+ code_verifier.set({
1623
1635
  httpOnly: true,
1624
1636
  maxAge: COOKIE_DURATION,
1625
1637
  path: "/",
@@ -1627,9 +1639,14 @@ var authorize = ({
1627
1639
  secure: true,
1628
1640
  value: codeVerifier
1629
1641
  });
1642
+ }
1643
+ try {
1630
1644
  const authorizationURL = await providerInstance.createAuthorizationUrl(codeVerifier ? { codeVerifier, scope, state: currentState } : { scope, state: currentState });
1631
1645
  searchParams?.forEach(([key, value]) => authorizationURL.searchParams.set(key, value));
1632
- onAuthorize?.();
1646
+ onAuthorize?.({
1647
+ authorizationUrl: authorizationURL,
1648
+ authProvider: normalizedProvider
1649
+ });
1633
1650
  return redirect(authorizationURL.toString());
1634
1651
  } catch (err) {
1635
1652
  if (err instanceof Error) {
@@ -1673,8 +1690,9 @@ var callback = ({
1673
1690
  },
1674
1691
  query: { code, state: callback_state }
1675
1692
  }) => {
1676
- if (stored_state === undefined || code_verifier === undefined || auth_provider === undefined || user_session_id === undefined)
1693
+ if (stored_state === undefined || code_verifier === undefined || auth_provider === undefined || user_session_id === undefined) {
1677
1694
  return error("Bad Request", "Cookies are missing");
1695
+ }
1678
1696
  if (!isNonEmptyString(code) || stored_state.value === undefined) {
1679
1697
  return error("Bad Request", "Invalid callback request");
1680
1698
  }
@@ -1689,17 +1707,17 @@ var callback = ({
1689
1707
  }
1690
1708
  const providerConfig = clientProviders[auth_provider.value];
1691
1709
  if (!providerConfig) {
1692
- return error("Unauthorized", "Invalid provider");
1710
+ return error("Unauthorized", "Client provider not found");
1693
1711
  }
1694
1712
  const { providerInstance } = providerConfig;
1713
+ stored_state.remove();
1714
+ const authProvider = auth_provider.value;
1715
+ const requiresPKCE = isPKCEProviderOption(authProvider);
1716
+ const verifier = requiresPKCE ? code_verifier.value : undefined;
1717
+ if (requiresPKCE && verifier === undefined) {
1718
+ return error("Bad Request", "Code verifier not found and is required");
1719
+ }
1695
1720
  try {
1696
- stored_state.remove();
1697
- const authProvider = auth_provider.value;
1698
- const requiresPKCE = isPKCEProviderOption(authProvider);
1699
- const verifier = requiresPKCE ? code_verifier.value : undefined;
1700
- if (requiresPKCE && verifier === undefined) {
1701
- return error("Bad Request", "Code verifier not found and is required");
1702
- }
1703
1721
  const tokenResponse = await providerInstance.validateAuthorizationCode(requiresPKCE ? { code, codeVerifier: verifier } : { code });
1704
1722
  const userProfile = tokenResponse.id_token ? decodeJWT(tokenResponse.id_token) : await providerInstance.fetchUserProfile(tokenResponse.access_token);
1705
1723
  await onCallback?.({
@@ -1740,7 +1758,7 @@ var profile = ({
1740
1758
  }
1741
1759
  const providerConfig = clientProviders[auth_provider.value];
1742
1760
  if (!providerConfig) {
1743
- return error("Unauthorized", "Invalid provider");
1761
+ return error("Unauthorized", "Client provider not found");
1744
1762
  }
1745
1763
  const { providerInstance } = providerConfig;
1746
1764
  const userSession = session[user_session_id.value];
@@ -1751,6 +1769,7 @@ var profile = ({
1751
1769
  try {
1752
1770
  const userProfile = await providerInstance.fetchUserProfile(accessToken);
1753
1771
  await onProfile?.({
1772
+ authProvider: auth_provider.value,
1754
1773
  userProfile
1755
1774
  });
1756
1775
  return new Response(JSON.stringify(userProfile));
@@ -1800,7 +1819,7 @@ var refresh = ({
1800
1819
  }
1801
1820
  const providerConfig = clientProviders[auth_provider.value];
1802
1821
  if (!providerConfig) {
1803
- return error("Unauthorized", "Invalid provider");
1822
+ return error("Unauthorized", "Client provider not found");
1804
1823
  }
1805
1824
  const { providerInstance } = providerConfig;
1806
1825
  const userSession = session[user_session_id.value];
@@ -1816,7 +1835,10 @@ var refresh = ({
1816
1835
  }
1817
1836
  try {
1818
1837
  const tokenResponse = await providerInstance.refreshAccessToken(refreshToken);
1819
- onRefresh?.({ tokenResponse });
1838
+ onRefresh?.({
1839
+ authProvider: auth_provider.value,
1840
+ tokenResponse
1841
+ });
1820
1842
  return new Response("Token refreshed", {
1821
1843
  status: 204
1822
1844
  });
@@ -1852,7 +1874,7 @@ var revoke = ({
1852
1874
  }
1853
1875
  const providerConfig = clientProviders[auth_provider.value];
1854
1876
  if (!providerConfig) {
1855
- return error("Unauthorized", "Invalid provider");
1877
+ return error("Unauthorized", "Client provider not found");
1856
1878
  }
1857
1879
  const { providerInstance } = providerConfig;
1858
1880
  if (!isRevocableOAuth2Client(auth_provider.value, providerInstance)) {
@@ -1865,7 +1887,10 @@ var revoke = ({
1865
1887
  const { accessToken } = userSession;
1866
1888
  try {
1867
1889
  await providerInstance.revokeToken(accessToken);
1868
- onRevocation?.({ tokenToRevoke: accessToken });
1890
+ onRevocation?.({
1891
+ authProvider: auth_provider.value,
1892
+ tokenToRevoke: accessToken
1893
+ });
1869
1894
  return new Response("Token revoked", {
1870
1895
  status: 204
1871
1896
  });
@@ -1882,24 +1907,35 @@ import { Elysia as Elysia8 } from "elysia";
1882
1907
  var signout = ({
1883
1908
  signoutRoute = "/oauth2/signout",
1884
1909
  onSignOut
1885
- }) => new Elysia8().post(signoutRoute, async ({ error, cookie: { user_session_id, auth_provider } }) => {
1886
- if (auth_provider === undefined || user_session_id === undefined)
1910
+ }) => new Elysia8().use(sessionStore()).delete(signoutRoute, async ({
1911
+ error,
1912
+ store: { session },
1913
+ cookie: { user_session_id, auth_provider }
1914
+ }) => {
1915
+ if (auth_provider === undefined || user_session_id === undefined) {
1887
1916
  return error("Bad Request", "Cookies are missing");
1917
+ }
1888
1918
  if (auth_provider.value === undefined) {
1889
1919
  return error("Unauthorized", "No auth provider found");
1890
1920
  }
1921
+ if (user_session_id.value === undefined) {
1922
+ return error("Unauthorized", "No user session found");
1923
+ }
1924
+ const userSession = session[user_session_id.value];
1925
+ user_session_id.remove();
1926
+ auth_provider.remove();
1927
+ if (userSession === undefined) {
1928
+ return new Response(null, { status: 204 });
1929
+ }
1891
1930
  try {
1892
- onSignOut?.();
1893
- user_session_id.remove();
1894
- auth_provider.remove();
1895
- return new Response("Succesfuly Logged Out", {
1896
- status: 204
1931
+ onSignOut?.({
1932
+ authProvider: auth_provider.value,
1933
+ user: userSession.user
1897
1934
  });
1935
+ return new Response(null, { status: 204 });
1898
1936
  } catch (err) {
1899
- if (err instanceof Error) {
1900
- return error("Internal Server Error", `Failed to signout: ${err.message}`);
1901
- }
1902
- return error("Internal Server Error", `Failed to signout: Unknown error: ${err}`);
1937
+ const msg = err instanceof Error ? `Failed to sign out: ${err.message}` : `Failed to sign out: ${err}`;
1938
+ return error("Internal Server Error", msg);
1903
1939
  }
1904
1940
  });
1905
1941
 
@@ -1911,47 +1947,43 @@ var status = ({
1911
1947
  onStatus
1912
1948
  }) => new Elysia9().use(sessionStore()).get(statusRoute, async ({
1913
1949
  error,
1914
- cookie: { user_session_id, auth_provider },
1950
+ cookie: { user_session_id },
1915
1951
  store: { session }
1916
1952
  }) => {
1917
- if (auth_provider === undefined || user_session_id === undefined)
1953
+ if (user_session_id === undefined) {
1918
1954
  return error("Bad Request", "Cookies are missing");
1919
- try {
1920
- if (user_session_id.value === undefined) {
1921
- return new Response(JSON.stringify({ isLoggedIn: false, user: null }), {
1922
- headers: { "Content-Type": "application/json" }
1923
- });
1924
- }
1925
- if (auth_provider.value === undefined) {
1926
- return new Response(JSON.stringify({ isLoggedIn: false, user: null }), {
1927
- headers: { "Content-Type": "application/json" }
1928
- });
1929
- }
1930
- const providerConfig = clientProviders[auth_provider.value];
1931
- if (!providerConfig) {
1932
- return error("Unauthorized", "Invalid provider");
1933
- }
1934
- const { providerInstance } = providerConfig;
1935
- if (!isRefreshableOAuth2Client("Google", providerInstance)) {
1936
- return error("Not Implemented", "Provider is not refreshable");
1937
- }
1938
- const userSession = session[user_session_id.value];
1939
- if (userSession === undefined) {
1940
- return new Response(JSON.stringify({ isLoggedIn: false, user: null }), {
1941
- headers: { "Content-Type": "application/json" }
1942
- });
1943
- }
1944
- const { user } = userSession;
1945
- onStatus?.();
1946
- return new Response(JSON.stringify({ isLoggedIn: true, user }), {
1955
+ }
1956
+ if (user_session_id.value === undefined) {
1957
+ onStatus?.({
1958
+ user: null
1959
+ });
1960
+ return new Response(JSON.stringify({ isLoggedIn: false, user: null }), {
1947
1961
  headers: { "Content-Type": "application/json" }
1948
1962
  });
1963
+ }
1964
+ const userSession = session[user_session_id.value];
1965
+ if (userSession === undefined) {
1966
+ onStatus?.({
1967
+ user: null
1968
+ });
1969
+ return new Response(JSON.stringify({ isLoggedIn: false, user: null }), {
1970
+ headers: { "Content-Type": "application/json" }
1971
+ });
1972
+ }
1973
+ const { user } = userSession;
1974
+ try {
1975
+ onStatus?.({
1976
+ user
1977
+ });
1949
1978
  } catch (err) {
1950
1979
  if (err instanceof Error) {
1951
1980
  return error("Internal Server Error", `Error: ${err.message} - ${err.stack ?? ""}`);
1952
1981
  }
1953
1982
  return error("Internal Server Error", `Unknown Error: ${err}`);
1954
1983
  }
1984
+ return new Response(JSON.stringify({ isLoggedIn: true, user }), {
1985
+ headers: { "Content-Type": "application/json" }
1986
+ });
1955
1987
  });
1956
1988
 
1957
1989
  // src/utils.ts
@@ -1980,11 +2012,12 @@ var instantiateUserSession = async ({
1980
2012
  value: sessionKey
1981
2013
  });
1982
2014
  };
1983
- var createAuthConfig = (props) => props;
2015
+ var createAuthConfiguration = (configuration) => configuration;
2016
+ var createProvidersConfiguration = (providersConfiguration) => providersConfiguration;
1984
2017
 
1985
2018
  // src/index.ts
1986
2019
  var absoluteAuth = ({
1987
- config,
2020
+ providersConfiguration,
1988
2021
  authorizeRoute,
1989
2022
  callbackRoute,
1990
2023
  profileRoute,
@@ -2000,9 +2033,9 @@ var absoluteAuth = ({
2000
2033
  onSignOut,
2001
2034
  onRevocation
2002
2035
  }) => {
2003
- const clientProviders = Object.entries(config).reduce((acc, [providerName, providerConfig]) => {
2036
+ const clientProviders = Object.entries(providersConfiguration).reduce((acc, [providerName, providerConfig]) => {
2004
2037
  if (isValidProviderOption(providerName)) {
2005
- acc[providerName.toLocaleLowerCase()] = {
2038
+ acc[providerName] = {
2006
2039
  providerInstance: createOAuth2Client(providerName, providerConfig.credentials),
2007
2040
  scope: providerConfig.scope,
2008
2041
  searchParams: providerConfig.searchParams
@@ -2022,6 +2055,7 @@ var absoluteAuth = ({
2022
2055
  };
2023
2056
  export {
2024
2057
  instantiateUserSession,
2025
- createAuthConfig,
2058
+ createProvidersConfiguration,
2059
+ createAuthConfiguration,
2026
2060
  absoluteAuth
2027
2061
  };
@@ -1,9 +1,9 @@
1
1
  import { Elysia } from 'elysia';
2
- import { AuthorizeRoute, ClientProviders } from './types';
2
+ import { AuthorizeRoute, ClientProviders, OnAuthorize } from './types';
3
3
  type AuthorizeProps = {
4
4
  clientProviders: ClientProviders;
5
5
  authorizeRoute?: AuthorizeRoute;
6
- onAuthorize?: () => void;
6
+ onAuthorize?: OnAuthorize;
7
7
  };
8
8
  export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize }: AuthorizeProps) => Elysia<"", {
9
9
  decorator: {};
@@ -31,7 +31,7 @@ export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize
31
31
  response: {
32
32
  200: import("undici-types").Response;
33
33
  400: "Cookies are missing" | "Provider is required" | "Invalid provider";
34
- 401: "Invalid provider";
34
+ 401: "Client provider not found";
35
35
  500: `${string} - ${string}` | `Unknown error: ${string}`;
36
36
  422: {
37
37
  type: "validation";
@@ -60,7 +60,7 @@ export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize
60
60
  response: {
61
61
  200: import("undici-types").Response;
62
62
  400: "Cookies are missing" | "Provider is required" | "Invalid provider";
63
- 401: "Invalid provider";
63
+ 401: "Client provider not found";
64
64
  500: `${string} - ${string}` | `Unknown error: ${string}`;
65
65
  422: {
66
66
  type: "validation";
@@ -30,7 +30,7 @@ export declare const callback: <UserType>({ clientProviders, callbackRoute, onCa
30
30
  response: {
31
31
  200: import("undici-types").Response;
32
32
  400: "Cookies are missing" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
33
- 401: "Invalid provider" | "No auth provider found";
33
+ 401: "Invalid provider" | "Client provider not found" | "No auth provider found";
34
34
  500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
35
35
  };
36
36
  };
@@ -1,9 +1,9 @@
1
1
  import { Elysia } from 'elysia';
2
2
  import { AbsoluteAuthProps } from './types';
3
- export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callbackRoute, profileRoute, signoutRoute, statusRoute, refreshRoute, revokeRoute, onAuthorize, onProfile, onCallback, onStatus, onRefresh, onSignOut, onRevocation }: AbsoluteAuthProps<UserType>) => Elysia<"", {
3
+ export declare const absoluteAuth: <UserType>({ providersConfiguration, authorizeRoute, callbackRoute, profileRoute, signoutRoute, statusRoute, refreshRoute, revokeRoute, onAuthorize, onProfile, onCallback, onStatus, onRefresh, onSignOut, onRevocation }: AbsoluteAuthProps<UserType>) => Elysia<"", {
4
4
  decorator: {};
5
5
  store: {
6
- session: import("./types").SessionRecord<unknown> & import("./types").SessionRecord<UserType>;
6
+ session: import("./types").SessionRecord<UserType> & import("./types").SessionRecord<unknown>;
7
7
  };
8
8
  derive: {};
9
9
  resolve: {};
@@ -17,7 +17,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
17
17
  parser: {};
18
18
  }, ((({
19
19
  [x: string]: {
20
- post: {
20
+ delete: {
21
21
  body: unknown;
22
22
  params: {};
23
23
  query: unknown;
@@ -25,8 +25,8 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
25
25
  response: {
26
26
  200: Response;
27
27
  400: "Cookies are missing";
28
- 401: "No auth provider found";
29
- 500: `Failed to signout: ${string}`;
28
+ 401: "No auth provider found" | "No user session found";
29
+ 500: string;
30
30
  };
31
31
  };
32
32
  };
@@ -40,7 +40,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
40
40
  response: {
41
41
  200: Response;
42
42
  400: "Cookies are missing" | "Invalid provider";
43
- 401: "Invalid provider" | "No auth provider found" | "No user session found";
43
+ 401: "Client provider not found" | "No auth provider found" | "No user session found";
44
44
  501: "Provider does not support revocation";
45
45
  500: `Failed to revoke token: ${string}`;
46
46
  };
@@ -56,8 +56,6 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
56
56
  response: {
57
57
  200: Response;
58
58
  400: "Cookies are missing";
59
- 401: "Invalid provider";
60
- 501: "Provider is not refreshable";
61
59
  500: `Error: ${string} - ${string}` | `Unknown Error: ${string}`;
62
60
  };
63
61
  };
@@ -72,7 +70,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
72
70
  response: {
73
71
  200: Response;
74
72
  400: "Cookies are missing" | "Invalid provider" | "No refresh token found";
75
- 401: "Invalid provider" | "No auth provider found" | "No user session found";
73
+ 401: "Client provider not found" | "No auth provider found" | "No user session found";
76
74
  501: "Provider is not refreshable";
77
75
  500: `Failed to refresh token: ${string}`;
78
76
  };
@@ -91,7 +89,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
91
89
  response: {
92
90
  200: import("undici-types").Response;
93
91
  400: "Cookies are missing" | "Provider is required" | "Invalid provider";
94
- 401: "Invalid provider";
92
+ 401: "Client provider not found";
95
93
  500: `${string} - ${string}` | `Unknown error: ${string}`;
96
94
  422: {
97
95
  type: "validation";
@@ -120,7 +118,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
120
118
  response: {
121
119
  200: import("undici-types").Response;
122
120
  400: "Cookies are missing" | "Provider is required" | "Invalid provider";
123
- 401: "Invalid provider";
121
+ 401: "Client provider not found";
124
122
  500: `${string} - ${string}` | `Unknown error: ${string}`;
125
123
  422: {
126
124
  type: "validation";
@@ -146,7 +144,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
146
144
  response: {
147
145
  200: import("undici-types").Response;
148
146
  400: "Cookies are missing" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
149
- 401: "Invalid provider" | "No auth provider found";
147
+ 401: "Invalid provider" | "Client provider not found" | "No auth provider found";
150
148
  500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
151
149
  };
152
150
  };
@@ -161,7 +159,7 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
161
159
  response: {
162
160
  200: Response;
163
161
  400: "Cookies are missing";
164
- 401: "Invalid provider" | "No auth provider found" | "No user session found";
162
+ 401: "Invalid provider" | "Client provider not found" | "No auth provider found" | "No user session found";
165
163
  500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
166
164
  };
167
165
  };
@@ -30,7 +30,7 @@ export declare const profile: <UserType>({ clientProviders, profileRoute, onProf
30
30
  response: {
31
31
  200: Response;
32
32
  400: "Cookies are missing";
33
- 401: "Invalid provider" | "No auth provider found" | "No user session found";
33
+ 401: "Invalid provider" | "Client provider not found" | "No auth provider found" | "No user session found";
34
34
  500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
35
35
  };
36
36
  };
@@ -30,7 +30,7 @@ export declare const refresh: <UserType>({ clientProviders, refreshRoute, onRefr
30
30
  response: {
31
31
  200: Response;
32
32
  400: "Cookies are missing" | "Invalid provider" | "No refresh token found";
33
- 401: "Invalid provider" | "No auth provider found" | "No user session found";
33
+ 401: "Client provider not found" | "No auth provider found" | "No user session found";
34
34
  501: "Provider is not refreshable";
35
35
  500: `Failed to refresh token: ${string}`;
36
36
  };
@@ -30,7 +30,7 @@ export declare const revoke: <UserType>({ clientProviders, revokeRoute, onRevoca
30
30
  response: {
31
31
  200: Response;
32
32
  400: "Cookies are missing" | "Invalid provider";
33
- 401: "Invalid provider" | "No auth provider found" | "No user session found";
33
+ 401: "Client provider not found" | "No auth provider found" | "No user session found";
34
34
  501: "Provider does not support revocation";
35
35
  500: `Failed to revoke token: ${string}`;
36
36
  };
@@ -1,17 +1,19 @@
1
1
  import { Elysia } from 'elysia';
2
- import { RouteString } from './types';
3
- type SignOutProps = {
2
+ import { OnSignOut, RouteString } from './types';
3
+ type SignOutProps<UserType> = {
4
4
  signoutRoute?: RouteString;
5
- onSignOut?: () => void;
5
+ onSignOut?: OnSignOut<UserType>;
6
6
  };
7
- export declare const signout: ({ signoutRoute, onSignOut }: SignOutProps) => Elysia<"", {
7
+ export declare const signout: <UserType>({ signoutRoute, onSignOut }: SignOutProps<UserType>) => Elysia<"", {
8
8
  decorator: {};
9
- store: {};
9
+ store: {
10
+ session: import("./types").SessionRecord<UserType>;
11
+ };
10
12
  derive: {};
11
13
  resolve: {};
12
14
  }, {
13
- typebox: import("@sinclair/typebox").TModule<{}>;
14
15
  error: {};
16
+ typebox: import("@sinclair/typebox").TModule<{}, {}>;
15
17
  }, {
16
18
  schema: {};
17
19
  macro: {};
@@ -19,7 +21,7 @@ export declare const signout: ({ signoutRoute, onSignOut }: SignOutProps) => Ely
19
21
  parser: {};
20
22
  }, {
21
23
  [x: string]: {
22
- post: {
24
+ delete: {
23
25
  body: unknown;
24
26
  params: {};
25
27
  query: unknown;
@@ -27,8 +29,8 @@ export declare const signout: ({ signoutRoute, onSignOut }: SignOutProps) => Ely
27
29
  response: {
28
30
  200: Response;
29
31
  400: "Cookies are missing";
30
- 401: "No auth provider found";
31
- 500: `Failed to signout: ${string}`;
32
+ 401: "No auth provider found" | "No user session found";
33
+ 500: string;
32
34
  };
33
35
  };
34
36
  };
@@ -1,11 +1,11 @@
1
1
  import { Elysia } from 'elysia';
2
- import { ClientProviders, RouteString } from './types';
3
- type StatusProps = {
2
+ import { ClientProviders, OnStatus, RouteString } from './types';
3
+ type StatusProps<UserType> = {
4
4
  clientProviders: ClientProviders;
5
5
  statusRoute?: RouteString;
6
- onStatus?: () => void;
6
+ onStatus?: OnStatus<UserType>;
7
7
  };
8
- export declare const status: <UserType>({ clientProviders, statusRoute, onStatus }: StatusProps) => Elysia<"", {
8
+ export declare const status: <UserType>({ clientProviders, statusRoute, onStatus }: StatusProps<UserType>) => Elysia<"", {
9
9
  decorator: {};
10
10
  store: {
11
11
  session: import("./types").SessionRecord<UserType>;
@@ -30,8 +30,6 @@ export declare const status: <UserType>({ clientProviders, statusRoute, onStatus
30
30
  response: {
31
31
  200: Response;
32
32
  400: "Cookies are missing";
33
- 401: "Invalid provider";
34
- 501: "Provider is not refreshable";
35
33
  500: `Error: ${string} - ${string}` | `Unknown Error: ${string}`;
36
34
  };
37
35
  };
@@ -6,7 +6,7 @@ type SessionData<UserType> = {
6
6
  refreshToken?: string;
7
7
  expiresAt: number;
8
8
  };
9
- type Oauth2ConfigOptions = {
9
+ export type OAuth2ConfigurationOptions = {
10
10
  [Provider in ProviderOption]?: {
11
11
  credentials: CredentialsFor<Provider>;
12
12
  scope?: string[];
@@ -27,19 +27,33 @@ export type OnCallback<UserType> = ({ authProvider, tokenResponse, userProfile,
27
27
  session: SessionRecord<UserType>;
28
28
  user_session_id: Cookie<string | undefined>;
29
29
  }) => void | Promise<void>;
30
- export type OnRefresh = ({ tokenResponse }: {
30
+ export type OnAuthorize = ({ authProvider, authorizationUrl }: {
31
+ authProvider: string;
32
+ authorizationUrl: URL;
33
+ }) => void | Promise<void>;
34
+ export type OnRefresh = ({ tokenResponse, authProvider }: {
31
35
  tokenResponse: OAuth2TokenResponse;
36
+ authProvider: string;
32
37
  }) => void | Promise<void>;
33
- export type OnProfile = ({ userProfile }: {
38
+ export type OnProfile = ({ userProfile, authProvider }: {
34
39
  userProfile: Record<string, unknown>;
40
+ authProvider: string;
35
41
  }) => void | Promise<void>;
36
- export type OnRevocation = ({ tokenToRevoke }: {
42
+ export type OnRevocation = ({ tokenToRevoke, authProvider }: {
37
43
  tokenToRevoke: string;
44
+ authProvider: string;
45
+ }) => void | Promise<void>;
46
+ export type OnStatus<UserType> = ({ user }: {
47
+ user: UserType | null;
48
+ }) => void | Promise<void>;
49
+ export type OnSignOut<UserType> = ({ authProvider, user }: {
50
+ authProvider: string;
51
+ user: UserType | null;
38
52
  }) => void | Promise<void>;
39
53
  export type RouteString = `/${string}`;
40
54
  export type AuthorizeRoute = `${string}/:provider${'' | `/${string}`}`;
41
55
  export type AbsoluteAuthProps<UserType> = {
42
- config: Oauth2ConfigOptions;
56
+ providersConfiguration: OAuth2ConfigurationOptions;
43
57
  authorizeRoute?: AuthorizeRoute;
44
58
  profileRoute?: RouteString;
45
59
  callbackRoute?: RouteString;
@@ -47,11 +61,11 @@ export type AbsoluteAuthProps<UserType> = {
47
61
  revokeRoute?: RouteString;
48
62
  signoutRoute?: RouteString;
49
63
  statusRoute?: RouteString;
50
- onAuthorize?: () => void;
64
+ onAuthorize?: OnAuthorize;
51
65
  onCallback?: OnCallback<UserType>;
52
- onStatus?: () => void;
66
+ onStatus?: OnStatus<UserType>;
53
67
  onRefresh?: OnRefresh;
54
- onSignOut?: () => void;
68
+ onSignOut?: OnSignOut<UserType>;
55
69
  onRevocation?: OnRevocation;
56
70
  onProfile?: OnProfile;
57
71
  };
@@ -67,6 +81,6 @@ export type InsantiateUserSessionProps<UserType> = {
67
81
  session: SessionRecord<UserType>;
68
82
  user_session_id: Cookie<string | undefined>;
69
83
  createUser: () => UserType | Promise<UserType>;
70
- getUser: () => UserType | Promise<UserType | null>;
84
+ getUser: () => UserType | null | undefined | Promise<UserType | null | undefined>;
71
85
  };
72
86
  export {};
@@ -1,3 +1,4 @@
1
- import { AbsoluteAuthProps, InsantiateUserSessionProps } from './types';
1
+ import { AbsoluteAuthProps, InsantiateUserSessionProps, OAuth2ConfigurationOptions } from './types';
2
2
  export declare const instantiateUserSession: <UserType>({ user_session_id, session, tokenResponse, getUser, createUser }: InsantiateUserSessionProps<UserType>) => Promise<void>;
3
- export declare const createAuthConfig: <UserType>(props: AbsoluteAuthProps<UserType>) => AbsoluteAuthProps<UserType>;
3
+ export declare const createAuthConfiguration: <UserType>(configuration: AbsoluteAuthProps<UserType>) => AbsoluteAuthProps<UserType>;
4
+ export declare const createProvidersConfiguration: (providersConfiguration: OAuth2ConfigurationOptions) => OAuth2ConfigurationOptions;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.1",
2
+ "version": "0.6.0",
3
3
  "name": "@absolutejs/auth",
4
4
  "description": "An authorization library for absolutejs",
5
5
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "elysia": ">= 1.2.0"
34
34
  },
35
35
  "dependencies": {
36
- "citra": "0.15.1"
36
+ "citra": "0.19.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@absolutejs/absolute": "0.4.0",