antarctic 0.4.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 +20 -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 +9 -6
  6. package/dist/providers/amazon-cognito.d.ts +3 -3
  7. package/dist/providers/amazon-cognito.js +9 -6
  8. package/dist/providers/anilist.d.ts +3 -3
  9. package/dist/providers/anilist.js +9 -6
  10. package/dist/providers/apple.d.ts +3 -3
  11. package/dist/providers/apple.js +9 -6
  12. package/dist/providers/atlassian.d.ts +3 -3
  13. package/dist/providers/atlassian.js +9 -6
  14. package/dist/providers/auth0.d.ts +3 -3
  15. package/dist/providers/auth0.js +9 -6
  16. package/dist/providers/authentik.d.ts +3 -3
  17. package/dist/providers/authentik.js +9 -6
  18. package/dist/providers/autodesk.d.ts +3 -3
  19. package/dist/providers/autodesk.js +9 -6
  20. package/dist/providers/battlenet.d.ts +3 -3
  21. package/dist/providers/battlenet.js +9 -6
  22. package/dist/providers/bitbucket.d.ts +3 -3
  23. package/dist/providers/bitbucket.js +9 -6
  24. package/dist/providers/box.d.ts +3 -3
  25. package/dist/providers/box.js +9 -6
  26. package/dist/providers/bungie.d.ts +3 -3
  27. package/dist/providers/bungie.js +9 -6
  28. package/dist/providers/coinbase.d.ts +3 -3
  29. package/dist/providers/coinbase.js +9 -6
  30. package/dist/providers/discord.d.ts +3 -3
  31. package/dist/providers/discord.js +9 -6
  32. package/dist/providers/donation-alerts.d.ts +3 -3
  33. package/dist/providers/donation-alerts.js +9 -6
  34. package/dist/providers/dribbble.d.ts +3 -3
  35. package/dist/providers/dribbble.js +9 -6
  36. package/dist/providers/dropbox.d.ts +3 -3
  37. package/dist/providers/dropbox.js +9 -6
  38. package/dist/providers/epicgames.d.ts +3 -3
  39. package/dist/providers/epicgames.js +9 -6
  40. package/dist/providers/etsy.d.ts +3 -3
  41. package/dist/providers/etsy.js +9 -6
  42. package/dist/providers/facebook.d.ts +3 -3
  43. package/dist/providers/facebook.js +9 -6
  44. package/dist/providers/figma.d.ts +3 -3
  45. package/dist/providers/figma.js +9 -6
  46. package/dist/providers/gitea.d.ts +3 -3
  47. package/dist/providers/gitea.js +9 -6
  48. package/dist/providers/github.d.ts +3 -3
  49. package/dist/providers/github.js +9 -6
  50. package/dist/providers/gitlab.d.ts +3 -3
  51. package/dist/providers/gitlab.js +9 -6
  52. package/dist/providers/google.d.ts +3 -3
  53. package/dist/providers/google.js +9 -6
  54. package/dist/providers/intuit.d.ts +3 -3
  55. package/dist/providers/intuit.js +9 -6
  56. package/dist/providers/kakao.d.ts +3 -3
  57. package/dist/providers/kakao.js +9 -6
  58. package/dist/providers/keycloak.d.ts +3 -3
  59. package/dist/providers/keycloak.js +9 -6
  60. package/dist/providers/kick.d.ts +3 -3
  61. package/dist/providers/kick.js +9 -6
  62. package/dist/providers/lichess.d.ts +3 -3
  63. package/dist/providers/lichess.js +9 -6
  64. package/dist/providers/line.d.ts +3 -3
  65. package/dist/providers/line.js +9 -6
  66. package/dist/providers/linear.d.ts +3 -3
  67. package/dist/providers/linear.js +9 -6
  68. package/dist/providers/linkedin.d.ts +3 -3
  69. package/dist/providers/linkedin.js +9 -6
  70. package/dist/providers/mastodon.d.ts +3 -3
  71. package/dist/providers/mastodon.js +9 -6
  72. package/dist/providers/mercadolibre.d.ts +3 -3
  73. package/dist/providers/mercadolibre.js +9 -6
  74. package/dist/providers/mercadopago.d.ts +3 -3
  75. package/dist/providers/mercadopago.js +9 -6
  76. package/dist/providers/microsoft-entra-id.d.ts +3 -3
  77. package/dist/providers/microsoft-entra-id.js +9 -6
  78. package/dist/providers/myanimelist.d.ts +3 -3
  79. package/dist/providers/myanimelist.js +9 -6
  80. package/dist/providers/naver.d.ts +3 -3
  81. package/dist/providers/naver.js +9 -6
  82. package/dist/providers/notion.d.ts +3 -3
  83. package/dist/providers/notion.js +9 -6
  84. package/dist/providers/okta.d.ts +3 -3
  85. package/dist/providers/okta.js +9 -6
  86. package/dist/providers/osu.d.ts +3 -3
  87. package/dist/providers/osu.js +9 -6
  88. package/dist/providers/patreon.d.ts +3 -3
  89. package/dist/providers/patreon.js +9 -6
  90. package/dist/providers/polar.d.ts +3 -3
  91. package/dist/providers/polar.js +9 -6
  92. package/dist/providers/reddit.d.ts +3 -3
  93. package/dist/providers/reddit.js +9 -6
  94. package/dist/providers/roblox.d.ts +3 -3
  95. package/dist/providers/roblox.js +9 -6
  96. package/dist/providers/salesforce.d.ts +3 -3
  97. package/dist/providers/salesforce.js +9 -6
  98. package/dist/providers/shikimori.d.ts +3 -3
  99. package/dist/providers/shikimori.js +9 -6
  100. package/dist/providers/slack.d.ts +3 -3
  101. package/dist/providers/slack.js +9 -6
  102. package/dist/providers/spotify.d.ts +3 -3
  103. package/dist/providers/spotify.js +9 -6
  104. package/dist/providers/startgg.d.ts +3 -3
  105. package/dist/providers/startgg.js +9 -6
  106. package/dist/providers/strava.d.ts +3 -3
  107. package/dist/providers/strava.js +9 -6
  108. package/dist/providers/tiktok.d.ts +3 -3
  109. package/dist/providers/tiktok.js +9 -6
  110. package/dist/providers/tiltify.d.ts +3 -3
  111. package/dist/providers/tiltify.js +9 -6
  112. package/dist/providers/tumblr.d.ts +3 -3
  113. package/dist/providers/tumblr.js +9 -6
  114. package/dist/providers/twitch.d.ts +3 -3
  115. package/dist/providers/twitch.js +9 -6
  116. package/dist/providers/twitter.d.ts +3 -3
  117. package/dist/providers/twitter.js +9 -6
  118. package/dist/providers/vk.d.ts +3 -3
  119. package/dist/providers/vk.js +9 -6
  120. package/dist/providers/withings.d.ts +3 -3
  121. package/dist/providers/withings.js +9 -6
  122. package/dist/providers/workos.d.ts +3 -3
  123. package/dist/providers/workos.js +9 -6
  124. package/dist/providers/yahoo.d.ts +3 -3
  125. package/dist/providers/yahoo.js +9 -6
  126. package/dist/providers/yandex.d.ts +3 -3
  127. package/dist/providers/yandex.js +9 -6
  128. package/dist/providers/zoom.d.ts +3 -3
  129. package/dist/providers/zoom.js +9 -6
  130. package/package.json +1 -1
  131. package/readme.md +12 -2
