@better-auth/core 1.7.0-beta.7 → 1.7.0-beta.9
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.
- package/dist/api/index.d.mts +3 -3
- package/dist/context/global.mjs +1 -1
- package/dist/db/adapter/factory.mjs +1 -1
- package/dist/db/get-tables.mjs +3 -3
- package/dist/db/schema/account.d.mts +1 -1
- package/dist/db/schema/account.mjs +1 -1
- package/dist/error/codes.d.mts +0 -5
- package/dist/error/codes.mjs +0 -5
- package/dist/instrumentation/tracer.mjs +1 -1
- package/dist/oauth2/create-authorization-url.d.mts +1 -4
- package/dist/oauth2/create-authorization-url.mjs +1 -4
- package/dist/oauth2/index.d.mts +3 -4
- package/dist/oauth2/index.mjs +2 -3
- package/dist/oauth2/oauth-provider.d.mts +12 -50
- package/dist/oauth2/refresh-access-token.mjs +2 -1
- package/dist/oauth2/utils.d.mts +6 -1
- package/dist/oauth2/utils.mjs +24 -2
- package/dist/oauth2/verify-id-token.d.mts +6 -5
- package/dist/oauth2/verify-id-token.mjs +2 -2
- package/dist/social-providers/apple.d.mts +1 -5
- package/dist/social-providers/apple.mjs +5 -5
- package/dist/social-providers/atlassian.d.mts +1 -5
- package/dist/social-providers/atlassian.mjs +4 -4
- package/dist/social-providers/cognito.d.mts +1 -5
- package/dist/social-providers/cognito.mjs +11 -18
- package/dist/social-providers/discord.d.mts +1 -5
- package/dist/social-providers/discord.mjs +6 -7
- package/dist/social-providers/dropbox.d.mts +1 -5
- package/dist/social-providers/dropbox.mjs +5 -5
- package/dist/social-providers/facebook.d.mts +1 -5
- package/dist/social-providers/facebook.mjs +5 -5
- package/dist/social-providers/figma.d.mts +1 -5
- package/dist/social-providers/figma.mjs +5 -5
- package/dist/social-providers/github.d.mts +1 -5
- package/dist/social-providers/github.mjs +4 -4
- package/dist/social-providers/gitlab.d.mts +1 -5
- package/dist/social-providers/gitlab.mjs +6 -6
- package/dist/social-providers/google.d.mts +8 -10
- package/dist/social-providers/google.mjs +12 -13
- package/dist/social-providers/huggingface.d.mts +1 -5
- package/dist/social-providers/huggingface.mjs +8 -8
- package/dist/social-providers/index.d.mts +35 -177
- package/dist/social-providers/kakao.d.mts +1 -5
- package/dist/social-providers/kakao.mjs +8 -8
- package/dist/social-providers/kick.d.mts +1 -5
- package/dist/social-providers/kick.mjs +4 -4
- package/dist/social-providers/line.d.mts +1 -5
- package/dist/social-providers/line.mjs +10 -10
- package/dist/social-providers/linear.d.mts +1 -5
- package/dist/social-providers/linear.mjs +4 -4
- package/dist/social-providers/linkedin.d.mts +1 -5
- package/dist/social-providers/linkedin.mjs +10 -10
- package/dist/social-providers/microsoft-entra-id.d.mts +1 -5
- package/dist/social-providers/microsoft-entra-id.mjs +10 -11
- package/dist/social-providers/naver.d.mts +1 -5
- package/dist/social-providers/naver.mjs +4 -4
- package/dist/social-providers/notion.d.mts +1 -5
- package/dist/social-providers/notion.mjs +4 -4
- package/dist/social-providers/paybin.d.mts +1 -5
- package/dist/social-providers/paybin.mjs +10 -10
- package/dist/social-providers/paypal.d.mts +1 -5
- package/dist/social-providers/paypal.mjs +2 -8
- package/dist/social-providers/polar.d.mts +1 -5
- package/dist/social-providers/polar.mjs +8 -8
- package/dist/social-providers/railway.d.mts +1 -5
- package/dist/social-providers/railway.mjs +9 -9
- package/dist/social-providers/reddit.d.mts +1 -5
- package/dist/social-providers/reddit.mjs +5 -5
- package/dist/social-providers/roblox.d.mts +1 -5
- package/dist/social-providers/roblox.mjs +5 -5
- package/dist/social-providers/salesforce.d.mts +1 -5
- package/dist/social-providers/salesforce.mjs +8 -8
- package/dist/social-providers/slack.d.mts +1 -5
- package/dist/social-providers/slack.mjs +9 -9
- package/dist/social-providers/spotify.d.mts +1 -5
- package/dist/social-providers/spotify.mjs +5 -5
- package/dist/social-providers/tiktok.d.mts +1 -5
- package/dist/social-providers/tiktok.mjs +5 -9
- package/dist/social-providers/twitch.d.mts +1 -5
- package/dist/social-providers/twitch.mjs +4 -4
- package/dist/social-providers/twitter.d.mts +1 -5
- package/dist/social-providers/twitter.mjs +9 -9
- package/dist/social-providers/vercel.d.mts +1 -5
- package/dist/social-providers/vercel.mjs +7 -4
- package/dist/social-providers/vk.d.mts +1 -5
- package/dist/social-providers/vk.mjs +5 -5
- package/dist/social-providers/wechat.d.mts +1 -5
- package/dist/social-providers/wechat.mjs +5 -9
- package/dist/social-providers/zoom.d.mts +1 -6
- package/dist/social-providers/zoom.mjs +9 -15
- package/dist/types/context.d.mts +6 -2
- package/package.json +1 -1
- package/src/db/get-tables.ts +3 -8
- package/src/db/schema/account.ts +5 -14
- package/src/error/codes.ts +0 -5
- package/src/oauth2/create-authorization-url.ts +1 -1
- package/src/oauth2/index.ts +2 -12
- package/src/oauth2/oauth-provider.ts +11 -56
- package/src/oauth2/refresh-access-token.ts +3 -2
- package/src/oauth2/utils.ts +39 -1
- package/src/oauth2/verify-id-token.ts +7 -5
- package/src/social-providers/apple.ts +8 -13
- package/src/social-providers/atlassian.ts +8 -12
- package/src/social-providers/cognito.ts +11 -18
- package/src/social-providers/discord.ts +8 -19
- package/src/social-providers/dropbox.ts +7 -13
- package/src/social-providers/facebook.ts +9 -13
- package/src/social-providers/figma.ts +9 -13
- package/src/social-providers/github.ts +8 -12
- package/src/social-providers/gitlab.ts +8 -14
- package/src/social-providers/google.ts +23 -29
- package/src/social-providers/huggingface.ts +8 -12
- package/src/social-providers/kakao.ts +8 -16
- package/src/social-providers/kick.ts +7 -12
- package/src/social-providers/line.ts +10 -14
- package/src/social-providers/linear.ts +6 -12
- package/src/social-providers/linkedin.ts +10 -14
- package/src/social-providers/microsoft-entra-id.ts +8 -18
- package/src/social-providers/naver.ts +6 -12
- package/src/social-providers/notion.ts +6 -12
- package/src/social-providers/paybin.ts +11 -14
- package/src/social-providers/paypal.ts +8 -6
- package/src/social-providers/polar.ts +8 -12
- package/src/social-providers/railway.ts +9 -13
- package/src/social-providers/reddit.ts +7 -18
- package/src/social-providers/roblox.ts +7 -18
- package/src/social-providers/salesforce.ts +8 -12
- package/src/social-providers/slack.ts +9 -18
- package/src/social-providers/spotify.ts +7 -13
- package/src/social-providers/tiktok.ts +7 -13
- package/src/social-providers/twitch.ts +8 -12
- package/src/social-providers/twitter.ts +8 -17
- package/src/social-providers/vercel.ts +10 -16
- package/src/social-providers/vk.ts +7 -13
- package/src/social-providers/wechat.ts +8 -20
- package/src/social-providers/zoom.ts +6 -19
- package/src/types/context.ts +8 -2
- package/dist/oauth2/scopes.d.mts +0 -76
- package/dist/oauth2/scopes.mjs +0 -96
- package/src/oauth2/scopes.ts +0 -118
package/dist/oauth2/scopes.mjs
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
//#region src/oauth2/scopes.ts
|
|
2
|
-
/**
|
|
3
|
-
* Parse a provider's `scope` token-response field into a string array.
|
|
4
|
-
*
|
|
5
|
-
* RFC 6749 §3.3 defines `scope` as a space-delimited string, but providers
|
|
6
|
-
* vary: some (e.g. Twitch) return an already-split array. Accept both, plus the
|
|
7
|
-
* omitted/empty case, without ever calling `.split` on a non-string. Returns
|
|
8
|
-
* `[]` when no scope is present.
|
|
9
|
-
*
|
|
10
|
-
* @see https://github.com/better-auth/better-auth/issues/9076
|
|
11
|
-
*/
|
|
12
|
-
function parseScopeField(scope) {
|
|
13
|
-
if (Array.isArray(scope)) return scope.filter((s) => typeof s === "string" && s !== "");
|
|
14
|
-
if (typeof scope === "string") return scope.split(" ").filter(Boolean);
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Normalize a scope set into a single deduped, sorted array.
|
|
19
|
-
*
|
|
20
|
-
* Scope order is insignificant per RFC 6749 §3.3, so normalize for idempotent
|
|
21
|
-
* writes and trivial comparisons: trim each token, drop empties, dedupe, and
|
|
22
|
-
* sort ascending. Returns `[]` when the union is empty.
|
|
23
|
-
*
|
|
24
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
|
|
25
|
-
*/
|
|
26
|
-
function normalizeScopes(stored, incoming) {
|
|
27
|
-
const normalized = /* @__PURE__ */ new Set();
|
|
28
|
-
for (const scope of [...stored ?? [], ...incoming ?? []]) {
|
|
29
|
-
const trimmed = scope.trim();
|
|
30
|
-
if (trimmed) normalized.add(trimmed);
|
|
31
|
-
}
|
|
32
|
-
return [...normalized].sort();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Union the stored granted-scope set with the scopes observed on an
|
|
36
|
-
* authorization or token exchange.
|
|
37
|
-
*
|
|
38
|
-
* The provider's echoed `scope` is authoritative when present. RFC 6749 §3.3
|
|
39
|
-
* and §5.1 say an omitted or empty echo means the grant equals what was
|
|
40
|
-
* requested, so fall back to `requested` in that case. The result unions onto
|
|
41
|
-
* the stored grant (never narrows on a normal write) and is normalized per
|
|
42
|
-
* {@link normalizeScopes}.
|
|
43
|
-
*
|
|
44
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
|
|
45
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
|
|
46
|
-
*/
|
|
47
|
-
function unionGrantedScopes(stored, echoed, requested) {
|
|
48
|
-
return normalizeScopes(stored, echoed?.length ? echoed : requested);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Coerce a stored granted-scope value into a usable array.
|
|
52
|
-
*
|
|
53
|
-
* `account.grantedScopes` is nullable (legacy rows and non-OAuth accounts read
|
|
54
|
-
* as unset), and on dialects that store the array as a JSON string a malformed
|
|
55
|
-
* operator backfill could deserialize to a non-array. Both collapse to `[]`
|
|
56
|
-
* here so every reader works against a real `string[]` without re-deriving the
|
|
57
|
-
* guard.
|
|
58
|
-
*/
|
|
59
|
-
function readGrantedScopes(stored) {
|
|
60
|
-
return Array.isArray(stored) ? stored : [];
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Test whether a normalized granted-scope set contains a specific scope.
|
|
64
|
-
*
|
|
65
|
-
* Matching is exact and case-sensitive per RFC 6749 §3.3. The argument is the
|
|
66
|
-
* normalized `account.grantedScopes` array; a raw provider `scope` string must
|
|
67
|
-
* be run through {@link parseScopeField} first.
|
|
68
|
-
*
|
|
69
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
|
|
70
|
-
*/
|
|
71
|
-
function includesGrantedScope(granted, scope) {
|
|
72
|
-
return granted?.includes(scope) ?? false;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Compose the effective scope set to encode in a single authorization URL.
|
|
76
|
-
*
|
|
77
|
-
* Precedence: the provider's built-in defaults (unless `disableDefaultScope`),
|
|
78
|
-
* then the integrator's configured `options.scope`, then the per-request
|
|
79
|
-
* `scopes`. The result is the value persisted into OAuth state as the RFC 6749
|
|
80
|
-
* §5.1 fallback, so it is preserved verbatim (not normalized) to match what is
|
|
81
|
-
* sent to the provider.
|
|
82
|
-
*
|
|
83
|
-
* `defaultScopes` is a parameter rather than a provider-contract field so the
|
|
84
|
-
* runtime-synthesized generic OAuth provider, which has no static default set,
|
|
85
|
-
* can pass its configured scopes here.
|
|
86
|
-
*
|
|
87
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
|
|
88
|
-
*/
|
|
89
|
-
function resolveRequestedScopes(options, defaultScopes, perRequestScopes) {
|
|
90
|
-
const scopes = options?.disableDefaultScope ? [] : [...defaultScopes];
|
|
91
|
-
if (options?.scope) scopes.push(...options.scope);
|
|
92
|
-
if (perRequestScopes) scopes.push(...perRequestScopes);
|
|
93
|
-
return scopes;
|
|
94
|
-
}
|
|
95
|
-
//#endregion
|
|
96
|
-
export { includesGrantedScope, normalizeScopes, parseScopeField, readGrantedScopes, resolveRequestedScopes, unionGrantedScopes };
|
package/src/oauth2/scopes.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import type { ProviderOptions } from "./oauth-provider";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Parse a provider's `scope` token-response field into a string array.
|
|
5
|
-
*
|
|
6
|
-
* RFC 6749 §3.3 defines `scope` as a space-delimited string, but providers
|
|
7
|
-
* vary: some (e.g. Twitch) return an already-split array. Accept both, plus the
|
|
8
|
-
* omitted/empty case, without ever calling `.split` on a non-string. Returns
|
|
9
|
-
* `[]` when no scope is present.
|
|
10
|
-
*
|
|
11
|
-
* @see https://github.com/better-auth/better-auth/issues/9076
|
|
12
|
-
*/
|
|
13
|
-
export function parseScopeField(scope: unknown): string[] {
|
|
14
|
-
if (Array.isArray(scope))
|
|
15
|
-
return scope.filter((s): s is string => typeof s === "string" && s !== "");
|
|
16
|
-
if (typeof scope === "string") return scope.split(" ").filter(Boolean);
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Normalize a scope set into a single deduped, sorted array.
|
|
22
|
-
*
|
|
23
|
-
* Scope order is insignificant per RFC 6749 §3.3, so normalize for idempotent
|
|
24
|
-
* writes and trivial comparisons: trim each token, drop empties, dedupe, and
|
|
25
|
-
* sort ascending. Returns `[]` when the union is empty.
|
|
26
|
-
*
|
|
27
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
|
|
28
|
-
*/
|
|
29
|
-
export function normalizeScopes(
|
|
30
|
-
stored: string[] | null | undefined,
|
|
31
|
-
incoming?: string[] | undefined,
|
|
32
|
-
): string[] {
|
|
33
|
-
const normalized = new Set<string>();
|
|
34
|
-
for (const scope of [...(stored ?? []), ...(incoming ?? [])]) {
|
|
35
|
-
const trimmed = scope.trim();
|
|
36
|
-
if (trimmed) normalized.add(trimmed);
|
|
37
|
-
}
|
|
38
|
-
return [...normalized].sort();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Union the stored granted-scope set with the scopes observed on an
|
|
43
|
-
* authorization or token exchange.
|
|
44
|
-
*
|
|
45
|
-
* The provider's echoed `scope` is authoritative when present. RFC 6749 §3.3
|
|
46
|
-
* and §5.1 say an omitted or empty echo means the grant equals what was
|
|
47
|
-
* requested, so fall back to `requested` in that case. The result unions onto
|
|
48
|
-
* the stored grant (never narrows on a normal write) and is normalized per
|
|
49
|
-
* {@link normalizeScopes}.
|
|
50
|
-
*
|
|
51
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
|
|
52
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
|
|
53
|
-
*/
|
|
54
|
-
export function unionGrantedScopes(
|
|
55
|
-
stored: string[] | null | undefined,
|
|
56
|
-
echoed: string[] | undefined,
|
|
57
|
-
requested: string[] | undefined,
|
|
58
|
-
): string[] {
|
|
59
|
-
const granted = echoed?.length ? echoed : requested;
|
|
60
|
-
return normalizeScopes(stored, granted);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Coerce a stored granted-scope value into a usable array.
|
|
65
|
-
*
|
|
66
|
-
* `account.grantedScopes` is nullable (legacy rows and non-OAuth accounts read
|
|
67
|
-
* as unset), and on dialects that store the array as a JSON string a malformed
|
|
68
|
-
* operator backfill could deserialize to a non-array. Both collapse to `[]`
|
|
69
|
-
* here so every reader works against a real `string[]` without re-deriving the
|
|
70
|
-
* guard.
|
|
71
|
-
*/
|
|
72
|
-
export function readGrantedScopes(
|
|
73
|
-
stored: string[] | null | undefined,
|
|
74
|
-
): string[] {
|
|
75
|
-
return Array.isArray(stored) ? stored : [];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Test whether a normalized granted-scope set contains a specific scope.
|
|
80
|
-
*
|
|
81
|
-
* Matching is exact and case-sensitive per RFC 6749 §3.3. The argument is the
|
|
82
|
-
* normalized `account.grantedScopes` array; a raw provider `scope` string must
|
|
83
|
-
* be run through {@link parseScopeField} first.
|
|
84
|
-
*
|
|
85
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-3.3
|
|
86
|
-
*/
|
|
87
|
-
export function includesGrantedScope(
|
|
88
|
-
granted: string[] | null | undefined,
|
|
89
|
-
scope: string,
|
|
90
|
-
): boolean {
|
|
91
|
-
return granted?.includes(scope) ?? false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Compose the effective scope set to encode in a single authorization URL.
|
|
96
|
-
*
|
|
97
|
-
* Precedence: the provider's built-in defaults (unless `disableDefaultScope`),
|
|
98
|
-
* then the integrator's configured `options.scope`, then the per-request
|
|
99
|
-
* `scopes`. The result is the value persisted into OAuth state as the RFC 6749
|
|
100
|
-
* §5.1 fallback, so it is preserved verbatim (not normalized) to match what is
|
|
101
|
-
* sent to the provider.
|
|
102
|
-
*
|
|
103
|
-
* `defaultScopes` is a parameter rather than a provider-contract field so the
|
|
104
|
-
* runtime-synthesized generic OAuth provider, which has no static default set,
|
|
105
|
-
* can pass its configured scopes here.
|
|
106
|
-
*
|
|
107
|
-
* @see https://www.rfc-editor.org/rfc/rfc6749#section-5.1
|
|
108
|
-
*/
|
|
109
|
-
export function resolveRequestedScopes(
|
|
110
|
-
options: Pick<ProviderOptions, "scope" | "disableDefaultScope"> | undefined,
|
|
111
|
-
defaultScopes: string[],
|
|
112
|
-
perRequestScopes: string[] | undefined,
|
|
113
|
-
): string[] {
|
|
114
|
-
const scopes = options?.disableDefaultScope ? [] : [...defaultScopes];
|
|
115
|
-
if (options?.scope) scopes.push(...options.scope);
|
|
116
|
-
if (perRequestScopes) scopes.push(...perRequestScopes);
|
|
117
|
-
return scopes;
|
|
118
|
-
}
|