antarctic 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +252 -0
  2. package/dist/auth.d.ts +19 -11
  3. package/dist/auth.js +16 -23
  4. package/dist/index.d.ts +1 -1
  5. package/dist/providers/42.d.ts +4 -4
  6. package/dist/providers/42.js +9 -8
  7. package/dist/providers/amazon-cognito.d.ts +4 -4
  8. package/dist/providers/amazon-cognito.js +9 -8
  9. package/dist/providers/anilist.d.ts +4 -4
  10. package/dist/providers/anilist.js +10 -9
  11. package/dist/providers/apple.d.ts +3 -3
  12. package/dist/providers/apple.js +8 -7
  13. package/dist/providers/atlassian.d.ts +4 -4
  14. package/dist/providers/atlassian.js +9 -8
  15. package/dist/providers/auth0.d.ts +4 -4
  16. package/dist/providers/auth0.js +9 -8
  17. package/dist/providers/authentik.d.ts +4 -4
  18. package/dist/providers/authentik.js +9 -8
  19. package/dist/providers/autodesk.d.ts +4 -4
  20. package/dist/providers/autodesk.js +9 -8
  21. package/dist/providers/battlenet.d.ts +4 -4
  22. package/dist/providers/battlenet.js +9 -8
  23. package/dist/providers/bitbucket.d.ts +4 -4
  24. package/dist/providers/bitbucket.js +10 -9
  25. package/dist/providers/box.d.ts +4 -4
  26. package/dist/providers/box.js +9 -8
  27. package/dist/providers/bungie.d.ts +4 -4
  28. package/dist/providers/bungie.js +9 -8
  29. package/dist/providers/coinbase.d.ts +4 -4
  30. package/dist/providers/coinbase.js +9 -8
  31. package/dist/providers/discord.d.ts +4 -4
  32. package/dist/providers/discord.js +9 -8
  33. package/dist/providers/donation-alerts.d.ts +4 -4
  34. package/dist/providers/donation-alerts.js +9 -8
  35. package/dist/providers/dribbble.d.ts +4 -4
  36. package/dist/providers/dribbble.js +9 -8
  37. package/dist/providers/dropbox.d.ts +4 -4
  38. package/dist/providers/dropbox.js +9 -8
  39. package/dist/providers/epicgames.d.ts +4 -4
  40. package/dist/providers/epicgames.js +9 -8
  41. package/dist/providers/etsy.d.ts +4 -4
  42. package/dist/providers/etsy.js +8 -7
  43. package/dist/providers/facebook.d.ts +4 -4
  44. package/dist/providers/facebook.js +9 -8
  45. package/dist/providers/figma.d.ts +4 -4
  46. package/dist/providers/figma.js +9 -8
  47. package/dist/providers/gitea.d.ts +4 -4
  48. package/dist/providers/gitea.js +9 -8
  49. package/dist/providers/github.d.ts +4 -4
  50. package/dist/providers/github.js +9 -8
  51. package/dist/providers/gitlab.d.ts +4 -4
  52. package/dist/providers/gitlab.js +9 -8
  53. package/dist/providers/google.d.ts +4 -4
  54. package/dist/providers/google.js +9 -8
  55. package/dist/providers/intuit.d.ts +4 -4
  56. package/dist/providers/intuit.js +9 -8
  57. package/dist/providers/kakao.d.ts +4 -4
  58. package/dist/providers/kakao.js +9 -8
  59. package/dist/providers/keycloak.d.ts +4 -4
  60. package/dist/providers/keycloak.js +9 -8
  61. package/dist/providers/kick.d.ts +4 -4
  62. package/dist/providers/kick.js +9 -8
  63. package/dist/providers/lichess.d.ts +4 -4
  64. package/dist/providers/lichess.js +9 -8
  65. package/dist/providers/line.d.ts +4 -4
  66. package/dist/providers/line.js +9 -8
  67. package/dist/providers/linear.d.ts +4 -4
  68. package/dist/providers/linear.js +9 -8
  69. package/dist/providers/linkedin.d.ts +4 -4
  70. package/dist/providers/linkedin.js +9 -8
  71. package/dist/providers/mastodon.d.ts +4 -4
  72. package/dist/providers/mastodon.js +9 -8
  73. package/dist/providers/mercadolibre.d.ts +4 -4
  74. package/dist/providers/mercadolibre.js +10 -9
  75. package/dist/providers/mercadopago.d.ts +4 -4
  76. package/dist/providers/mercadopago.js +10 -9
  77. package/dist/providers/microsoft-entra-id.d.ts +4 -4
  78. package/dist/providers/microsoft-entra-id.js +9 -8
  79. package/dist/providers/myanimelist.d.ts +4 -4
  80. package/dist/providers/myanimelist.js +10 -9
  81. package/dist/providers/naver.d.ts +4 -4
  82. package/dist/providers/naver.js +10 -9
  83. package/dist/providers/notion.d.ts +4 -4
  84. package/dist/providers/notion.js +10 -9
  85. package/dist/providers/okta.d.ts +4 -4
  86. package/dist/providers/okta.js +9 -8
  87. package/dist/providers/osu.d.ts +4 -4
  88. package/dist/providers/osu.js +9 -8
  89. package/dist/providers/patreon.d.ts +4 -4
  90. package/dist/providers/patreon.js +9 -8
  91. package/dist/providers/polar.d.ts +4 -4
  92. package/dist/providers/polar.js +9 -8
  93. package/dist/providers/reddit.d.ts +4 -4
  94. package/dist/providers/reddit.js +9 -8
  95. package/dist/providers/roblox.d.ts +4 -4
  96. package/dist/providers/roblox.js +9 -8
  97. package/dist/providers/salesforce.d.ts +4 -4
  98. package/dist/providers/salesforce.js +9 -8
  99. package/dist/providers/shikimori.d.ts +4 -4
  100. package/dist/providers/shikimori.js +10 -9
  101. package/dist/providers/slack.d.ts +4 -4
  102. package/dist/providers/slack.js +9 -8
  103. package/dist/providers/spotify.d.ts +4 -4
  104. package/dist/providers/spotify.js +9 -8
  105. package/dist/providers/startgg.d.ts +4 -4
  106. package/dist/providers/startgg.js +8 -7
  107. package/dist/providers/strava.d.ts +4 -4
  108. package/dist/providers/strava.js +9 -8
  109. package/dist/providers/tiktok.d.ts +4 -4
  110. package/dist/providers/tiktok.js +9 -8
  111. package/dist/providers/tiltify.d.ts +4 -4
  112. package/dist/providers/tiltify.js +9 -8
  113. package/dist/providers/tumblr.d.ts +4 -4
  114. package/dist/providers/tumblr.js +9 -8
  115. package/dist/providers/twitch.d.ts +4 -4
  116. package/dist/providers/twitch.js +9 -8
  117. package/dist/providers/twitter.d.ts +4 -4
  118. package/dist/providers/twitter.js +9 -8
  119. package/dist/providers/vk.d.ts +4 -4
  120. package/dist/providers/vk.js +9 -8
  121. package/dist/providers/withings.d.ts +4 -4
  122. package/dist/providers/withings.js +9 -8
  123. package/dist/providers/workos.d.ts +4 -4
  124. package/dist/providers/workos.js +10 -9
  125. package/dist/providers/yahoo.d.ts +4 -4
  126. package/dist/providers/yahoo.js +9 -8
  127. package/dist/providers/yandex.d.ts +4 -4
  128. package/dist/providers/yandex.js +9 -8
  129. package/dist/providers/zoom.d.ts +4 -4
  130. package/dist/providers/zoom.js +9 -8
  131. package/package.json +2 -1
  132. package/readme.md +0 -155