@@ -1,7 +1,7 @@
1
1
  // LinkedIn doesn't seem to support HTTP Basic Auth
2
2
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
3
3
  import { decodeIdToken } from "../oidc.js";
4
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
4
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
5
5
  const authorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
6
6
  const tokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
7
7
  const userinfoEndpoint = "https://api.linkedin.com/v2/userinfo";
@@ -64,13 +64,14 @@ export class LinkedIn {
64
64
  const auth = requireAuthConfig(this.auth);
65
65
  const state = generateOAuthState();
66
66
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
67
- await saveOAuthState(auth.store, state, {});
68
- return url;
67
+ const payload = {};
68
+ await saveOAuthState(auth.store, state, payload);
69
+ return { url, state, payload };
69
70
  }
70
- async getUser(query) {
71
+ async getUser(query, saved) {
71
72
  const auth = requireAuthConfig(this.auth);
72
73
  const { code, state } = parseCallbackQuery(query);
73
- await consumeOAuthState(auth.store, state);
74
+ await resolveOAuthState(auth.store, state, saved);
74
75
  const tokens = await this.validateAuthorizationCode(code);
75
76
  let claims;
76
77
  if ("id_token" in tokens.data) {
@@ -83,7 +84,9 @@ export class LinkedIn {
83
84
  id: profileId(claims.sub),
84
85
  name: profileString(claims.name),
85
86
  email: profileString(claims.email),
86
- image: profileString(claims.picture)
87
+ image: profileString(claims.picture),
88
+ raw: claims,
89
+ ...extractOAuthTokens(tokens)
87
90
  };
88
91
  }
89
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 MastodonOptions extends ProviderOptions {
4
4
  baseURL?: string;
5
5
  }
@@ -15,6 +15,6 @@ export declare class Mastodon {
15
15
  createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): Promise<URL>;
16
16
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
17
17
  revokeToken(token: string): Promise<void>;
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,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
  }
@@ -61,7 +62,9 @@ export class Mastodon {
61
62
  id: profileId(profile.id),
62
63
  name: profileString(profile.display_name) ?? profileString(profile.username),
63
64
  email: null,
64
- image: profileString(profile.avatar)
65
+ image: profileString(profile.avatar),
66
+ raw: profile,
67
+ ...extractOAuthTokens(tokens)
65
68
  };
66
69
  }
