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 { createOAuth2Request, sendTokenRequest } from "../request.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://linear.app/oauth/authorize";
4
4
  const tokenEndpoint = "https://api.linear.app/oauth/token";
5
5
  const graphqlEndpoint = "https://api.linear.app/graphql";
@@ -10,7 +10,7 @@ export class Linear {
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 Linear {
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 viewer = await fetchViewer(tokens.accessToken());
64
64
  return {
@@ -66,7 +66,8 @@ export class Linear {
66
66
  name: profileString(viewer.name),
67
67
  email: profileString(viewer.email),
68
68
  image: profileString(viewer.avatarUrl),
69
- raw: viewer
69
+ raw: viewer,
70
+ ...extractOAuthTokens(tokens)
70
71
  };
71
72
  }
72
73
  }
@@ -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 LinkedInOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class LinkedIn {
@@ -7,11 +7,11 @@ export declare class LinkedIn {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: LinkedInOptions);
10
+ constructor(options?: LinkedInOptions);
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
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,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 } 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";
@@ -12,7 +12,7 @@ export class LinkedIn {
12
12
  clientSecret;
13
13
  redirectURI;
14
14
  auth = null;
15
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
15
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
16
16
  if (typeof clientIdOrOptions === "object") {
17
17
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
18
18
  clientSecret: true,
@@ -64,13 +64,13 @@ 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
+ return { url, state, payload };
69
69
  }
70
- async getUser(query) {
71
- const auth = requireAuthConfig(this.auth);
70
+ async getUser(query, saved) {
71
+ requireAuthConfig(this.auth);
72
72
  const { code, state } = parseCallbackQuery(query);
73
- await consumeOAuthState(auth.store, state);
73
+ resolveOAuthState(state, saved);
74
74
  const tokens = await this.validateAuthorizationCode(code);
75
75
  let claims;
76
76
  if ("id_token" in tokens.data) {
@@ -84,7 +84,8 @@ export class LinkedIn {
84
84
  name: profileString(claims.name),
85
85
  email: profileString(claims.email),
86
86
  image: profileString(claims.picture),
87
- raw: claims
87
+ raw: claims,
88
+ ...extractOAuthTokens(tokens)
88
89
  };
89
90
  }
90
91
  }
@@ -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
  }
@@ -10,11 +10,11 @@ export declare class Mastodon {
10
10
  private userEndpoint;
11
11
  private client;
12
12
  private auth;
13
- constructor(options: MastodonOptions);
13
+ constructor(options?: MastodonOptions);
14
14
  constructor(baseURL: string, clientId: string, clientSecret: string, redirectURI: string);
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 } from "../auth.js";
4
4
  const envPrefix = "MASTODON";
5
5
  const defaultScopes = ["read:accounts"];
6
6
  export class Mastodon {
@@ -10,7 +10,7 @@ export class Mastodon {
10
10
  userEndpoint;
11
11
  client;
12
12
  auth = null;
13
- constructor(baseURLOrOptions, clientId, clientSecret, redirectURI) {
13
+ constructor(baseURLOrOptions = {}, clientId, clientSecret, redirectURI) {
14
14
  let baseURL;
15
15
  if (typeof baseURLOrOptions === "object") {
16
16
  this.auth = resolveAuthConfig(envPrefix, baseURLOrOptions, {
@@ -45,13 +45,13 @@ 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
+ return { url, state, payload };
50
50
  }
51
- async getUser(query) {
52
- const auth = requireAuthConfig(this.auth);
51
+ async getUser(query, saved) {
52
+ requireAuthConfig(this.auth);
53
53
  const { code, state } = parseCallbackQuery(query);
54
- const stored = await consumeOAuthState(auth.store, state);
54
+ const stored = resolveOAuthState(state, saved);
55
55
  if (typeof stored.codeVerifier !== "string") {
56
56
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
57
57
  }
@@ -62,7 +62,8 @@ export class Mastodon {
62
62
  name: profileString(profile.display_name) ?? profileString(profile.username),
63
63
  email: null,
64
64
  image: profileString(profile.avatar),
65
- raw: profile
65
+ raw: profile,
66
+ ...extractOAuthTokens(tokens)
66
67
  };
67
68
  }
68
69
  }
@@ -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 {
@@ -7,11 +7,11 @@ export declare class MercadoLibre {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: MercadoLibreOptions);
10
+ constructor(options?: MercadoLibreOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
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 } 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";
@@ -10,7 +10,7 @@ export class MercadoLibre {
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,17 +62,17 @@ export class MercadoLibre {
62
62
  }
63
63
  // Scopes are defined in the application settings, so the argument is ignored.
64
64
  async getAuthorizationURL(_scopes) {
65
- const auth = requireAuthConfig(this.auth);
65
+ requireAuthConfig(this.auth);
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
+ return { url, state, payload };
71
71
  }
72
- async getUser(query) {
73
- const auth = requireAuthConfig(this.auth);
72
+ async getUser(query, saved) {
73
+ requireAuthConfig(this.auth);
74
74
  const { code, state } = parseCallbackQuery(query);
75
- const stored = await consumeOAuthState(auth.store, state);
75
+ const stored = resolveOAuthState(state, saved);
76
76
  if (typeof stored.codeVerifier !== "string") {
77
77
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
78
78
  }
@@ -90,7 +90,8 @@ export class MercadoLibre {
90
90
  name: fullName !== "" ? fullName : profileString(profile.nickname),
91
91
  email: profileString(profile.email),
92
92
  image,
93
- raw: profile
93
+ raw: profile,
94
+ ...extractOAuthTokens(tokens)
94
95
  };
95
96
  }
96
97
  }
@@ -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 {
@@ -7,11 +7,11 @@ export declare class MercadoPago {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: MercadoPagoOptions);
10
+ constructor(options?: MercadoPagoOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
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 } 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";
@@ -10,7 +10,7 @@ export class MercadoPago {
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,17 +62,17 @@ export class MercadoPago {
62
62
  }
63
63
  // Scopes are defined in the application settings, so the argument is ignored.
64
64
  async getAuthorizationURL(_scopes) {
65
- const auth = requireAuthConfig(this.auth);
65
+ requireAuthConfig(this.auth);
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
+ return { url, state, payload };
71
71
  }
72
- async getUser(query) {
73
- const auth = requireAuthConfig(this.auth);
72
+ async getUser(query, saved) {
73
+ requireAuthConfig(this.auth);
74
74
  const { code, state } = parseCallbackQuery(query);
75
- const stored = await consumeOAuthState(auth.store, state);
75
+ const stored = resolveOAuthState(state, saved);
76
76
  if (typeof stored.codeVerifier !== "string") {
77
77
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
78
78
  }
@@ -90,7 +90,8 @@ export class MercadoPago {
90
90
  name: fullName !== "" ? fullName : profileString(profile.nickname),
91
91
  email: profileString(profile.email),
92
92
  image,
93
- raw: profile
93
+ raw: profile,
94
+ ...extractOAuthTokens(tokens)
94
95
  };
95
96
  }
96
97
  }
@@ -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
  }
@@ -10,11 +10,11 @@ export declare class MicrosoftEntraId {
10
10
  private clientSecret;
11
11
  private redirectURI;
12
12
  private auth;
13
- constructor(options: MicrosoftEntraIdOptions);
13
+ constructor(options?: MicrosoftEntraIdOptions);
14
14
  constructor(tenant: string, clientId: string, clientSecret: string | null, redirectURI: string);
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 } 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"];
@@ -12,7 +12,7 @@ export class MicrosoftEntraId {
12
12
  clientSecret;
13
13
  redirectURI;
14
14
  auth = null;
15
- constructor(tenantOrOptions, clientId, clientSecret, redirectURI) {
15
+ constructor(tenantOrOptions = {}, clientId, clientSecret, redirectURI) {
16
16
  let tenant;
17
17
  if (typeof tenantOrOptions === "object") {
18
18
  this.auth = resolveAuthConfig(envPrefix, tenantOrOptions, { redirectURI: true });
@@ -92,13 +92,13 @@ 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
+ return { url, state, payload };
97
97
  }
98
- async getUser(query) {
99
- const auth = requireAuthConfig(this.auth);
98
+ async getUser(query, saved) {
99
+ requireAuthConfig(this.auth);
100
100
  const { code, state } = parseCallbackQuery(query);
101
- const stored = await consumeOAuthState(auth.store, state);
101
+ const stored = resolveOAuthState(state, saved);
102
102
  if (typeof stored.codeVerifier !== "string") {
103
103
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
104
104
  }
@@ -115,7 +115,8 @@ export class MicrosoftEntraId {
115
115
  name: profileString(claims.name),
116
116
  email: profileString(claims.email) ?? profileString(claims.preferred_username),
117
117
  image: profileString(claims.picture),
118
- raw: claims
118
+ raw: claims,
119
+ ...extractOAuthTokens(tokens)
119
120
  };
120
121
  }
121
122
  }
@@ -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 MyAnimeListOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class MyAnimeList {
6
6
  private client;
7
7
  private auth;
8
- constructor(options: MyAnimeListOptions);
8
+ constructor(options?: MyAnimeListOptions);
9
9
  constructor(clientId: string, clientSecret: string, redirectURI: string | null);
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 } 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";
@@ -7,7 +7,7 @@ const envPrefix = "MY_ANIME_LIST";
7
7
  export class MyAnimeList {
8
8
  client;
9
9
  auth = null;
10
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
10
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
11
11
  if (typeof clientIdOrOptions === "object") {
12
12
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, { clientSecret: true });
13
13
  this.client = new OAuth2Client(this.auth.clientId, this.auth.clientSecret, this.auth.redirectURI);
@@ -30,17 +30,17 @@ export class MyAnimeList {
30
30
  }
31
31
  // MyAnimeList does not use scopes, so the argument is ignored.
32
32
  async getAuthorizationURL(_scopes) {
33
- const auth = requireAuthConfig(this.auth);
33
+ requireAuthConfig(this.auth);
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
+ return { url, state, payload };
39
39
  }
40
- async getUser(query) {
41
- const auth = requireAuthConfig(this.auth);
40
+ async getUser(query, saved) {
41
+ requireAuthConfig(this.auth);
42
42
  const { code, state } = parseCallbackQuery(query);
43
- const stored = await consumeOAuthState(auth.store, state);
43
+ const stored = resolveOAuthState(state, saved);
44
44
  if (typeof stored.codeVerifier !== "string") {
45
45
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
46
46
  }
@@ -51,7 +51,8 @@ export class MyAnimeList {
51
51
  name: profileString(profile.name),
52
52
  email: null,
53
53
  image: profileString(profile.picture),
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 NaverOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Naver {
@@ -7,11 +7,11 @@ export declare class Naver {
7
7
  private clientSecret;
8
8
  private redirectURI;
9
9
  private auth;
10
- constructor(options: NaverOptions);
10
+ constructor(options?: NaverOptions);
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
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 } 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";
@@ -9,7 +9,7 @@ export class Naver {
9
9
  clientSecret;
10
10
  redirectURI;
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,
@@ -55,17 +55,17 @@ export class Naver {
55
55
  }
56
56
  // Naver scopes are configured in the application settings, so the argument is ignored.
57
57
  async getAuthorizationURL(_scopes) {
58
- const auth = requireAuthConfig(this.auth);
58
+ requireAuthConfig(this.auth);
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
+ return { url, state, payload };
64
64
  }
65
- async getUser(query) {
66
- const auth = requireAuthConfig(this.auth);
65
+ async getUser(query, saved) {
66
+ requireAuthConfig(this.auth);
67
67
  const { code, state } = parseCallbackQuery(query);
68
- await consumeOAuthState(auth.store, state);
68
+ resolveOAuthState(state, saved);
69
69
  const tokens = await this.validateAuthorizationCode(code);
70
70
  const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
71
71
  const response = profile.response;
@@ -78,7 +78,8 @@ export class Naver {
78
78
  name: profileString(user.name) ?? profileString(user.nickname),
79
79
  email: profileString(user.email),
80
80
  image: profileString(user.profile_image),
81
- raw: user
81
+ raw: user,
82
+ ...extractOAuthTokens(tokens)
82
83
  };
83
84
  }
84
85
  }
@@ -1,14 +1,14 @@
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 {
6
6
  private client;
7
7
  private auth;
8
- constructor(options: NotionOptions);
8
+ constructor(options?: NotionOptions);
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,12 +1,12 @@
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 } 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";
6
6
  export class Notion {
7
7
  client;
8
8
  auth = null;
9
- constructor(clientIdOrOptions, clientSecret, redirectURI) {
9
+ constructor(clientIdOrOptions = {}, clientSecret, redirectURI) {
10
10
  if (typeof clientIdOrOptions === "object") {
11
11
  this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
12
12
  clientSecret: true,
@@ -29,16 +29,16 @@ export class Notion {
29
29
  }
30
30
  // Notion does not use scopes, so the argument is ignored.
31
31
  async getAuthorizationURL(_scopes) {
32
- const auth = requireAuthConfig(this.auth);
32
+ 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
+ return { url, state, payload };
37
37
  }
38
- async getUser(query) {
39
- const auth = requireAuthConfig(this.auth);
38
+ async getUser(query, saved) {
39
+ requireAuthConfig(this.auth);
40
40
  const { code, state } = parseCallbackQuery(query);
41
- await consumeOAuthState(auth.store, state);
41
+ resolveOAuthState(state, saved);
42
42
  const tokens = await this.validateAuthorizationCode(code);
43
43
  // Notion returns the authorizing user inside the token response.
44
44
  const data = tokens.data;
@@ -60,7 +60,8 @@ export class Notion {
60
60
  name: profileString(profile.name),
61
61
  email,
62
62
  image: profileString(profile.avatar_url),
63
- raw: profile
63
+ raw: profile,
64
+ ...extractOAuthTokens(tokens)
64
65
  };
65
66
  }
66
67
  }
@@ -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;
@@ -11,12 +11,12 @@ export declare class Okta {
11
11
  private userinfoEndpoint;
12
12
  private client;
13
13
  private auth;
14
- constructor(options: OktaOptions);
14
+ constructor(options?: OktaOptions);
15
15
  constructor(domain: string, authorizationServerId: string | null, clientId: string, clientSecret: string, redirectURI: string);
16
16
  createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): Promise<URL>;
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
  }