antarctic 0.5.0 → 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.
Files changed (131) hide show
  1. package/dist/auth.d.ts +19 -0
  2. package/dist/auth.js +20 -0
  3. package/dist/index.d.ts +1 -1
  4. package/dist/providers/42.d.ts +3 -3
  5. package/dist/providers/42.js +8 -6
  6. package/dist/providers/amazon-cognito.d.ts +3 -3
  7. package/dist/providers/amazon-cognito.js +8 -6
  8. package/dist/providers/anilist.d.ts +3 -3
  9. package/dist/providers/anilist.js +8 -6
  10. package/dist/providers/apple.d.ts +3 -3
  11. package/dist/providers/apple.js +8 -6
  12. package/dist/providers/atlassian.d.ts +3 -3
  13. package/dist/providers/atlassian.js +8 -6
  14. package/dist/providers/auth0.d.ts +3 -3
  15. package/dist/providers/auth0.js +8 -6
  16. package/dist/providers/authentik.d.ts +3 -3
  17. package/dist/providers/authentik.js +8 -6
  18. package/dist/providers/autodesk.d.ts +3 -3
  19. package/dist/providers/autodesk.js +8 -6
  20. package/dist/providers/battlenet.d.ts +3 -3
  21. package/dist/providers/battlenet.js +8 -6
  22. package/dist/providers/bitbucket.d.ts +3 -3
  23. package/dist/providers/bitbucket.js +8 -6
  24. package/dist/providers/box.d.ts +3 -3
  25. package/dist/providers/box.js +8 -6
  26. package/dist/providers/bungie.d.ts +3 -3
  27. package/dist/providers/bungie.js +8 -6
  28. package/dist/providers/coinbase.d.ts +3 -3
  29. package/dist/providers/coinbase.js +8 -6
  30. package/dist/providers/discord.d.ts +3 -3
  31. package/dist/providers/discord.js +8 -6
  32. package/dist/providers/donation-alerts.d.ts +3 -3
  33. package/dist/providers/donation-alerts.js +8 -6
  34. package/dist/providers/dribbble.d.ts +3 -3
  35. package/dist/providers/dribbble.js +8 -6
  36. package/dist/providers/dropbox.d.ts +3 -3
  37. package/dist/providers/dropbox.js +8 -6
  38. package/dist/providers/epicgames.d.ts +3 -3
  39. package/dist/providers/epicgames.js +8 -6
  40. package/dist/providers/etsy.d.ts +3 -3
  41. package/dist/providers/etsy.js +8 -6
  42. package/dist/providers/facebook.d.ts +3 -3
  43. package/dist/providers/facebook.js +8 -6
  44. package/dist/providers/figma.d.ts +3 -3
  45. package/dist/providers/figma.js +8 -6
  46. package/dist/providers/gitea.d.ts +3 -3
  47. package/dist/providers/gitea.js +8 -6
  48. package/dist/providers/github.d.ts +3 -3
  49. package/dist/providers/github.js +8 -6
  50. package/dist/providers/gitlab.d.ts +3 -3
  51. package/dist/providers/gitlab.js +8 -6
  52. package/dist/providers/google.d.ts +3 -3
  53. package/dist/providers/google.js +8 -6
  54. package/dist/providers/intuit.d.ts +3 -3
  55. package/dist/providers/intuit.js +8 -6
  56. package/dist/providers/kakao.d.ts +3 -3
  57. package/dist/providers/kakao.js +8 -6
  58. package/dist/providers/keycloak.d.ts +3 -3
  59. package/dist/providers/keycloak.js +8 -6
  60. package/dist/providers/kick.d.ts +3 -3
  61. package/dist/providers/kick.js +8 -6
  62. package/dist/providers/lichess.d.ts +3 -3
  63. package/dist/providers/lichess.js +8 -6
  64. package/dist/providers/line.d.ts +3 -3
  65. package/dist/providers/line.js +8 -6
  66. package/dist/providers/linear.d.ts +3 -3
  67. package/dist/providers/linear.js +8 -6
  68. package/dist/providers/linkedin.d.ts +3 -3
  69. package/dist/providers/linkedin.js +8 -6
  70. package/dist/providers/mastodon.d.ts +3 -3
  71. package/dist/providers/mastodon.js +8 -6
  72. package/dist/providers/mercadolibre.d.ts +3 -3
  73. package/dist/providers/mercadolibre.js +8 -6
  74. package/dist/providers/mercadopago.d.ts +3 -3
  75. package/dist/providers/mercadopago.js +8 -6
  76. package/dist/providers/microsoft-entra-id.d.ts +3 -3
  77. package/dist/providers/microsoft-entra-id.js +8 -6
  78. package/dist/providers/myanimelist.d.ts +3 -3
  79. package/dist/providers/myanimelist.js +8 -6
  80. package/dist/providers/naver.d.ts +3 -3
  81. package/dist/providers/naver.js +8 -6
  82. package/dist/providers/notion.d.ts +3 -3
  83. package/dist/providers/notion.js +8 -6
  84. package/dist/providers/okta.d.ts +3 -3
  85. package/dist/providers/okta.js +8 -6
  86. package/dist/providers/osu.d.ts +3 -3
  87. package/dist/providers/osu.js +8 -6
  88. package/dist/providers/patreon.d.ts +3 -3
  89. package/dist/providers/patreon.js +8 -6
  90. package/dist/providers/polar.d.ts +3 -3
  91. package/dist/providers/polar.js +8 -6
  92. package/dist/providers/reddit.d.ts +3 -3
  93. package/dist/providers/reddit.js +8 -6
  94. package/dist/providers/roblox.d.ts +3 -3
  95. package/dist/providers/roblox.js +8 -6
  96. package/dist/providers/salesforce.d.ts +3 -3
  97. package/dist/providers/salesforce.js +8 -6
  98. package/dist/providers/shikimori.d.ts +3 -3
  99. package/dist/providers/shikimori.js +8 -6
  100. package/dist/providers/slack.d.ts +3 -3
  101. package/dist/providers/slack.js +8 -6
  102. package/dist/providers/spotify.d.ts +3 -3
  103. package/dist/providers/spotify.js +8 -6
  104. package/dist/providers/startgg.d.ts +3 -3
  105. package/dist/providers/startgg.js +8 -6
  106. package/dist/providers/strava.d.ts +3 -3
  107. package/dist/providers/strava.js +8 -6
  108. package/dist/providers/tiktok.d.ts +3 -3
  109. package/dist/providers/tiktok.js +8 -6
  110. package/dist/providers/tiltify.d.ts +3 -3
  111. package/dist/providers/tiltify.js +8 -6
  112. package/dist/providers/tumblr.d.ts +3 -3
  113. package/dist/providers/tumblr.js +8 -6
  114. package/dist/providers/twitch.d.ts +3 -3
  115. package/dist/providers/twitch.js +8 -6
  116. package/dist/providers/twitter.d.ts +3 -3
  117. package/dist/providers/twitter.js +8 -6
  118. package/dist/providers/vk.d.ts +3 -3
  119. package/dist/providers/vk.js +8 -6
  120. package/dist/providers/withings.d.ts +3 -3
  121. package/dist/providers/withings.js +8 -6
  122. package/dist/providers/workos.d.ts +3 -3
  123. package/dist/providers/workos.js +8 -6
  124. package/dist/providers/yahoo.d.ts +3 -3
  125. package/dist/providers/yahoo.js +8 -6
  126. package/dist/providers/yandex.d.ts +3 -3
  127. package/dist/providers/yandex.js +8 -6
  128. package/dist/providers/zoom.d.ts +3 -3
  129. package/dist/providers/zoom.js +8 -6
  130. package/package.json +1 -1
  131. package/readme.md +12 -2
