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,6 +1,6 @@
1
1
  import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
2
  import { joinURIAndPath } from "../request.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
4
4
  const envPrefix = "GITEA";
5
5
  const defaultScopes = ["read:user"];
6
6
  export class Gitea {
@@ -39,13 +39,14 @@ export class Gitea {
39
39
  const state = generateOAuthState();
40
40
  const codeVerifier = generateOAuthCodeVerifier();
41
41
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
42
- await saveOAuthState(auth.store, state, { codeVerifier });
43
- return url;
42
+ const payload = { codeVerifier };
43
+ await saveOAuthState(auth.store, state, payload);
44
+ return { url, state, payload };
44
45
  }
45
- async getUser(query) {
46
+ async getUser(query, saved) {
46
47
  const auth = requireAuthConfig(this.auth);
47
48
  const { code, state } = parseCallbackQuery(query);
48
- const stored = await consumeOAuthState(auth.store, state);
49
+ const stored = await resolveOAuthState(auth.store, state, saved);
49
50
  if (typeof stored.codeVerifier !== "string") {
50
51
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
51
52
  }
@@ -56,7 +57,9 @@ export class Gitea {
56
57
  id: profileId(profile.id),
57
58
  name: profileString(profile.full_name) ?? profileString(profile.login),
58
59
  email: profileString(profile.email),
59
- image: profileString(profile.avatar_url)
60
+ image: profileString(profile.avatar_url),
61
+ raw: profile,
62
+ ...extractOAuthTokens(tokens)
60
63
  };
61
64
  }
62
65
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Tokens } from "../oauth2.js";
2
- import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
2
+ import type { AuthorizationRequest, OAuthCallbackQuery, OAuthUser, ProviderOptions, SavedOAuthState } from "../auth.js";
3
3
  export interface GitHubOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class GitHub {
@@ -12,6 +12,6 @@ export declare class GitHub {
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,6 +1,6 @@
1
1
  import { ArcticFetchError, createOAuth2Request, createOAuth2RequestError, encodeBasicCredentials, UnexpectedErrorResponseBodyError, UnexpectedResponseError } from "../request.js";
2
2
  import { OAuth2Tokens } from "../oauth2.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
4
4
  const authorizationEndpoint = "https://github.com/login/oauth/authorize";
5
5
  const tokenEndpoint = "https://github.com/login/oauth/access_token";
6
6
  const userEndpoint = "https://api.github.com/user";
@@ -65,13 +65,14 @@ export class GitHub {
65
65
  const auth = requireAuthConfig(this.auth);
66
66
  const state = generateOAuthState();
67
67
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
68
- await saveOAuthState(auth.store, state, {});
69
- return url;
68
+ const payload = {};
69
+ await saveOAuthState(auth.store, state, payload);
70
+ return { url, state, payload };
70
71
  }
71
- async getUser(query) {
72
+ async getUser(query, saved) {
72
73
  const auth = requireAuthConfig(this.auth);
73
74
  const { code, state } = parseCallbackQuery(query);
74
- await consumeOAuthState(auth.store, state);
75
+ await resolveOAuthState(auth.store, state, saved);
75
76
  const tokens = await this.validateAuthorizationCode(code);
76
77
  const accessToken = tokens.accessToken();
77
78
  const profile = await fetchUserProfile(userEndpoint, accessToken);
@@ -83,7 +84,9 @@ export class GitHub {
83
84
  id: profileId(profile.id),
84
85
  name: profileString(profile.name) ?? profileString(profile.login),
85
86
  email,
86
- image: profileString(profile.avatar_url)
87
+ image: profileString(profile.avatar_url),
88
+ raw: profile,
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 GitLabOptions extends ProviderOptions {
4
4
  baseURL?: string;
5
5
  }
@@ -16,6 +16,6 @@ export declare class GitLab {
16
16
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
17
17
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
18
18
  revokeToken(token: string): Promise<void>;
19
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
20
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
19
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
20
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
21
21
  }
@@ -1,6 +1,6 @@
1
1
  import { OAuth2Client } from "../client.js";
2
2
  import { joinURIAndPath } from "../request.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
4
4
  const envPrefix = "GITLAB";
5
5
  const defaultScopes = ["openid", "profile", "email"];
6
6
  export class GitLab {
@@ -43,13 +43,14 @@ export class GitLab {
43
43
  const auth = requireAuthConfig(this.auth);
44
44
  const state = generateOAuthState();
45
45
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
46
- await saveOAuthState(auth.store, state, {});
47
- return url;
46
+ const payload = {};
47
+ await saveOAuthState(auth.store, state, payload);
48
+ return { url, state, payload };
48
49
  }
49
- async getUser(query) {
50
+ async getUser(query, saved) {
50
51
  const auth = requireAuthConfig(this.auth);
51
52
  const { code, state } = parseCallbackQuery(query);
52
- await consumeOAuthState(auth.store, state);
53
+ await resolveOAuthState(auth.store, state, saved);
53
54
  const tokens = await this.validateAuthorizationCode(code);
54
55
  // GitLab id_tokens omit profile claims, so always use the OIDC userinfo endpoint.
55
56
  const userinfoEndpoint = joinURIAndPath(this.baseURL, "/oauth/userinfo");
@@ -58,7 +59,9 @@ export class GitLab {
58
59
  id: profileId(claims.sub),
59
60
  name: profileString(claims.name) ?? profileString(claims.nickname),
60
61
  email: profileString(claims.email),
61
- image: profileString(claims.picture)
62
+ image: profileString(claims.picture),
63
+ raw: claims,
64
+ ...extractOAuthTokens(tokens)
62
65
  };
63
66
  }
64
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 GoogleOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Google {
@@ -11,6 +11,6 @@ export declare class Google {
11
11
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
12
12
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
13
  revokeToken(token: string): Promise<void>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,6 +1,6 @@
1
1
  import { OAuth2Client, CodeChallengeMethod } from "../client.js";
2
2
  import { decodeIdToken } from "../oidc.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://accounts.google.com/o/oauth2/v2/auth";
5
5
  const tokenEndpoint = "https://oauth2.googleapis.com/token";
6
6
  const tokenRevocationEndpoint = "https://oauth2.googleapis.com/revoke";
@@ -42,13 +42,14 @@ export class Google {
42
42
  const state = generateOAuthState();
43
43
  const codeVerifier = generateOAuthCodeVerifier();
44
44
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
45
- await saveOAuthState(auth.store, state, { codeVerifier });
46
- return url;
45
+ const payload = { codeVerifier };
46
+ await saveOAuthState(auth.store, state, payload);
47
+ return { url, state, payload };
47
48
  }
48
- async getUser(query) {
49
+ async getUser(query, saved) {
49
50
  const auth = requireAuthConfig(this.auth);
50
51
  const { code, state } = parseCallbackQuery(query);
51
- const stored = await consumeOAuthState(auth.store, state);
52
+ const stored = await resolveOAuthState(auth.store, state, saved);
52
53
  if (typeof stored.codeVerifier !== "string") {
53
54
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
54
55
  }
@@ -64,7 +65,9 @@ export class Google {
64
65
  id: profileId(claims.sub),
65
66
  name: profileString(claims.name),
66
67
  email: profileString(claims.email),
67
- image: profileString(claims.picture)
68
+ image: profileString(claims.picture),
69
+ raw: claims,
70
+ ...extractOAuthTokens(tokens)
68
71
  };
69
72
  }
70
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 IntuitOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Intuit {
@@ -11,6 +11,6 @@ export declare class Intuit {
11
11
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
12
12
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
13
  revokeToken(token: string): Promise<void>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Client } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://appcenter.intuit.com/connect/oauth2";
4
4
  const tokenEndpoint = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer";
5
5
  const tokenRevocationEndpoint = "https://developer.API.intuit.com/v2/oauth2/tokens/revoke";
@@ -40,13 +40,14 @@ export class Intuit {
40
40
  const auth = requireAuthConfig(this.auth);
41
41
  const state = generateOAuthState();
42
42
  const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
43
- await saveOAuthState(auth.store, state, {});
44
- return url;
43
+ const payload = {};
44
+ await saveOAuthState(auth.store, state, payload);
45
+ return { url, state, payload };
45
46
  }
46
- async getUser(query) {
47
+ async getUser(query, saved) {
47
48
  const auth = requireAuthConfig(this.auth);
48
49
  const { code, state } = parseCallbackQuery(query);
49
- await consumeOAuthState(auth.store, state);
50
+ await resolveOAuthState(auth.store, state, saved);
50
51
  const tokens = await this.validateAuthorizationCode(code);
51
52
  // Intuit id_tokens omit profile claims, so always use the OIDC userinfo endpoint.
52
53
  const claims = await fetchUserProfile(userinfoEndpoint, tokens.accessToken());
@@ -60,7 +61,9 @@ export class Intuit {
60
61
  id: profileId(claims.sub),
61
62
  name,
62
63
  email: profileString(claims.email),
63
- image: null
64
+ image: null,
65
+ raw: claims,
66
+ ...extractOAuthTokens(tokens)
64
67
  };
65
68
  }
66
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 KakaoOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Kakao {
@@ -12,6 +12,6 @@ export declare class Kakao {
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://kauth.kakao.com/oauth/authorize";
4
4
  const tokenEndpoint = "https://kauth.kakao.com/oauth/token";
5
5
  const userEndpoint = "https://kapi.kakao.com/v2/user/me";
@@ -62,13 +62,14 @@ export class Kakao {
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 profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
74
75
  let name = null;
@@ -89,7 +90,9 @@ export class Kakao {
89
90
  id: profileId(profile.id),
90
91
  name,
91
92
  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 KeyCloakOptions extends ProviderOptions {
4
4
  realmURL?: string;
5
5
  }
@@ -16,6 +16,6 @@ export declare class KeyCloak {
16
16
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
17
17
  refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
18
18
  revokeToken(token: string): Promise<void>;
19
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
20
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
19
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
20
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
21
21
  }
@@ -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, 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 = "KEYCLOAK";
5
5
  const defaultScopes = ["openid", "profile", "email"];
6
6
  export class KeyCloak {
@@ -46,13 +46,14 @@ export class KeyCloak {
46
46
  const state = generateOAuthState();
47
47
  const codeVerifier = generateOAuthCodeVerifier();
48
48
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
49
- await saveOAuthState(auth.store, state, { codeVerifier });
50
- return url;
49
+ const payload = { codeVerifier };
50
+ await saveOAuthState(auth.store, state, payload);
51
+ return { url, state, payload };
51
52
  }
52
- async getUser(query) {
53
+ async getUser(query, saved) {
53
54
  const auth = requireAuthConfig(this.auth);
54
55
  const { code, state } = parseCallbackQuery(query);
55
- const stored = await consumeOAuthState(auth.store, state);
56
+ const stored = await resolveOAuthState(auth.store, state, saved);
56
57
  if (typeof stored.codeVerifier !== "string") {
57
58
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
58
59
  }
@@ -68,7 +69,9 @@ export class KeyCloak {
68
69
  id: profileId(claims.sub),
69
70
  name: profileString(claims.name) ?? profileString(claims.preferred_username),
70
71
  email: profileString(claims.email),
71
- image: profileString(claims.picture)
72
+ image: profileString(claims.picture),
73
+ raw: claims,
74
+ ...extractOAuthTokens(tokens)
72
75
  };
73
76
  }
74
77
  }
@@ -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 KickOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Kick {
@@ -13,6 +13,6 @@ export declare class Kick {
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 { createOAuth2Request, sendTokenRequest, sendTokenRevocationRequest } from "../request.js";
2
2
  import { createS256CodeChallenge } from "../oauth2.js";
3
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
4
4
  const authorizationEndpoint = "https://id.kick.com/oauth/authorize";
5
5
  const tokenEndpoint = "https://id.kick.com/oauth/token";
6
6
  const tokenRevocationEndpoint = "https://id.kick.com/oauth/revoke";
@@ -75,13 +75,14 @@ export class Kick {
75
75
  const state = generateOAuthState();
76
76
  const codeVerifier = generateOAuthCodeVerifier();
77
77
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
78
- await saveOAuthState(auth.store, state, { codeVerifier });
79
- return url;
78
+ const payload = { codeVerifier };
79
+ await saveOAuthState(auth.store, state, payload);
80
+ return { url, state, payload };
80
81
  }
81
- async getUser(query) {
82
+ async getUser(query, saved) {
82
83
  const auth = requireAuthConfig(this.auth);
83
84
  const { code, state } = parseCallbackQuery(query);
84
- const stored = await consumeOAuthState(auth.store, state);
85
+ const stored = await resolveOAuthState(auth.store, state, saved);
85
86
  if (typeof stored.codeVerifier !== "string") {
86
87
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
87
88
  }
@@ -97,7 +98,9 @@ export class Kick {
97
98
  id: profileId(profile.user_id),
98
99
  name: profileString(profile.name),
99
100
  email: profileString(profile.email),
100
- image: profileString(profile.profile_picture)
101
+ image: profileString(profile.profile_picture),
102
+ raw: profile,
103
+ ...extractOAuthTokens(tokens)
101
104
  };
102
105
  }
103
106
  }
@@ -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 LichessOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Lichess {
@@ -9,6 +9,6 @@ export declare class Lichess {
9
9
  constructor(clientId: string, redirectURI: string);
10
10
  createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): Promise<URL>;
11
11
  validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
12
- 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, CodeChallengeMethod } from "../client.js";
2
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
3
3
  const authorizationEndpoint = "https://lichess.org/oauth";
4
4
  const tokenEndpoint = "https://lichess.org/api/token";
5
5
  const accountEndpoint = "https://lichess.org/api/account";
@@ -31,13 +31,14 @@ export class Lichess {
31
31
  const state = generateOAuthState();
32
32
  const codeVerifier = generateOAuthCodeVerifier();
33
33
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
34
- await saveOAuthState(auth.store, state, { codeVerifier });
35
- return url;
34
+ const payload = { codeVerifier };
35
+ await saveOAuthState(auth.store, state, payload);
36
+ return { url, state, payload };
36
37
  }
37
- async getUser(query) {
38
+ async getUser(query, saved) {
38
39
  const auth = requireAuthConfig(this.auth);
39
40
  const { code, state } = parseCallbackQuery(query);
40
- const stored = await consumeOAuthState(auth.store, state);
41
+ const stored = await resolveOAuthState(auth.store, state, saved);
41
42
  if (typeof stored.codeVerifier !== "string") {
42
43
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
43
44
  }
@@ -57,7 +58,9 @@ export class Lichess {
57
58
  id: profileId(profile.id),
58
59
  name: profileString(profile.username),
59
60
  email,
60
- image: null
61
+ image: null,
62
+ raw: profile,
63
+ ...extractOAuthTokens(tokens)
61
64
  };
62
65
  }
63
66
  }
@@ -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 LineOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Line {
@@ -12,6 +12,6 @@ export declare class Line {
12
12
  createAuthorizationURL(state: string, codeVerifier: string, scopes: 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,7 +1,7 @@
1
1
  import { createS256CodeChallenge } from "../oauth2.js";
2
2
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
3
3
  import { decodeIdToken } from "../oidc.js";
4
- import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
4
+ import { extractOAuthTokens, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } from "../auth.js";
5
5
  const authorizationEndpoint = "https://access.line.me/oauth2/v2.1/authorize";
6
6
  const tokenEndpoint = "https://api.line.me/oauth2/v2.1/token";
7
7
  const userinfoEndpoint = "https://api.line.me/oauth2/v2.1/userinfo";
@@ -69,13 +69,14 @@ export class Line {
69
69
  const state = generateOAuthState();
70
70
  const codeVerifier = generateOAuthCodeVerifier();
71
71
  const url = await this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
72
- await saveOAuthState(auth.store, state, { codeVerifier });
73
- return url;
72
+ const payload = { codeVerifier };
73
+ await saveOAuthState(auth.store, state, payload);
74
+ return { url, state, payload };
74
75
  }
75
- async getUser(query) {
76
+ async getUser(query, saved) {
76
77
  const auth = requireAuthConfig(this.auth);
77
78
  const { code, state } = parseCallbackQuery(query);
78
- const stored = await consumeOAuthState(auth.store, state);
79
+ const stored = await resolveOAuthState(auth.store, state, saved);
79
80
  if (typeof stored.codeVerifier !== "string") {
80
81
  throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
81
82
  }
@@ -92,7 +93,9 @@ export class Line {
92
93
  id: profileId(claims.sub),
93
94
  name: profileString(claims.name),
94
95
  email: profileString(claims.email),
95
- image: profileString(claims.picture)
96
+ image: profileString(claims.picture),
97
+ raw: claims,
98
+ ...extractOAuthTokens(tokens)
96
99
  };
97
100
  }
98
101
  }
@@ -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 LinearOptions extends ProviderOptions {
4
4
  }
5
5
  export declare class Linear {
@@ -11,6 +11,6 @@ export declare class Linear {
11
11
  constructor(clientId: string, clientSecret: string, redirectURI: string);
12
12
  createAuthorizationURL(state: string, scopes: string[]): URL;
13
13
  validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
- getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
- getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<AuthorizationRequest>;
15
+ getUser(query: OAuthCallbackQuery, saved?: SavedOAuthState): Promise<OAuthUser>;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
- import { consumeOAuthState, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
2
+ import { extractOAuthTokens, generateOAuthState, OAuthProviderError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveOAuthState, resolveScopes, saveOAuthState } 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";
@@ -52,20 +52,23 @@ 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
+ await saveOAuthState(auth.store, state, payload);
57
+ return { url, state, payload };
57
58
  }
58
- async getUser(query) {
59
+ async getUser(query, saved) {
59
60
  const auth = requireAuthConfig(this.auth);
60
61
  const { code, state } = parseCallbackQuery(query);
61
- await consumeOAuthState(auth.store, state);
62
+ await resolveOAuthState(auth.store, state, saved);
62
63
  const tokens = await this.validateAuthorizationCode(code);
63
64
  const viewer = await fetchViewer(tokens.accessToken());
64
65
  return {
65
66
  id: profileId(viewer.id),
66
67
  name: profileString(viewer.name),
67
68
  email: profileString(viewer.email),
68
- image: profileString(viewer.avatarUrl)
69
+ image: profileString(viewer.avatarUrl),
70
+ raw: viewer,
71
+ ...extractOAuthTokens(tokens)
69
72
  };
70
73
  }
71
74
  }
@@ -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 {
@@ -12,6 +12,6 @@ export declare class LinkedIn {
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
  }