antarctic 0.2.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 (145) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +155 -0
  3. package/dist/auth.d.ts +63 -0
  4. package/dist/auth.js +191 -0
  5. package/dist/client.d.ts +16 -0
  6. package/dist/client.js +105 -0
  7. package/dist/index.d.ts +70 -0
  8. package/dist/index.js +69 -0
  9. package/dist/oauth2.d.ts +16 -0
  10. package/dist/oauth2.js +67 -0
  11. package/dist/oidc.d.ts +1 -0
  12. package/dist/oidc.js +11 -0
  13. package/dist/providers/42.d.ts +16 -0
  14. package/dist/providers/42.js +75 -0
  15. package/dist/providers/amazon-cognito.d.ts +21 -0
  16. package/dist/providers/amazon-cognito.js +76 -0
  17. package/dist/providers/anilist.d.ts +14 -0
  18. package/dist/providers/anilist.js +91 -0
  19. package/dist/providers/apple.d.ts +22 -0
  20. package/dist/providers/apple.js +106 -0
  21. package/dist/providers/atlassian.d.ts +17 -0
  22. package/dist/providers/atlassian.js +83 -0
  23. package/dist/providers/auth0.d.ts +21 -0
  24. package/dist/providers/auth0.js +80 -0
  25. package/dist/providers/authentik.d.ts +21 -0
  26. package/dist/providers/authentik.js +75 -0
  27. package/dist/providers/autodesk.d.ts +16 -0
  28. package/dist/providers/autodesk.js +60 -0
  29. package/dist/providers/battlenet.d.ts +16 -0
  30. package/dist/providers/battlenet.js +69 -0
  31. package/dist/providers/bitbucket.d.ts +15 -0
  32. package/dist/providers/bitbucket.js +79 -0
  33. package/dist/providers/box.d.ts +18 -0
  34. package/dist/providers/box.js +90 -0
  35. package/dist/providers/bungie.d.ts +17 -0
  36. package/dist/providers/bungie.js +72 -0
  37. package/dist/providers/coinbase.d.ts +18 -0
  38. package/dist/providers/coinbase.js +95 -0
  39. package/dist/providers/discord.d.ts +16 -0
  40. package/dist/providers/discord.js +68 -0
  41. package/dist/providers/donation-alerts.d.ts +17 -0
  42. package/dist/providers/donation-alerts.js +86 -0
  43. package/dist/providers/dribbble.d.ts +16 -0
  44. package/dist/providers/dribbble.js +73 -0
  45. package/dist/providers/dropbox.d.ts +16 -0
  46. package/dist/providers/dropbox.js +96 -0
  47. package/dist/providers/epicgames.d.ts +16 -0
  48. package/dist/providers/epicgames.js +60 -0
  49. package/dist/providers/etsy.d.ts +15 -0
  50. package/dist/providers/etsy.js +68 -0
  51. package/dist/providers/facebook.d.ts +16 -0
  52. package/dist/providers/facebook.js +80 -0
  53. package/dist/providers/figma.d.ts +15 -0
  54. package/dist/providers/figma.js +56 -0
  55. package/dist/providers/gitea.d.ts +19 -0
  56. package/dist/providers/gitea.js +62 -0
  57. package/dist/providers/github.d.ts +17 -0
  58. package/dist/providers/github.js +142 -0
  59. package/dist/providers/gitlab.d.ts +21 -0
  60. package/dist/providers/gitlab.js +64 -0
  61. package/dist/providers/google.d.ts +16 -0
  62. package/dist/providers/google.js +70 -0
  63. package/dist/providers/intuit.d.ts +16 -0
  64. package/dist/providers/intuit.js +66 -0
  65. package/dist/providers/kakao.d.ts +17 -0
  66. package/dist/providers/kakao.js +95 -0
  67. package/dist/providers/keycloak.d.ts +21 -0
  68. package/dist/providers/keycloak.js +74 -0
  69. package/dist/providers/kick.d.ts +18 -0
  70. package/dist/providers/kick.js +103 -0
  71. package/dist/providers/lichess.d.ts +14 -0
  72. package/dist/providers/lichess.js +63 -0
  73. package/dist/providers/line.d.ts +17 -0
  74. package/dist/providers/line.js +98 -0
  75. package/dist/providers/linear.d.ts +16 -0
  76. package/dist/providers/linear.js +112 -0
  77. package/dist/providers/linkedin.d.ts +17 -0
  78. package/dist/providers/linkedin.js +89 -0
  79. package/dist/providers/mastodon.d.ts +20 -0
  80. package/dist/providers/mastodon.js +67 -0
  81. package/dist/providers/mercadolibre.d.ts +17 -0
  82. package/dist/providers/mercadolibre.js +95 -0
  83. package/dist/providers/mercadopago.d.ts +17 -0
  84. package/dist/providers/mercadopago.js +95 -0
  85. package/dist/providers/microsoft-entra-id.d.ts +20 -0
  86. package/dist/providers/microsoft-entra-id.js +120 -0
  87. package/dist/providers/myanimelist.d.ts +15 -0
  88. package/dist/providers/myanimelist.js +56 -0
  89. package/dist/providers/naver.d.ts +17 -0
  90. package/dist/providers/naver.js +83 -0
  91. package/dist/providers/notion.d.ts +14 -0
  92. package/dist/providers/notion.js +65 -0
  93. package/dist/providers/okta.d.ts +22 -0
  94. package/dist/providers/okta.js +85 -0
  95. package/dist/providers/osu.d.ts +17 -0
  96. package/dist/providers/osu.js +82 -0
  97. package/dist/providers/patreon.d.ts +17 -0
  98. package/dist/providers/patreon.js +89 -0
  99. package/dist/providers/polar.d.ts +18 -0
  100. package/dist/providers/polar.js +100 -0
  101. package/dist/providers/reddit.d.ts +15 -0
  102. package/dist/providers/reddit.js +55 -0
  103. package/dist/providers/roblox.d.ts +16 -0
  104. package/dist/providers/roblox.js +67 -0
  105. package/dist/providers/salesforce.d.ts +21 -0
  106. package/dist/providers/salesforce.js +74 -0
  107. package/dist/providers/shikimori.d.ts +17 -0
  108. package/dist/providers/shikimori.js +81 -0
  109. package/dist/providers/slack.d.ts +14 -0
  110. package/dist/providers/slack.js +59 -0
  111. package/dist/providers/spotify.d.ts +15 -0
  112. package/dist/providers/spotify.js +67 -0
  113. package/dist/providers/startgg.d.ts +17 -0
  114. package/dist/providers/startgg.js +143 -0
  115. package/dist/providers/strava.d.ts +17 -0
  116. package/dist/providers/strava.js +85 -0
  117. package/dist/providers/synology.d.ts +9 -0
  118. package/dist/providers/synology.js +20 -0
  119. package/dist/providers/tiktok.d.ts +18 -0
  120. package/dist/providers/tiktok.js +109 -0
  121. package/dist/providers/tiltify.d.ts +17 -0
  122. package/dist/providers/tiltify.js +90 -0
  123. package/dist/providers/tumblr.d.ts +15 -0
  124. package/dist/providers/tumblr.js +63 -0
  125. package/dist/providers/twitch.d.ts +17 -0
  126. package/dist/providers/twitch.js +91 -0
  127. package/dist/providers/twitter.d.ts +16 -0
  128. package/dist/providers/twitter.js +67 -0
  129. package/dist/providers/vk.d.ts +16 -0
  130. package/dist/providers/vk.js +82 -0
  131. package/dist/providers/withings.d.ts +16 -0
  132. package/dist/providers/withings.js +120 -0
  133. package/dist/providers/workos.d.ts +16 -0
  134. package/dist/providers/workos.js +82 -0
  135. package/dist/providers/yahoo.d.ts +15 -0
  136. package/dist/providers/yahoo.js +65 -0
  137. package/dist/providers/yandex.d.ts +15 -0
  138. package/dist/providers/yandex.js +66 -0
  139. package/dist/providers/zoom.d.ts +16 -0
  140. package/dist/providers/zoom.js +66 -0
  141. package/dist/request.d.ts +26 -0
  142. package/dist/request.js +182 -0
  143. package/dist/utils.d.ts +2 -0
  144. package/dist/utils.js +20 -0
  145. package/package.json +42 -0