@@ -1,5 +1,5 @@
1
1
  import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://discord.com/oauth2/authorize";
4
4
  const tokenEndpoint = "https://discord.com/api/oauth2/token";
5
5
  const tokenRevocationEndpoint = "https://discord.com/api/oauth2/token/revoke";
@@ -9,7 +9,7 @@ const defaultScopes = ["identify", "email"];
9
9
  export class Discord {
10
10
  client;
11
11
  auth = null;
12
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
12
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
13
13
  if (typeof clientIdOrOptions === "object") {
14
14
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, { redirectURI: true });
15
15
  this.client = new OAuth2Client(this.auth.clientId, this.auth.clientSecret, this.auth.redirectURI);
@@ -44,13 +44,13 @@ export class Discord {
44
44
  const state = generateOAuthState();
45
45
  const codeVerifier = generateOAuthCodeVerifier();
46
46
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
47
- await saveOAuthState(auth.store, state, { codeVerifier });
48
- return url;
47
+ const payload = { codeVerifier };
48
+ return { url, state, payload };
49
49
  }
50
- async getUser(query) {
51
- const auth = requireAuthConfig(this.auth);
50
+ async getUser(query, saved) {
51
+ requireAuthConfig(this.auth);
52
52
  const { code, state } = parseCallbackQuery(query);
53
- const stored = await consumeOAuthState(auth.store, state);
53
+ const stored = resolveOAuthState(state, saved);
54
54
  if (typeof stored.codeVerifier !== "string") {
55
55
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
56
56
  }
@@ -63,7 +63,8 @@ export class Discord {
63
63
  name: profileString(profile.global_name) ?? profileString(profile.username),
64
64
  email: profileString(profile.email),
65
65
  image: avatar === null ? null : `https://cdn.discordapp.com/avatars/${id}/${avatar}.png`,
66
- raw: profile
66
+ raw: profile,
67
+ ...extractOAuthTokens(tokens)
67
68
  };
68
69
  }
69
70
  }
@@ -1,5 +1,5 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface DonationAlertsOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class DonationAlerts {
@@ -7,11 +7,11 @@ export declare class DonationAlerts {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: DonationAlertsOptions);
10
+ constructor(options?: DonationAlertsOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
12
12
  createAuthorizationURL(scopes: string[]): URL;
13
13
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
14
  refreshAccessToken(refreshToken: string, scopes: string[]): Promise<OAuth2Tokens>;
15
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
16
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
15
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
16
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
17
17
  }
@@ -1,5 +1,5 @@
1
1
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.donationalerts.com/oauth/authorize";
4
4
  const tokenEndpoint = "https://www.donationalerts.com/oauth/token";
5
5
  const userEndpoint = "https://www.donationalerts.com/api/v1/user/oauth";
@@ -10,7 +10,7 @@ export class DonationAlerts {
10
10
  clientSecret;
11
11
  redirectURI;
12
12
  auth = null;
13
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
13
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
14
14
  if (typeof clientIdOrOptions === "object") {
15
15
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
16
16
  clientSecret: true,
@@ -62,13 +62,13 @@ export class DonationAlerts {
62
62
  const url = this.createAuthorizationURL(resolveScopes(scopes, auth, defaultScopes));
63
63
  // The legacy URL builder does not take a state parameter.
64
64
  url.searchParams.set("state", state);
65
- await saveOAuthState(auth.store, state, {});
66
- return url;
65
+ const payload = {};
66
+ return { url, state, payload };
67
67
  }
68
- async getUser(query) {
69
- const auth = requireAuthConfig(this.auth);
68
+ async getUser(query, saved) {
69
+ requireAuthConfig(this.auth);
70
70
  const { code, state } = parseCallbackQuery(query);
71
- await consumeOAuthState(auth.store, state);
71
+ resolveOAuthState(state, saved);
72
72
  const tokens = await this.validateAuthorizationCode(code);
73
73
  const body = await fetchUserProfile(userEndpoint, tokens.accessToken());
74
74
  const profile = body.data;
@@ -81,7 +81,8 @@ export class DonationAlerts {
81
81
  name: profileString(user.name) ?? profileString(user.code),
82
82
  email: profileString(user.email),
83
83
  image: profileString(user.avatar),
84
- raw: user
84
+ raw: user,
85
+ ...extractOAuthTokens(tokens)
85
86
  };
86
87
  }
87
88
  }
@@ -1,5 +1,5 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface DribbbleOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Dribbble {
@@ -7,10 +7,10 @@ export declare class Dribbble {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: DribbbleOptions);
10
+ constructor(options?: DribbbleOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
12
12
  createAuthorizationURL(state: string, scopes: string[]): URL;
13
13
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://dribbble.com/oauth/authorize";
4
4
  const tokenEndpoint = "https://dribbble.com/oauth/token";
5
5
  const userEndpoint = "https://api.dribbble.com/v2/user";
@@ -11,7 +11,7 @@ export class Dribbble {
11
11
  clientSecret;
12
12
  redirectURI;
13
13
  auth = null;
14
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
14
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
15
15
  if (typeof clientIdOrOptions === "object") {
16
16
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
17
17
  clientSecret: true,
@@ -53,13 +53,13 @@ export class Dribbble {
53
53
  const auth = requireAuthConfig(this.auth);
54
54
  const state = generateOAuthState();
55
55
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
56
- await saveOAuthState(auth.store, state, {});
57
- return url;
56
+ const payload = {};
57
+ return { url, state, payload };
58
58
  }
59
- async getUser(query) {
60
- const auth = requireAuthConfig(this.auth);
59
+ async getUser(query, saved) {
60
+ requireAuthConfig(this.auth);
61
61
  const { code, state } = parseCallbackQuery(query);
62
- await consumeOAuthState(auth.store, state);
62
+ resolveOAuthState(state, saved);
63
63
  const tokens = await this.validateAuthorizationCode(code);
64
64
  const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
65
65
  return {
@@ -68,7 +68,8 @@ export class Dribbble {
68
68
  // The v2 user endpoint does not expose an email address.
69
69
  email: null,
70
70
  image: profileString(profile.avatar_url),
71
- raw: profile
71
+ raw: profile,
72
+ ...extractOAuthTokens(tokens)
72
73
  };
73
74
  }
74
75
  }
@@ -1,16 +1,16 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface DropboxOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Dropbox {
6
6
  private client;
7
7
  private auth;
8
- constructor(options: DropboxOptions);
8
+ constructor(options?: DropboxOptions);
9
9
  constructor(clientId: string, clientSecret: string, redirectURI: string);
10
10
  createAuthorizationURL(state: string, scopes: string[]): URL;
11
11
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
12
12
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
13
  revokeToken(token: string): Promise<void>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.dropbox.com/oauth2/authorize";
4
4
  const tokenEndpoint = "https://api.dropboxapi.com/oauth2/token";
5
5
  const tokenRevocationEndpoint = "https://api.dropboxapi.com/2/auth/token/revoke";
@@ -9,7 +9,7 @@ const defaultScopes = ["account_info.read"];
9
9
  export class Dropbox {
10
10
  client;
11
11
  auth = null;
12
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
12
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
13
13
  if (typeof clientIdOrOptions === "object") {
14
14
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
15
15
  clientSecret: true,
@@ -40,13 +40,13 @@ export class Dropbox {
40
40
  const auth = requireAuthConfig(this.auth);
41
41
  const state = generateOAuthState();
42
42
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
43
- await saveOAuthState(auth.store, state, {});
44
- return url;
43
+ const payload = {};
44
+ return { url, state, payload };
45
45
  }
46
- async getUser(query) {
47
- const auth = requireAuthConfig(this.auth);
46
+ async getUser(query, saved) {
47
+ requireAuthConfig(this.auth);
48
48
  const { code, state } = parseCallbackQuery(query);
49
- await consumeOAuthState(auth.store, state);
49
+ resolveOAuthState(state, saved);
50
50
  const tokens = await this.validateAuthorizationCode(code);
51
51
  const profile = await fetchCurrentAccount(tokens.accessToken());
52
52
  let name = null;
@@ -58,7 +58,8 @@ export class Dropbox {
58
58
  name,
59
59
  email: profileString(profile.email),
60
60
  image: profileString(profile.profile_photo_url),
61
- raw: profile
61
+ raw: profile,
62
+ ...extractOAuthTokens(tokens)
62
63
  };
63
64
  }
64
65
  }
@@ -1,16 +1,16 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface EpicGamesOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class EpicGames {
6
6
  private client;
7
7
  private auth;
8
- constructor(options: EpicGamesOptions);
8
+ constructor(options?: EpicGamesOptions);
9
9
  constructor(clientId: string, clientSecret: string, redirectURI: string);
10
10
  createAuthorizationURL(state: string, scopes: string[]): URL;
11
11
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
12
12
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
13
  revokeToken(token: string): Promise<void>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.epicgames.com/id/authorize";
4
4
  const tokenEndpoint = "https://api.epicgames.dev/epic/oauth/v2/token";
5
5
  const tokenRevocationEndpoint = "https://api.epicgames.dev/epic/oauth/v2/revoke";
@@ -9,7 +9,7 @@ const defaultScopes = ["basic_profile"];
9
9
  export class EpicGames {
10
10
  client;
11
11
  auth = null;
12
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
12
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
13
13
  if (typeof clientIdOrOptions === "object") {
14
14
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
15
15
  clientSecret: true,
@@ -40,13 +40,13 @@ export class EpicGames {
40
40
  const auth = requireAuthConfig(this.auth);
41
41
  const state = generateOAuthState();
42
42
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
43
- await saveOAuthState(auth.store, state, {});
44
- return url;
43
+ const payload = {};
44
+ return { url, state, payload };
45
45
  }
46
- async getUser(query) {
47
- const auth = requireAuthConfig(this.auth);
46
+ async getUser(query, saved) {
47
+ requireAuthConfig(this.auth);
48
48
  const { code, state } = parseCallbackQuery(query);
49
- await consumeOAuthState(auth.store, state);
49
+ resolveOAuthState(state, saved);
50
50
  const tokens = await this.validateAuthorizationCode(code);
51
51
  const claims = await fetchUserProfile(userinfoEndpoint, tokens.accessToken());
52
52
  return {
@@ -55,7 +55,8 @@ export class EpicGames {
55
55
  // Epic Games does not expose user emails or avatars.
56
56
  email: null,
57
57
  image: null,
58
- raw: claims
58
+ raw: claims,
59
+ ...extractOAuthTokens(tokens)
59
60
  };
60
61
  }
61
62
  }
@@ -1,15 +1,15 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface EtsyOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Etsy {
6
6
  private client;
7
7
  private auth;
8
- constructor(options: EtsyOptions);
8
+ constructor(options?: EtsyOptions);
9
9
  constructor(clientId: string, redirectURI: string);
10
10
  createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): Promise<URL>;
11
11
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
12
12
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
14
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
13
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
14
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
15
15
  }
@@ -1,5 +1,5 @@
1
1
  import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.etsy.com/oauth/connect";
4
4
  const tokenEndpoint = "https://api.etsy.com/v3/public/oauth/token";
5
5
  const meEndpoint = "https://openapi.etsy.com/v3/application/users/me";
@@ -9,7 +9,7 @@ const defaultScopes = ["email_r"];
9
9
  export class Etsy {
10
10
  client;
11
11
  auth = null;
12
- constructor(clientIdOrOptions, redirectURI) {
12
+ constructor(clientIdOrOptions = {}, redirectURI) {
13
13
  if (typeof clientIdOrOptions === "object") {
14
14
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, { redirectURI: true });
15
15
  this.client = new OAuth2Client(this.auth.clientId, null, this.auth.redirectURI);
@@ -35,13 +35,13 @@ export class Etsy {
35
35
  const state = generateOAuthState();
36
36
  const codeVerifier = generateOAuthCodeVerifier();
37
37
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
38
- await saveOAuthState(auth.store, state, { codeVerifier });
39
- return url;
38
+ const payload = { codeVerifier };
39
+ return { url, state, payload };
40
40
  }
41
- async getUser(query) {
41
+ async getUser(query, saved) {
42
42
  const auth = requireAuthConfig(this.auth);
43
43
  const { code, state } = parseCallbackQuery(query);
44
- const stored = await consumeOAuthState(auth.store, state);
44
+ const stored = resolveOAuthState(state, saved);
45
45
  if (typeof stored.codeVerifier !== "string") {
46
46
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
47
47
  }
@@ -63,7 +63,8 @@ export class Etsy {
63
63
  name,
64
64
  email: profileString(profile.primary_email),
65
65
  image: profileString(profile.image_url_75x75),
66
- raw: profile
66
+ raw: profile,
67
+ ...extractOAuthTokens(tokens)
67
68
  };
68
69
  }
69
70
  }
@@ -1,5 +1,5 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface FacebookOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Facebook {
@@ -7,10 +7,10 @@ export declare class Facebook {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: FacebookOptions);
10
+ constructor(options?: FacebookOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
12
12
  createAuthorizationURL(state: string, scopes: string[]): URL;
13
13
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.facebook.com/v16.0/dialog/oauth";
4
4
  const tokenEndpoint = "https://graph.facebook.com/v16.0/oauth/access_token";
5
5
  const userEndpoint = "https://graph.facebook.com/v16.0/me";
@@ -10,7 +10,7 @@ export class Facebook {
10
10
  clientSecret;
11
11
  redirectURI;
12
12
  auth = null;
13
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
13
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
14
14
  if (typeof clientIdOrOptions === "object") {
15
15
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
16
16
  clientSecret: true,
@@ -52,13 +52,13 @@ export class Facebook {
52
52
  const auth = requireAuthConfig(this.auth);
53
53
  const state = generateOAuthState();
54
54
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
55
- await saveOAuthState(auth.store, state, {});
56
- return url;
55
+ const payload = {};
56
+ return { url, state, payload };
57
57
  }
58
- async getUser(query) {
59
- const auth = requireAuthConfig(this.auth);
58
+ async getUser(query, saved) {
59
+ requireAuthConfig(this.auth);
60
60
  const { code, state } = parseCallbackQuery(query);
61
- await consumeOAuthState(auth.store, state);
61
+ resolveOAuthState(state, saved);
62
62
  const tokens = await this.validateAuthorizationCode(code);
63
63
  const url = new URL(userEndpoint);
64
64
  url.searchParams.set("fields", "id,name,email,picture.width(256)");
@@ -75,7 +75,8 @@ export class Facebook {
75
75
  name: profileString(profile.name),
76
76
  email: profileString(profile.email),
77
77
  image,
78
- raw: profile
78
+ raw: profile,
79
+ ...extractOAuthTokens(tokens)
79
80
  };
80
81
  }
81
82
  }
@@ -1,15 +1,15 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface FigmaOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Figma {
6
6
  private client;
7
7
  private auth;
8
- constructor(options: FigmaOptions);
8
+ constructor(options?: FigmaOptions);
9
9
  constructor(clientId: string, clientSecret: string, redirectURI: string);
10
10
  createAuthorizationURL(state: string, scopes: string[]): URL;
11
11
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
12
12
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
14
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
13
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
14
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
15
15
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.figma.com/oauth";
4
4
  const tokenEndpoint = "https://api.figma.com/v1/oauth/token";
5
5
  const refreshEndpoint = "https://api.figma.com/v1/oauth/refresh";
@@ -9,7 +9,7 @@ const defaultScopes = ["current_user:read"];
9
9
  export class Figma {
10
10
  client;
11
11
  auth = null;
12
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
12
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
13
13
  if (typeof clientIdOrOptions === "object") {
14
14
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
15
15
  clientSecret: true,
@@ -37,13 +37,13 @@ export class Figma {
37
37
  const auth = requireAuthConfig(this.auth);
38
38
  const state = generateOAuthState();
39
39
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
40
- await saveOAuthState(auth.store, state, {});
41
- return url;
40
+ const payload = {};
41
+ return { url, state, payload };
42
42
  }
43
- async getUser(query) {
44
- const auth = requireAuthConfig(this.auth);
43
+ async getUser(query, saved) {
44
+ requireAuthConfig(this.auth);
45
45
  const { code, state } = parseCallbackQuery(query);
46
- await consumeOAuthState(auth.store, state);
46
+ resolveOAuthState(state, saved);
47
47
  const tokens = await this.validateAuthorizationCode(code);
48
48
  const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
49
49
  return {
@@ -51,7 +51,8 @@ export class Figma {
51
51
  name: profileString(profile.handle),
52
52
  email: profileString(profile.email),
53
53
  image: profileString(profile.img_url),
54
- raw: profile
54
+ raw: profile,
55
+ ...extractOAuthTokens(tokens)
55
56
  };
56
57
  }
57
58
  }
@@ -1,5 +1,5 @@
1
1
  import type { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface GiteaOptions extends ProviderOptions {
4
4
  baseURL?: string;
5
5
  }
@@ -9,11 +9,11 @@ export declare class Gitea {
9
9
  private baseURL;
10
10
  private client;
11
11
  private auth;
12
- constructor(options: GiteaOptions);
12
+ constructor(options?: GiteaOptions);
13
13
  constructor(baseURL: string, clientId: string, clientSecret: string | null, redirectURI: string);
14
14
  createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): Promise<URL>;
15
15
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
16
16
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
17
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
18
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
17
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
18
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
19
19
  }
@@ -1,6 +1,6 @@
1
1
  import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
2
  import { joinURIAndPath } from "../request.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveOAuthState, resolveScopes } from "../auth.js";
4
4
  const envPrefix = "GITEA";
5
5
  const defaultScopes = ["read:user"];
6
6
  export class Gitea {
@@ -9,7 +9,7 @@ export class Gitea {
9
9
  baseURL;
10
10
  client;
11
11
  auth = null;
12
- constructor(baseURLOrOptions, clientId, clientSecret, redirectURI) {
12
+ constructor(baseURLOrOptions = {}, clientId, clientSecret, redirectURI) {
13
13
  if (typeof baseURLOrOptions === "object") {
14
14
  this.auth = resolveAuthConfig(envPrefix, baseURLOrOptions, { redirectURI: true });
15
15
  this.baseURL = requireProviderOption(baseURLOrOptions.baseURL, envPrefix, "BASE_URL", "baseURL");
@@ -39,13 +39,13 @@ export class Gitea {
39
39
  const state = generateOAuthState();
40
40
  const codeVerifier = generateOAuthCodeVerifier();
41
41
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
42
- await saveOAuthState(auth.store, state, { codeVerifier });
43
- return url;
42
+ const payload = { codeVerifier };
43
+ return { url, state, payload };
44
44
  }
45
- async getUser(query) {
46
- const auth = requireAuthConfig(this.auth);
45
+ async getUser(query, saved) {
46
+ requireAuthConfig(this.auth);
47
47
  const { code, state } = parseCallbackQuery(query);
48
- const stored = await consumeOAuthState(auth.store, state);
48
+ const stored = resolveOAuthState(state, saved);
49
49
  if (typeof stored.codeVerifier !== "string") {
50
50
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
51
51
  }
@@ -57,7 +57,8 @@ export class Gitea {
57
57
  name: profileString(profile.full_name) ?? profileString(profile.login),
58
58
  email: profileString(profile.email),
59
59
  image: profileString(profile.avatar_url),
60
- raw: profile
60
+ raw: profile,
61
+ ...extractOAuthTokens(tokens)
61
62
  };
62
63
  }
63
64
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface GitHubOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class GitHub {
@@ -7,11 +7,11 @@ export declare class GitHub {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: GitHubOptions);
10
+ constructor(options?: GitHubOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string | null);
12
12
  createAuthorizationURL(state: string, scopes: string[]): URL;
13
13
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
14
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
15
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
16
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
15
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
16
+ getUser(query: OAuthCallbackQuery, saved: SavedOAuthState): Promise<OAuthUser>;
17
17
  }