67
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
  }
@@ -89,7 +90,9 @@ export class MercadoLibre {
89
90
  id: profileId(profile.id),
90
91
  name: fullName !== "" ? fullName : profileString(profile.nickname),
91
92
  email: profileString(profile.email),
92
- image
93
+ image,
94
+ raw: profile,
95
+ ...extractOAuthTokens(tokens)
93
96
  };
94
97
  }
95
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
  }
@@ -89,7 +90,9 @@ export class MercadoPago {
89
90
  id: profileId(profile.id),
90
91
  name: fullName !== "" ? fullName : profileString(profile.nickname),
91
92
  email: profileString(profile.email),
92
- image
93
+ image,
94
+ raw: profile,
95
+ ...extractOAuthTokens(tokens)
93
96
  };
94
97
  }
95
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
  }
@@ -114,7 +115,9 @@ export class MicrosoftEntraId {
114
115
  id: profileId(claims.sub),
115
116
  name: profileString(claims.name),
116
117
  email: profileString(claims.email) ?? profileString(claims.preferred_username),
117
- image: profileString(claims.picture)
118
+ image: profileString(claims.picture),
119
+ raw: claims,
120
+ ...extractOAuthTokens(tokens)
118
121
  };
119
122
  }
120
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
  }
@@ -50,7 +51,9 @@ export class MyAnimeList {
50
51
  id: profileId(profile.id),
51
52
  name: profileString(profile.name),
52
53
  email: null,
53
- image: profileString(profile.picture)
54
+ image: profileString(profile.picture),
55
+ raw: profile,
56
+ ...extractOAuthTokens(tokens)
54
57
  };
55
58
  }
56
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;
@@ -77,7 +78,9 @@ export class Naver {
77
78
  id: profileId(user.id),
78
79
  name: profileString(user.name) ?? profileString(user.nickname),
79
80
  email: profileString(user.email),
80
- image: profileString(user.profile_image)
81
+ image: profileString(user.profile_image),
82
+ raw: user,
83
+ ...extractOAuthTokens(tokens)
81
84
  };
82
85
  }
83
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;
@@ -59,7 +60,9 @@ export class Notion {
59
60
  id: profileId(profile.id),
60
61
  name: profileString(profile.name),
61
62
  email,
62
- image: profileString(profile.avatar_url)
63
+ image: profileString(profile.avatar_url),
64
+ raw: profile,
65
+ ...extractOAuthTokens(tokens)
63
66
  };
64
67
  }
65
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
  }
@@ -79,7 +80,9 @@ export class Okta {
79
80
  id: profileId(claims.sub),
80
81
  name: profileString(claims.name),
81
82
  email: profileString(claims.email),
82
- image: profileString(claims.picture)
83
+ image: profileString(claims.picture),
84
+ raw: claims,
85
+ ...extractOAuthTokens(tokens)
83
86
  };
84
87
  }
85
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,20 +63,23 @@ 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 {
76
77
  id: profileId(profile.id),
77
78
  name: profileString(profile.username),
78
79
  email: null,
79
- image: profileString(profile.avatar_url)
80
+ image: profileString(profile.avatar_url),
81
+ raw: profile,
82
+ ...extractOAuthTokens(tokens)
80
83
  };
81
84
  }
82
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");
@@ -83,7 +84,9 @@ export class Patreon {
83
84
  id: profileId(user.id),
84
85
  name: profileString(attributes.full_name),
85
86
  email: profileString(attributes.email),
86
- image: profileString(attributes.image_url)
87
+ image: profileString(attributes.image_url),
88
+ raw: user,
89
+ ...extractOAuthTokens(tokens)
87
90
  };
88
91
  }
89
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
  }