@@ -0,0 +1,83 @@
1
+ import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
+ import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ const authorizationEndpoint = "https://auth.atlassian.com/authorize";
4
+ const tokenEndpoint = "https://auth.atlassian.com/oauth/token";
5
+ const userEndpoint = "https://api.atlassian.com/me";
6
+ const envPrefix = "ATLASSIAN";
7
+ const defaultScopes = ["read:me"];
8
+ export class Atlassian {
9
+ clientId;
10
+ clientSecret;
11
+ redirectURI;
12
+ auth = null;
13
+ constructor(clientIdOrOptions, clientSecret, redirectURI) {
14
+ if (typeof clientIdOrOptions === "object") {
15
+ this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
16
+ clientSecret: true,
17
+ redirectURI: true
18
+ });
19
+ this.clientId = this.auth.clientId;
20
+ this.clientSecret = this.auth.clientSecret ?? "";
21
+ this.redirectURI = this.auth.redirectURI ?? "";
22
+ }
23
+ else {
24
+ this.clientId = clientIdOrOptions;
25
+ this.clientSecret = clientSecret ?? "";
26
+ this.redirectURI = redirectURI ?? "";
27
+ }
28
+ }
29
+ createAuthorizationURL(state, scopes) {
30
+ const url = new URL(authorizationEndpoint);
31
+ url.searchParams.set("response_type", "code");
32
+ url.searchParams.set("client_id", this.clientId);
33
+ url.searchParams.set("state", state);
34
+ if (scopes.length > 0) {
35
+ url.searchParams.set("scope", scopes.join(" "));
36
+ }
37
+ url.searchParams.set("redirect_uri", this.redirectURI);
38
+ url.searchParams.set("audience", "api.atlassian.com");
39
+ url.searchParams.set("prompt", "consent");
40
+ return url;
41
+ }
42
+ async validateAuthorizationCode(code) {
43
+ const body = new URLSearchParams();
44
+ body.set("grant_type", "authorization_code");
45
+ body.set("code", code);
46
+ body.set("redirect_uri", this.redirectURI);
47
+ body.set("client_id", this.clientId);
48
+ body.set("client_secret", this.clientSecret);
49
+ const request = createOAuth2Request(tokenEndpoint, body);
50
+ const tokens = await sendTokenRequest(request);
51
+ return tokens;
52
+ }
53
+ async refreshAccessToken(refreshToken) {
54
+ const body = new URLSearchParams();
55
+ body.set("grant_type", "refresh_token");
56
+ body.set("refresh_token", refreshToken);
57
+ body.set("client_id", this.clientId);
58
+ body.set("client_secret", this.clientSecret);
59
+ const request = createOAuth2Request(tokenEndpoint, body);
60
+ const tokens = await sendTokenRequest(request);
61
+ return tokens;
62
+ }
63
+ async getAuthorizationURL(scopes) {
64
+ const auth = requireAuthConfig(this.auth);
65
+ const state = generateOAuthState();
66
+ const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
67
+ await saveOAuthState(auth.store, state, {});
68
+ return url;
69
+ }
70
+ async getUser(query) {
71
+ const auth = requireAuthConfig(this.auth);
72
+ const { code, state } = parseCallbackQuery(query);
73
+ await consumeOAuthState(auth.store, state);
74
+ const tokens = await this.validateAuthorizationCode(code);
75
+ const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
76
+ return {
77
+ id: profileId(profile.account_id),
78
+ name: profileString(profile.name) ?? profileString(profile.nickname),
79
+ email: profileString(profile.email),
80
+ image: profileString(profile.picture)
81
+ };
82
+ }
83
+ }
@@ -0,0 +1,21 @@
1
+ import type { OAuth2Tokens } from "../oauth2.js";
2
+ import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
3
+ export interface Auth0Options extends ProviderOptions {
4
+ domain?: string;
5
+ }
6
+ export declare class Auth0 {
7
+ private authorizationEndpoint;
8
+ private tokenEndpoint;
9
+ private tokenRevocationEndpoint;
10
+ private userinfoEndpoint;
11
+ private client;
12
+ private auth;
13
+ constructor(options: Auth0Options);
14
+ constructor(domain: string, clientId: string, clientSecret: string | null, redirectURI: string);
15
+ createAuthorizationURL(state: string, codeVerifier: string | null, scopes: string[]): URL;
16
+ validateAuthorizationCode(code: string, codeVerifier: string | null): Promise<OAuth2Tokens>;
17
+ refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
18
+ revokeToken(token: string): Promise<void>;
19
+ getAuthorizationURL(scopes?: string[]): Promise<URL>;
20
+ getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
21
+ }
@@ -0,0 +1,80 @@
1
+ import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
+ import { decodeIdToken } from "../oidc.js";
3
+ import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
4
+ const envPrefix = "AUTH0";
5
+ const defaultScopes = ["openid", "profile", "email"];
6
+ export class Auth0 {
7
+ authorizationEndpoint;
8
+ tokenEndpoint;
9
+ tokenRevocationEndpoint;
10
+ userinfoEndpoint;
11
+ client;
12
+ auth = null;
13
+ constructor(domainOrOptions, clientId, clientSecret, redirectURI) {
14
+ let domain;
15
+ if (typeof domainOrOptions === "object") {
16
+ this.auth = resolveAuthConfig(envPrefix, domainOrOptions, { redirectURI: true });
17
+ domain = requireProviderOption(domainOrOptions.domain, envPrefix, "DOMAIN", "domain");
18
+ this.client = new OAuth2Client(this.auth.clientId, this.auth.clientSecret, this.auth.redirectURI);
19
+ }
20
+ else {
21
+ domain = domainOrOptions;
22
+ this.client = new OAuth2Client(clientId ?? "", clientSecret ?? null, redirectURI ?? null);
23
+ }
24
+ this.authorizationEndpoint = `https://${domain}/authorize`;
25
+ this.tokenEndpoint = `https://${domain}/oauth/token`;
26
+ this.tokenRevocationEndpoint = `https://${domain}/oauth/revoke`;
27
+ this.userinfoEndpoint = `https://${domain}/userinfo`;
28
+ }
29
+ createAuthorizationURL(state, codeVerifier, scopes) {
30
+ let url;
31
+ if (codeVerifier !== null) {
32
+ url = this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint, state, CodeChallengeMethod.S256, codeVerifier, scopes);
33
+ }
34
+ else {
35
+ url = this.client.createAuthorizationURL(this.authorizationEndpoint, state, scopes);
36
+ }
37
+ return url;
38
+ }
39
+ async validateAuthorizationCode(code, codeVerifier) {
40
+ const tokens = await this.client.validateAuthorizationCode(this.tokenEndpoint, code, codeVerifier);
41
+ return tokens;
42
+ }
43
+ async refreshAccessToken(refreshToken) {
44
+ const tokens = await this.client.refreshAccessToken(this.tokenEndpoint, refreshToken, []);
45
+ return tokens;
46
+ }
47
+ async revokeToken(token) {
48
+ await this.client.revokeToken(this.tokenRevocationEndpoint, token);
49
+ }
50
+ async getAuthorizationURL(scopes) {
51
+ const auth = requireAuthConfig(this.auth);
52
+ const state = generateOAuthState();
53
+ const codeVerifier = generateOAuthCodeVerifier();
54
+ const url = this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
55
+ await saveOAuthState(auth.store, state, { codeVerifier });
56
+ return url;
57
+ }
58
+ async getUser(query) {
59
+ const auth = requireAuthConfig(this.auth);
60
+ const { code, state } = parseCallbackQuery(query);
61
+ const stored = await consumeOAuthState(auth.store, state);
62
+ if (typeof stored.codeVerifier !== "string") {
63
+ throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
64
+ }
65
+ const tokens = await this.validateAuthorizationCode(code, stored.codeVerifier);
66
+ let claims;
67
+ if ("id_token" in tokens.data) {
68
+ claims = decodeIdToken(tokens.idToken());
69
+ }
70
+ else {
71
+ claims = await fetchUserProfile(this.userinfoEndpoint, tokens.accessToken());
72
+ }
73
+ return {
74
+ id: profileId(claims.sub),
75
+ name: profileString(claims.name) ?? profileString(claims.nickname),
76
+ email: profileString(claims.email),
77
+ image: profileString(claims.picture)
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,21 @@
1
+ import type { OAuth2Tokens } from "../oauth2.js";
2
+ import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
3
+ export interface AuthentikOptions extends ProviderOptions {
4
+ baseURL?: string;
5
+ }
6
+ export declare class Authentik {
7
+ private authorizationEndpoint;
8
+ private tokenEndpoint;
9
+ private tokenRevocationEndpoint;
10
+ private userinfoEndpoint;
11
+ private client;
12
+ private auth;
13
+ constructor(options: AuthentikOptions);
14
+ constructor(baseURL: string, clientId: string, clientSecret: string | null, redirectURI: string);
15
+ createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): URL;
16
+ validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
17
+ refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
18
+ revokeToken(token: string): Promise<void>;
19
+ getAuthorizationURL(scopes?: string[]): Promise<URL>;
20
+ getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
21
+ }
@@ -0,0 +1,75 @@
1
+ import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
+ import { joinURIAndPath } from "../request.js";
3
+ import { decodeIdToken } from "../oidc.js";
4
+ import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, requireProviderOption, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
5
+ const envPrefix = "AUTHENTIK";
6
+ const defaultScopes = ["openid", "profile", "email"];
7
+ export class Authentik {
8
+ authorizationEndpoint;
9
+ tokenEndpoint;
10
+ tokenRevocationEndpoint;
11
+ userinfoEndpoint;
12
+ client;
13
+ auth = null;
14
+ constructor(baseURLOrOptions, clientId, clientSecret, redirectURI) {
15
+ let baseURL;
16
+ if (typeof baseURLOrOptions === "object") {
17
+ this.auth = resolveAuthConfig(envPrefix, baseURLOrOptions, { redirectURI: true });
18
+ baseURL = requireProviderOption(baseURLOrOptions.baseURL, envPrefix, "BASE_URL", "baseURL");
19
+ this.client = new OAuth2Client(this.auth.clientId, this.auth.clientSecret, this.auth.redirectURI);
20
+ }
21
+ else {
22
+ baseURL = baseURLOrOptions;
23
+ this.client = new OAuth2Client(clientId ?? "", clientSecret ?? null, redirectURI ?? null);
24
+ }
25
+ this.authorizationEndpoint = joinURIAndPath(baseURL, "/application/o/authorize/");
26
+ this.tokenEndpoint = joinURIAndPath(baseURL, "/application/o/token/");
27
+ this.tokenRevocationEndpoint = joinURIAndPath(baseURL, "/application/o/revoke/");
28
+ this.userinfoEndpoint = joinURIAndPath(baseURL, "/application/o/userinfo/");
29
+ }
30
+ createAuthorizationURL(state, codeVerifier, scopes) {
31
+ const url = this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint, state, CodeChallengeMethod.S256, codeVerifier, scopes);
32
+ return url;
33
+ }
34
+ async validateAuthorizationCode(code, codeVerifier) {
35
+ const tokens = await this.client.validateAuthorizationCode(this.tokenEndpoint, code, codeVerifier);
36
+ return tokens;
37
+ }
38
+ async refreshAccessToken(refreshToken) {
39
+ const tokens = await this.client.refreshAccessToken(this.tokenEndpoint, refreshToken, []);
40
+ return tokens;
41
+ }
42
+ async revokeToken(token) {
43
+ await this.client.revokeToken(this.tokenRevocationEndpoint, token);
44
+ }
45
+ async getAuthorizationURL(scopes) {
46
+ const auth = requireAuthConfig(this.auth);
47
+ const state = generateOAuthState();
48
+ const codeVerifier = generateOAuthCodeVerifier();
49
+ const url = this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
50
+ await saveOAuthState(auth.store, state, { codeVerifier });
51
+ return url;
52
+ }
53
+ async getUser(query) {
54
+ const auth = requireAuthConfig(this.auth);
55
+ const { code, state } = parseCallbackQuery(query);
56
+ const stored = await consumeOAuthState(auth.store, state);
57
+ if (typeof stored.codeVerifier !== "string") {
58
+ throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
59
+ }
60
+ const tokens = await this.validateAuthorizationCode(code, stored.codeVerifier);
61
+ let claims;
62
+ if ("id_token" in tokens.data) {
63
+ claims = decodeIdToken(tokens.idToken());
64
+ }
65
+ else {
66
+ claims = await fetchUserProfile(this.userinfoEndpoint, tokens.accessToken());
67
+ }
68
+ return {
69
+ id: profileId(claims.sub),
70
+ name: profileString(claims.name) ?? profileString(claims.preferred_username),
71
+ email: profileString(claims.email),
72
+ image: profileString(claims.picture)
73
+ };
74
+ }
75
+ }
@@ -0,0 +1,16 @@
1
+ import type { OAuth2Tokens } from "../oauth2.js";
2
+ import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
3
+ export interface AutodeskOptions extends ProviderOptions {
4
+ }
5
+ export declare class Autodesk {
6
+ private client;
7
+ private auth;
8
+ constructor(options: AutodeskOptions);
9
+ constructor(clientId: string, clientSecret: string | null, redirectURI: string);
10
+ createAuthorizationURL(state: string, codeVerifier: string, scopes: string[]): URL;
11
+ validateAuthorizationCode(code: string, codeVerifier: string): Promise<OAuth2Tokens>;
12
+ refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
+ revokeToken(token: string): Promise<void>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
+ getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
16
+ }
@@ -0,0 +1,60 @@
1
+ import { CodeChallengeMethod, OAuth2Client } from "../client.js";
2
+ import { consumeOAuthState, fetchUserProfile, generateOAuthCodeVerifier, generateOAuthState, InvalidOAuthCallbackError, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ const authorizationEndpoint = "https://developer.api.autodesk.com/authentication/v2/authorize";
4
+ const tokenEndpoint = "https://developer.api.autodesk.com/authentication/v2/token";
5
+ const tokenRevocationEndpoint = "https://developer.api.autodesk.com/authentication/v2/revoke";
6
+ const userinfoEndpoint = "https://api.userprofile.autodesk.com/userinfo";
7
+ const envPrefix = "AUTODESK";
8
+ const defaultScopes = ["openid", "user-profile:read"];
9
+ export class Autodesk {
10
+ client;
11
+ auth = null;
12
+ constructor(clientIdOrOptions, clientSecret, redirectURI) {
13
+ if (typeof clientIdOrOptions === "object") {
14
+ this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, { redirectURI: true });
15
+ this.client = new OAuth2Client(this.auth.clientId, this.auth.clientSecret, this.auth.redirectURI);
16
+ }
17
+ else {
18
+ this.client = new OAuth2Client(clientIdOrOptions, clientSecret ?? null, redirectURI ?? null);
19
+ }
20
+ }
21
+ createAuthorizationURL(state, codeVerifier, scopes) {
22
+ const url = this.client.createAuthorizationURLWithPKCE(authorizationEndpoint, state, CodeChallengeMethod.S256, codeVerifier, scopes);
23
+ return url;
24
+ }
25
+ async validateAuthorizationCode(code, codeVerifier) {
26
+ const tokens = await this.client.validateAuthorizationCode(tokenEndpoint, code, codeVerifier);
27
+ return tokens;
28
+ }
29
+ async refreshAccessToken(refreshToken) {
30
+ const tokens = await this.client.refreshAccessToken(tokenEndpoint, refreshToken, []);
31
+ return tokens;
32
+ }
33
+ async revokeToken(token) {
34
+ await this.client.revokeToken(tokenRevocationEndpoint, token);
35
+ }
36
+ async getAuthorizationURL(scopes) {
37
+ const auth = requireAuthConfig(this.auth);
38
+ const state = generateOAuthState();
39
+ const codeVerifier = generateOAuthCodeVerifier();
40
+ const url = this.createAuthorizationURL(state, codeVerifier, resolveScopes(scopes, auth, defaultScopes));
41
+ await saveOAuthState(auth.store, state, { codeVerifier });
42
+ return url;
43
+ }
44
+ async getUser(query) {
45
+ const auth = requireAuthConfig(this.auth);
46
+ const { code, state } = parseCallbackQuery(query);
47
+ const stored = await consumeOAuthState(auth.store, state);
48
+ if (typeof stored.codeVerifier !== "string") {
49
+ throw new InvalidOAuthCallbackError("Missing PKCE code verifier for OAuth state");
50
+ }
51
+ const tokens = await this.validateAuthorizationCode(code, stored.codeVerifier);
52
+ const claims = await fetchUserProfile(userinfoEndpoint, tokens.accessToken());
53
+ return {
54
+ id: profileId(claims.sub),
55
+ name: profileString(claims.name) ?? profileString(claims.preferred_username),
56
+ email: profileString(claims.email),
57
+ image: profileString(claims.picture)
58
+ };
59
+ }
60
+ }
@@ -0,0 +1,16 @@
1
+ import type { OAuth2Tokens } from "../oauth2.js";
2
+ import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
3
+ export interface BattleNetOptions extends ProviderOptions {
4
+ }
5
+ export declare class BattleNet {
6
+ private clientId;
7
+ private clientSecret;
8
+ private redirectURI;
9
+ private auth;
10
+ constructor(options: BattleNetOptions);
11
+ constructor(clientId: string, clientSecret: string, redirectURI: string);
12
+ createAuthorizationURL(state: string, scopes: string[]): URL;
13
+ validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
+ getAuthorizationURL(scopes?: string[]): Promise<URL>;
15
+ getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
16
+ }
@@ -0,0 +1,69 @@
1
+ import { createOAuth2Request, sendTokenRequest } from "../request.js";
2
+ import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ const authorizationEndpoint = "https://oauth.battle.net/authorize";
4
+ const tokenEndpoint = "https://oauth.battle.net/token";
5
+ const userinfoEndpoint = "https://oauth.battle.net/userinfo";
6
+ const envPrefix = "BATTLE_NET";
7
+ const defaultScopes = ["openid"];
8
+ export class BattleNet {
9
+ clientId;
10
+ clientSecret;
11
+ redirectURI;
12
+ auth = null;
13
+ constructor(clientIdOrOptions, clientSecret, redirectURI) {
14
+ if (typeof clientIdOrOptions === "object") {
15
+ this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
16
+ clientSecret: true,
17
+ redirectURI: true
18
+ });
19
+ this.clientId = this.auth.clientId;
20
+ this.clientSecret = this.auth.clientSecret ?? "";
21
+ this.redirectURI = this.auth.redirectURI ?? "";
22
+ }
23
+ else {
24
+ this.clientId = clientIdOrOptions;
25
+ this.clientSecret = clientSecret ?? "";
26
+ this.redirectURI = redirectURI ?? "";
27
+ }
28
+ }
29
+ createAuthorizationURL(state, scopes) {
30
+ const url = new URL(authorizationEndpoint);
31
+ url.searchParams.set("response_type", "code");
32
+ url.searchParams.set("client_id", this.clientId);
33
+ url.searchParams.set("state", state);
34
+ url.searchParams.set("scope", scopes.join(" "));
35
+ url.searchParams.set("redirect_uri", this.redirectURI);
36
+ return url;
37
+ }
38
+ async validateAuthorizationCode(code) {
39
+ const body = new URLSearchParams();
40
+ body.set("grant_type", "authorization_code");
41
+ body.set("code", code);
42
+ body.set("redirect_uri", this.redirectURI);
43
+ body.set("client_id", this.clientId);
44
+ body.set("client_secret", this.clientSecret);
45
+ const request = createOAuth2Request(tokenEndpoint, body);
46
+ const tokens = await sendTokenRequest(request);
47
+ return tokens;
48
+ }
49
+ async getAuthorizationURL(scopes) {
50
+ const auth = requireAuthConfig(this.auth);
51
+ const state = generateOAuthState();
52
+ const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
53
+ await saveOAuthState(auth.store, state, {});
54
+ return url;
55
+ }
56
+ async getUser(query) {
57
+ const auth = requireAuthConfig(this.auth);
58
+ const { code, state } = parseCallbackQuery(query);
59
+ await consumeOAuthState(auth.store, state);
60
+ const tokens = await this.validateAuthorizationCode(code);
61
+ const profile = await fetchUserProfile(userinfoEndpoint, tokens.accessToken());
62
+ return {
63
+ id: profileId(profile.sub),
64
+ name: profileString(profile.battletag),
65
+ email: null,
66
+ image: null
67
+ };
68
+ }
69
+ }
@@ -0,0 +1,15 @@
1
+ import type { OAuth2Tokens } from "../oauth2.js";
2
+ import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
3
+ export interface BitbucketOptions extends ProviderOptions {
4
+ }
5
+ export declare class Bitbucket {
6
+ private client;
7
+ private auth;
8
+ constructor(options: BitbucketOptions);
9
+ constructor(clientId: string, clientSecret: string, redirectURI: string);
10
+ createAuthorizationURL(state: string): URL;
11
+ validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
12
+ refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
13
+ getAuthorizationURL(): Promise<URL>;
14
+ getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
15
+ }
@@ -0,0 +1,79 @@
1
+ import { OAuth2Client } from "../client.js";
2
+ import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, saveOAuthState } from "../auth.js";
3
+ const authorizationEndpoint = "https://bitbucket.org/site/oauth2/authorize";
4
+ const tokenEndpoint = "https://bitbucket.org/site/oauth2/access_token";
5
+ const userEndpoint = "https://api.bitbucket.org/2.0/user";
6
+ const userEmailsEndpoint = "https://api.bitbucket.org/2.0/user/emails";
7
+ const envPrefix = "BITBUCKET";
8
+ export class Bitbucket {
9
+ client;
10
+ auth = null;
11
+ constructor(clientIdOrOptions, clientSecret, redirectURI) {
12
+ if (typeof clientIdOrOptions === "object") {
13
+ this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
14
+ clientSecret: true,
15
+ redirectURI: true
16
+ });
17
+ this.client = new OAuth2Client(this.auth.clientId, this.auth.clientSecret, this.auth.redirectURI);
18
+ }
19
+ else {
20
+ this.client = new OAuth2Client(clientIdOrOptions, clientSecret ?? null, redirectURI ?? null);
21
+ }
22
+ }
23
+ createAuthorizationURL(state) {
24
+ const url = this.client.createAuthorizationURL(authorizationEndpoint, state, []);
25
+ return url;
26
+ }
27
+ async validateAuthorizationCode(code) {
28
+ const tokens = await this.client.validateAuthorizationCode(tokenEndpoint, code, null);
29
+ return tokens;
30
+ }
31
+ async refreshAccessToken(refreshToken) {
32
+ const tokens = await this.client.refreshAccessToken(tokenEndpoint, refreshToken, []);
33
+ return tokens;
34
+ }
35
+ async getAuthorizationURL() {
36
+ const auth = requireAuthConfig(this.auth);
37
+ const state = generateOAuthState();
38
+ const url = this.createAuthorizationURL(state);
39
+ await saveOAuthState(auth.store, state, {});
40
+ return url;
41
+ }
42
+ async getUser(query) {
43
+ const auth = requireAuthConfig(this.auth);
44
+ const { code, state } = parseCallbackQuery(query);
45
+ await consumeOAuthState(auth.store, state);
46
+ const tokens = await this.validateAuthorizationCode(code);
47
+ const accessToken = tokens.accessToken();
48
+ const profile = await fetchUserProfile(userEndpoint, accessToken);
49
+ let image = null;
50
+ if (typeof profile.links === "object" && profile.links !== null) {
51
+ const avatar = profile.links.avatar;
52
+ if (typeof avatar === "object" && avatar !== null) {
53
+ image = profileString(avatar.href);
54
+ }
55
+ }
56
+ return {
57
+ id: profileId(profile.uuid ?? profile.account_id),
58
+ name: profileString(profile.display_name) ?? profileString(profile.username),
59
+ email: await fetchPrimaryEmail(accessToken),
60
+ image
61
+ };
62
+ }
63
+ }
64
+ // Emails are not in the profile and need the "email" scope on the consumer.
65
+ async function fetchPrimaryEmail(accessToken) {
66
+ let data;
67
+ try {
68
+ data = await fetchUserProfile(userEmailsEndpoint, accessToken);
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ if (!Array.isArray(data.values)) {
74
+ return null;
75
+ }
76
+ const entries = data.values.filter((entry) => typeof entry === "object" && entry !== null && typeof entry.email === "string");
77
+ const primary = entries.find((entry) => entry.is_primary === true);
78
+ return primary?.email ?? entries[0]?.email ?? null;
79
+ }
@@ -0,0 +1,18 @@
1
+ import type { OAuth2Tokens } from "../oauth2.js";
2
+ import type { OAuthCallbackQuery, OAuthUser, ProviderOptions } from "../auth.js";
3
+ export interface BoxOptions extends ProviderOptions {
4
+ }
5
+ export declare class Box {
6
+ private clientId;
7
+ private clientSecret;
8
+ private redirectURI;
9
+ private auth;
10
+ constructor(options: BoxOptions);
11
+ constructor(clientId: string, clientSecret: string, redirectURI: string);
12
+ createAuthorizationURL(state: string, scopes: string[]): URL;
13
+ validateAuthorizationCode(code: string): Promise<OAuth2Tokens>;
14
+ refreshAccessToken(refreshToken: string): Promise<OAuth2Tokens>;
15
+ revokeToken(token: string): Promise<void>;
16
+ getAuthorizationURL(scopes?: string[]): Promise<URL>;
17
+ getUser(query: OAuthCallbackQuery): Promise<OAuthUser>;
18
+ }
@@ -0,0 +1,90 @@
1
+ import { createOAuth2Request, sendTokenRequest, sendTokenRevocationRequest } from "../request.js";
2
+ import { consumeOAuthState, fetchUserProfile, generateOAuthState, parseCallbackQuery, profileId, profileString, requireAuthConfig, resolveAuthConfig, resolveScopes, saveOAuthState } from "../auth.js";
3
+ const authorizationEndpoint = "https://account.box.com/api/oauth2/authorize";
4
+ const tokenEndpoint = "https://api.box.com/oauth2/token";
5
+ const tokenRevocationEndpoint = "https://api.box.com/oauth2/revoke";
6
+ const userEndpoint = "https://api.box.com/2.0/users/me";
7
+ const envPrefix = "BOX";
8
+ const defaultScopes = [];
9
+ export class Box {
10
+ clientId;
11
+ clientSecret;
12
+ redirectURI;
13
+ auth = null;
14
+ constructor(clientIdOrOptions, clientSecret, redirectURI) {
15
+ if (typeof clientIdOrOptions === "object") {
16
+ this.auth = resolveAuthConfig(envPrefix, clientIdOrOptions, {
17
+ clientSecret: true,
18
+ redirectURI: true
19
+ });
20
+ this.clientId = this.auth.clientId;
21
+ this.clientSecret = this.auth.clientSecret ?? "";
22
+ this.redirectURI = this.auth.redirectURI ?? "";
23
+ }
24
+ else {
25
+ this.clientId = clientIdOrOptions;
26
+ this.clientSecret = clientSecret ?? "";
27
+ this.redirectURI = redirectURI ?? "";
28
+ }
29
+ }
30
+ createAuthorizationURL(state, scopes) {
31
+ const url = new URL(authorizationEndpoint);
32
+ url.searchParams.set("response_type", "code");
33
+ url.searchParams.set("client_id", this.clientId);
34
+ url.searchParams.set("state", state);
35
+ if (scopes.length > 0) {
36
+ url.searchParams.set("scope", scopes.join(" "));
37
+ }
38
+ url.searchParams.set("redirect_uri", this.redirectURI);
39
+ return url;
40
+ }
41
+ async validateAuthorizationCode(code) {
42
+ const body = new URLSearchParams();
43
+ body.set("grant_type", "authorization_code");
44
+ body.set("code", code);
45
+ body.set("redirect_uri", this.redirectURI);
46
+ body.set("client_id", this.clientId);
47
+ body.set("client_secret", this.clientSecret);
48
+ const request = createOAuth2Request(tokenEndpoint, body);
49
+ const tokens = await sendTokenRequest(request);
50
+ return tokens;
51
+ }
52
+ async refreshAccessToken(refreshToken) {
53
+ const body = new URLSearchParams();
54
+ body.set("grant_type", "refresh_token");
55
+ body.set("refresh_token", refreshToken);
56
+ body.set("client_id", this.clientId);
57
+ body.set("client_secret", this.clientSecret);
58
+ const request = createOAuth2Request(tokenEndpoint, body);
59
+ const tokens = await sendTokenRequest(request);
60
+ return tokens;
61
+ }
62
+ async revokeToken(token) {
63
+ const body = new URLSearchParams();
64
+ body.set("token", token);
65
+ body.set("client_id", this.clientId);
66
+ body.set("client_secret", this.clientSecret);
67
+ const request = createOAuth2Request(tokenRevocationEndpoint, body);
68
+ await sendTokenRevocationRequest(request);
69
+ }
70
+ async getAuthorizationURL(scopes) {
71
+ const auth = requireAuthConfig(this.auth);
72
+ const state = generateOAuthState();
73
+ const url = this.createAuthorizationURL(state, resolveScopes(scopes, auth, defaultScopes));
74
+ await saveOAuthState(auth.store, state, {});
75
+ return url;
76
+ }
77
+ async getUser(query) {
78
+ const auth = requireAuthConfig(this.auth);
79
+ const { code, state } = parseCallbackQuery(query);
80
+ await consumeOAuthState(auth.store, state);
81
+ const tokens = await this.validateAuthorizationCode(code);
82
+ const profile = await fetchUserProfile(userEndpoint, tokens.accessToken());
83
+ return {
84
+ id: profileId(profile.id),
85
+ name: profileString(profile.name),
86
+ email: profileString(profile.login),
87
+ image: profileString(profile.avatar_url)
88
+ };
89
+ }
90
+ }