@@ -1,6 +1,6 @@
1
1
  import { OAuth2Client, CodeChallengeMethod } 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, saveOAuthState } from "../auth.js";
4
4
  const envPrefix = "MASTODON";
5
5
  const defaultScopes = ["read:accounts"];
6
6
  export class Mastodon {
@@ -45,13 +45,14 @@ export class Mastodon {
45
45
  const state = generateOAuthState();
46
46
  const codeVerifier = generateOAuthCodeVerifier();
47
47
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
48
- await saveOAuthState(auth.store, state, { codeVerifier });
49
- return url;
48
+ const payload = { codeVerifier };
49
+ await saveOAuthState(auth.store, state, payload);
50
+ return { url, state, payload };
50
51
  }
51
- async getUser(query) {
52
+ async getUser(query, saved) {
52
53
  const auth = requireAuthConfig(this.auth);
53
54
  const { code, state } = parseCallbackQuery(query);
54
- const stored = await consumeOAuthState(auth.store, state);
55
+ const stored = await resolveOAuthState(auth.store, state, saved);
55
56
  if (typeof stored.codeVerifier !== "string") {
56
57
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
57
58
  }
@@ -62,7 +63,8 @@ export class Mastodon {
62
63
  name: profileString(profile.display_name) ?? profileString(profile.username),
63
64
  email: null,
64
65
  image: profileString(profile.avatar),
65
- raw: profile
66
+ raw: profile,
67
+ ...extractOAuthTokens(tokens)
66
68
  };
67
69
  }
68
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 MercadoLibreOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class MercadoLibre {
@@ -12,6 +12,6 @@ export declare class MercadoLibre {
12
12
  createAuthorizationURL(state: string, codeVerifier: string): Promise<URL>;
13
13
  validateAuthorizationCode(code: string, codeVerifier: 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
  }
@@ -1,6 +1,6 @@
1
1
  import { createS256CodeChallenge } from "../oauth2.js";
2
2
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, saveOAuthState } from "../auth.js";
4
4
  const authorizationEndpoint = "https://auth.mercadolibre.com/authorization";
5
5
  const tokenEndpoint = "https://api.mercadolibre.com/oauth/token";
6
6
  const userEndpoint = "https://api.mercadolibre.com/users/me";
@@ -66,13 +66,14 @@ export class MercadoLibre {
66
66
  const state = generateOAuthState();
67
67
  const codeVerifier = generateOAuthCodeVerifier();
68
68
  const url = await this.createAuthorizationURL(state, codeVerifier);
69
- await saveOAuthState(auth.store, state, { codeVerifier });
70
- return url;
69
+ const payload = { codeVerifier };
70
+ await saveOAuthState(auth.store, state, payload);
71
+ return { url, state, payload };
71
72
  }
72
- async getUser(query) {
73
+ async getUser(query, saved) {
73
74
  const auth = requireAuthConfig(this.auth);
74
75
  const { code, state } = parseCallbackQuery(query);
75
- const stored = await consumeOAuthState(auth.store, state);
76
+ const stored = await resolveOAuthState(auth.store, state, saved);
76
77
  if (typeof stored.codeVerifier !== "string") {
77
78
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
78
79
  }
@@ -90,7 +91,8 @@ export class MercadoLibre {
90
91
  name: fullName !== "" ? fullName : profileString(profile.nickname),
91
92
  email: profileString(profile.email),
92
93
  image,
93
- raw: profile
94
+ raw: profile,
95
+ ...extractOAuthTokens(tokens)
94
96
  };
95
97
  }
96
98
  }
@@ -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 MercadoPagoOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class MercadoPago {
@@ -12,6 +12,6 @@ export declare class MercadoPago {
12
12
  createAuthorizationURL(state: string, codeVerifier: string): Promise<URL>;
13
13
  validateAuthorizationCode(code: string, codeVerifier: 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
  }
@@ -1,6 +1,6 @@
1
1
  import { createS256CodeChallenge } from "../oauth2.js";
2
2
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, saveOAuthState } from "../auth.js";
4
4
  const authorizationEndpoint = "https://auth.mercadopago.com/authorization";
5
5
  const tokenEndpoint = "https://api.mercadopago.com/oauth/token";
6
6
  const userEndpoint = "https://api.mercadopago.com/users/me";
@@ -66,13 +66,14 @@ export class MercadoPago {
66
66
  const state = generateOAuthState();
67
67
  const codeVerifier = generateOAuthCodeVerifier();
68
68
  const url = await this.createAuthorizationURL(state, codeVerifier);
69
- await saveOAuthState(auth.store, state, { codeVerifier });
70
- return url;
69
+ const payload = { codeVerifier };
70
+ await saveOAuthState(auth.store, state, payload);
71
+ return { url, state, payload };
71
72
  }
72
- async getUser(query) {
73
+ async getUser(query, saved) {
73
74
  const auth = requireAuthConfig(this.auth);
74
75
  const { code, state } = parseCallbackQuery(query);
75
- const stored = await consumeOAuthState(auth.store, state);
76
+ const stored = await resolveOAuthState(auth.store, state, saved);
76
77
  if (typeof stored.codeVerifier !== "string") {
77
78
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
78
79
  }
@@ -90,7 +91,8 @@ export class MercadoPago {
90
91
  name: fullName !== "" ? fullName : profileString(profile.nickname),
91
92
  email: profileString(profile.email),
92
93
  image,
93
- raw: profile
94
+ raw: profile,
95
+ ...extractOAuthTokens(tokens)
94
96
  };
95
97
  }
96
98
  }
@@ -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 MicrosoftEntraIdOptions extends ProviderOptions {
4
4
  tenant?: string;
5
5
  }
@@ -15,6 +15,6 @@ export declare class MicrosoftEntraId {
15
15
  createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): Promise<URL>;
16
16
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
17
17
  refreshAccessToken(refreshToken: string, scopes: string[]): Promise<OAuth2Tokens>;
18
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
19
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
18
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
19
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
20
20
  }
@@ -1,7 +1,7 @@
1
1
  import { createS256CodeChallenge } from "../oauth2.js";
2
2
  import { createOAuth2Request, encodeBasicCredentials, joinURIAndPath, sendTokenRequest } from "../request.js";
3
3
  import { decodeIdToken } from "../oidc.js";
4
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
4
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
5
5
  const userinfoEndpoint = "https://graph.microsoft.com/oidc/userinfo";
6
6
  const envPrefix = "MICROSOFT_ENTRA_ID";
7
7
  const defaultScopes = ["openid", "profile", "email"];
@@ -92,13 +92,14 @@ export class MicrosoftEntraId {
92
92
  const state = generateOAuthState();
93
93
  const codeVerifier = generateOAuthCodeVerifier();
94
94
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
95
- await saveOAuthState(auth.store, state, { codeVerifier });
96
- return url;
95
+ const payload = { codeVerifier };
96
+ await saveOAuthState(auth.store, state, payload);
97
+ return { url, state, payload };
97
98
  }
98
- async getUser(query) {
99
+ async getUser(query, saved) {
99
100
  const auth = requireAuthConfig(this.auth);
100
101
  const { code, state } = parseCallbackQuery(query);
101
- const stored = await consumeOAuthState(auth.store, state);
102
+ const stored = await resolveOAuthState(auth.store, state, saved);
102
103
  if (typeof stored.codeVerifier !== "string") {
103
104
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
104
105
  }
@@ -115,7 +116,8 @@ export class MicrosoftEntraId {
115
116
  name: profileString(claims.name),
116
117
  email: profileString(claims.email) ?? profileString(claims.preferred_username),
117
118
  image: profileString(claims.picture),
118
- raw: claims
119
+ raw: claims,
120
+ ...extractOAuthTokens(tokens)
119
121
  };
120
122
  }
121
123
  }
@@ -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 MyAnimeListOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class MyAnimeList {
@@ -10,6 +10,6 @@ export declare class MyAnimeList {
10
10
  createAuthorizationURL(state: string, codeVerifier: 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 { OAuth2Client, CodeChallengeMethod } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://myanimelist.net/v1/oauth2/authorize";
4
4
  const tokenEndpoint = "https://myanimelist.net/v1/oauth2/token";
5
5
  const userEndpoint = "https://api.myanimelist.net/v2/users/@me";
@@ -34,13 +34,14 @@ export class MyAnimeList {
34
34
  const state = generateOAuthState();
35
35
  const codeVerifier = generateOAuthCodeVerifier();
36
36
  const url = await this.createAuthorizationURL(state, codeVerifier);
37
- await saveOAuthState(auth.store, state, { codeVerifier });
38
- return url;
37
+ const payload = { codeVerifier };
38
+ await saveOAuthState(auth.store, state, payload);
39
+ return { url, state, payload };
39
40
  }
40
- async getUser(query) {
41
+ async getUser(query, saved) {
41
42
  const auth = requireAuthConfig(this.auth);
42
43
  const { code, state } = parseCallbackQuery(query);
43
- const stored = await consumeOAuthState(auth.store, state);
44
+ const stored = await resolveOAuthState(auth.store, state, saved);
44
45
  if (typeof stored.codeVerifier !== "string") {
45
46
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
46
47
  }
@@ -51,7 +52,8 @@ export class MyAnimeList {
51
52
  name: profileString(profile.name),
52
53
  email: null,
53
54
  image: profileString(profile.picture),
54
- raw: profile
55
+ raw: profile,
56
+ ...extractOAuthTokens(tokens)
55
57
  };
56
58
  }
57
59
  }
@@ -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 NaverOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Naver {
@@ -12,6 +12,6 @@ export declare class Naver {
12
12
  createAuthorizationURL(): 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
  }
@@ -1,5 +1,5 @@
1
1
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://nid.naver.com/oauth2.0/authorize";
4
4
  const tokenEndpoint = "https://nid.naver.com/oauth2.0/token";
5
5
  const userEndpoint = "https://openapi.naver.com/v1/nid/me";
@@ -59,13 +59,14 @@ export class Naver {
59
59
  const state = generateOAuthState();
60
60
  const url = this.createAuthorizationURL();
61
61
  url.searchParams.set("state", state);
62
- await saveOAuthState(auth.store, state, {});
63
- return url;
62
+ const payload = {};
63
+ await saveOAuthState(auth.store, state, payload);
64
+ return { url, state, payload };
64
65
  }
65
- async getUser(query) {
66
+ async getUser(query, saved) {
66
67
  const auth = requireAuthConfig(this.auth);
67
68
  const { code, state } = parseCallbackQuery(query);
68
- await consumeOAuthState(auth.store, state);
69
+ await resolveOAuthState(auth.store, state, saved);
69
70
  const tokens = await this.validateAuthorizationCode(code);
70
71
  const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
71
72
  const response = profile.response;
@@ -78,7 +79,8 @@ export class Naver {
78
79
  name: profileString(user.name) ?? profileString(user.nickname),
79
80
  email: profileString(user.email),
80
81
  image: profileString(user.profile_image),
81
- raw: user
82
+ raw: user,
83
+ ...extractOAuthTokens(tokens)
82
84
  };
83
85
  }
84
86
  }
@@ -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 NotionOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Notion {
@@ -9,6 +9,6 @@ export declare class Notion {
9
9
  constructor(clientId: string, clientSecret: string, redirectURI: string);
10
10
  createAuthorizationURL(state: string): URL;
11
11
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
12
- getAuthorizationURL(_scopes?: string[]): Promise<URL>;
13
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
12
+ getAuthorizationURL(_scopes?: string[]): Promise<AuthorizationRequest>;
13
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
14
14
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://api.notion.com/v1/oauth/authorize";
4
4
  const tokenEndpoint = "https://api.notion.com/v1/oauth/token";
5
5
  const envPrefix = "NOTION";
@@ -32,13 +32,14 @@ export class Notion {
32
32
  const auth = requireAuthConfig(this.auth);
33
33
  const state = generateOAuthState();
34
34
  const url = this.createAuthorizationURL(state);
35
- await saveOAuthState(auth.store, state, {});
36
- return url;
35
+ const payload = {};
36
+ await saveOAuthState(auth.store, state, payload);
37
+ return { url, state, payload };
37
38
  }
38
- async getUser(query) {
39
+ async getUser(query, saved) {
39
40
  const auth = requireAuthConfig(this.auth);
40
41
  const { code, state } = parseCallbackQuery(query);
41
- await consumeOAuthState(auth.store, state);
42
+ await resolveOAuthState(auth.store, state, saved);
42
43
  const tokens = await this.validateAuthorizationCode(code);
43
44
  // Notion returns the authorizing user inside the token response.
44
45
  const data = tokens.data;
@@ -60,7 +61,8 @@ export class Notion {
60
61
  name: profileString(profile.name),
61
62
  email,
62
63
  image: profileString(profile.avatar_url),
63
- raw: profile
64
+ raw: profile,
65
+ ...extractOAuthTokens(tokens)
64
66
  };
65
67
  }
66
68
  }
@@ -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 OktaOptions extends ProviderOptions {
4
4
  domain?: string;
5
5
  authorizationServerId?: string;
@@ -17,6 +17,6 @@ export declare class Okta {
17
17
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
18
18
  refreshAccessToken(refreshToken: string, scopes: string[]): Promise<OAuth2Tokens>;
19
19
  revokeToken(token: string): Promise<void>;
20
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
21
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
20
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
21
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
22
22
  }
@@ -1,6 +1,6 @@
1
1
  import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
2
  import { decodeIdToken } from "../oidc.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveProviderOption, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveOAuthState, resolveProviderOption, resolveScopes, saveOAuthState } from "../auth.js";
4
4
  import { joinURIAndPath } from "../request.js";
5
5
  const envPrefix = "OKTA";
6
6
  const defaultScopes = ["openid", "profile", "email"];
@@ -57,13 +57,14 @@ export class Okta {
57
57
  const state = generateOAuthState();
58
58
  const codeVerifier = generateOAuthCodeVerifier();
59
59
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
60
- await saveOAuthState(auth.store, state, { codeVerifier });
61
- return url;
60
+ const payload = { codeVerifier };
61
+ await saveOAuthState(auth.store, state, payload);
62
+ return { url, state, payload };
62
63
  }
63
- async getUser(query) {
64
+ async getUser(query, saved) {
64
65
  const auth = requireAuthConfig(this.auth);
65
66
  const { code, state } = parseCallbackQuery(query);
66
- const stored = await consumeOAuthState(auth.store, state);
67
+ const stored = await resolveOAuthState(auth.store, state, saved);
67
68
  if (typeof stored.codeVerifier !== "string") {
68
69
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
69
70
  }
@@ -80,7 +81,8 @@ export class Okta {
80
81
  name: profileString(claims.name),
81
82
  email: profileString(claims.email),
82
83
  image: profileString(claims.picture),
83
- raw: claims
84
+ raw: claims,
85
+ ...extractOAuthTokens(tokens)
84
86
  };
85
87
  }
86
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 OsuOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Osu {
@@ -12,6 +12,6 @@ export declare class Osu {
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
  }
@@ -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, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://osu.ppy.sh/oauth/authorize";
4
4
  const tokenEndpoint = "https://osu.ppy.sh/oauth/token";
5
5
  const userEndpoint = "https://osu.ppy.sh/api/v2/me";
@@ -63,13 +63,14 @@ export class Osu {
63
63
  const auth = requireAuthConfig(this.auth);
64
64
  const state = generateOAuthState();
65
65
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
66
- await saveOAuthState(auth.store, state, {});
67
- return url;
66
+ const payload = {};
67
+ await saveOAuthState(auth.store, state, payload);
68
+ return { url, state, payload };
68
69
  }
69
- async getUser(query) {
70
+ async getUser(query, saved) {
70
71
  const auth = requireAuthConfig(this.auth);
71
72
  const { code, state } = parseCallbackQuery(query);
72
- await consumeOAuthState(auth.store, state);
73
+ await resolveOAuthState(auth.store, state, saved);
73
74
  const tokens = await this.validateAuthorizationCode(code);
74
75
  const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
75
76
  return {
@@ -77,7 +78,8 @@ export class Osu {
77
78
  name: profileString(profile.username),
78
79
  email: null,
79
80
  image: profileString(profile.avatar_url),
80
- raw: profile
81
+ raw: profile,
82
+ ...extractOAuthTokens(tokens)
81
83
  };
82
84
  }
83
85
  }
@@ -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 PatreonOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Patreon {
@@ -12,6 +12,6 @@ export declare class Patreon {
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
  }
@@ -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, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.patreon.com/oauth2/authorize";
4
4
  const tokenEndpoint = "https://www.patreon.com/api/oauth2/token";
5
5
  const identityEndpoint = "https://www.patreon.com/api/oauth2/v2/identity";
@@ -62,13 +62,14 @@ export class Patreon {
62
62
  const auth = requireAuthConfig(this.auth);
63
63
  const state = generateOAuthState();
64
64
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
65
- await saveOAuthState(auth.store, state, {});
66
- return url;
65
+ const payload = {};
66
+ await saveOAuthState(auth.store, state, payload);
67
+ return { url, state, payload };
67
68
  }
68
- async getUser(query) {
69
+ async getUser(query, saved) {
69
70
  const auth = requireAuthConfig(this.auth);
70
71
  const { code, state } = parseCallbackQuery(query);
71
- await consumeOAuthState(auth.store, state);
72
+ await resolveOAuthState(auth.store, state, saved);
72
73
  const tokens = await this.validateAuthorizationCode(code);
73
74
  const url = new URL(identityEndpoint);
74
75
  url.searchParams.set("fields[user]", "email,full_name,image_url");
@@ -84,7 +85,8 @@ export class Patreon {
84
85
  name: profileString(attributes.full_name),
85
86
  email: profileString(attributes.email),
86
87
  image: profileString(attributes.image_url),
87
- raw: user
88
+ raw: user,
89
+ ...extractOAuthTokens(tokens)
88
90
  };
89
91
  }
90
92
  }
@@ -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 PolarOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Polar {
@@ -13,6 +13,6 @@ export declare class Polar {
13
13
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
14
14
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
15
15
  revokeToken(token: string): Promise<void>;
16
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
17
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
16
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
17
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
18
18
  }
@@ -1,6 +1,6 @@
1
1
  import { createS256CodeChallenge } from "../oauth2.js";
2
2
  import { createOAuth2Request, sendTokenRequest, sendTokenRevocationRequest } from "../request.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
4
4
  const authorizationEndpoint = "https://polar.sh/oauth2/authorize";
5
5
  const tokenEndpoint = "https://api.polar.sh/v1/oauth2/token";
6
6
  const tokenRevocationEndpoint = "https://api.polar.sh/v1/oauth2/revoke";
@@ -77,13 +77,14 @@ export class Polar {
77
77
  const state = generateOAuthState();
78
78
  const codeVerifier = generateOAuthCodeVerifier();
79
79
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
80
- await saveOAuthState(auth.store, state, { codeVerifier });
81
- return url;
80
+ const payload = { codeVerifier };
81
+ await saveOAuthState(auth.store, state, payload);
82
+ return { url, state, payload };
82
83
  }
83
- async getUser(query) {
84
+ async getUser(query, saved) {
84
85
  const auth = requireAuthConfig(this.auth);
85
86
  const { code, state } = parseCallbackQuery(query);
86
- const stored = await consumeOAuthState(auth.store, state);
87
+ const stored = await resolveOAuthState(auth.store, state, saved);
87
88
  if (typeof stored.codeVerifier !== "string") {
88
89
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
89
90
  }
@@ -95,7 +96,8 @@ export class Polar {
95
96
  email: profileString(claims.email),
96
97
  // Polar's userinfo response has no avatar field.
97
98
  image: null,
98
- raw: claims
99
+ raw: claims,
100
+ ...extractOAuthTokens(tokens)
99
101
  };
100
102
  }
101
103
  }
@@ -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 RedditOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Reddit {
@@ -10,6 +10,6 @@ export declare class Reddit {
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, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://www.reddit.com/api/v1/authorize";
4
4
  const tokenEndpoint = "https://www.reddit.com/api/v1/access_token";
5
5
  const userEndpoint = "https://oauth.reddit.com/api/v1/me";
@@ -36,13 +36,14 @@ export class Reddit {
36
36
  const auth = requireAuthConfig(this.auth);
37
37
  const state = generateOAuthState();
38
38
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
39
- await saveOAuthState(auth.store, state, {});
40
- return url;
39
+ const payload = {};
40
+ await saveOAuthState(auth.store, state, payload);
41
+ return { url, state, payload };
41
42
  }
42
- async getUser(query) {
43
+ async getUser(query, saved) {
43
44
  const auth = requireAuthConfig(this.auth);
44
45
  const { code, state } = parseCallbackQuery(query);
45
- await consumeOAuthState(auth.store, state);
46
+ await resolveOAuthState(auth.store, state, saved);
46
47
  const tokens = await this.validateAuthorizationCode(code);
47
48
  const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
48
49
  return {
@@ -50,7 +51,8 @@ export class Reddit {
50
51
  name: profileString(profile.name),
51
52
  email: null,
52
53
  image: profileString(profile.icon_img),
53
- raw: profile
54
+ raw: profile,
55
+ ...extractOAuthTokens(tokens)
54
56
  };
55
57
  }
56
58
  }