@better-auth-ui/core 1.6.30 → 1.6.32
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/{create-auth-plugin-DcxR23rZ.js → create-auth-plugin-D4wsYnHD.js} +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +46 -15
- package/dist/lib/auth-mutation-keys.d.ts +5 -4
- package/dist/lib/auth-redirect.d.ts +31 -0
- package/dist/lib/view-paths.d.ts +5 -0
- package/dist/plugins/admin/admin-localization.d.ts +5 -0
- package/dist/plugins/admin/admin-mutation-keys.d.ts +9 -0
- package/dist/plugins/admin/admin-plugin.d.ts +32 -0
- package/dist/plugins/device-authorization/device-authorization-localization.d.ts +33 -0
- package/dist/plugins/device-authorization/device-authorization-mutation-keys.d.ts +16 -0
- package/dist/plugins/device-authorization/device-authorization-plugin.d.ts +59 -0
- package/dist/plugins/oauth-provider/oauth-provider-localization.d.ts +25 -0
- package/dist/plugins/oauth-provider/oauth-provider-mutation-keys.d.ts +12 -0
- package/dist/plugins/oauth-provider/oauth-provider-plugin.d.ts +78 -0
- package/dist/plugins/oauth-provider/oauth-provider-query-keys.d.ts +9 -0
- package/dist/plugins.d.ts +10 -0
- package/dist/plugins.js +193 -63
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/lib/auth-mutation-keys.ts +5 -4
- package/src/lib/auth-redirect.ts +105 -0
- package/src/lib/view-paths.ts +6 -0
- package/src/plugins/admin/admin-localization.ts +6 -0
- package/src/plugins/admin/admin-mutation-keys.ts +9 -0
- package/src/plugins/admin/admin-plugin.ts +52 -0
- package/src/plugins/device-authorization/device-authorization-localization.ts +36 -0
- package/src/plugins/device-authorization/device-authorization-mutation-keys.ts +16 -0
- package/src/plugins/device-authorization/device-authorization-plugin.ts +65 -0
- package/src/plugins/oauth-provider/oauth-provider-localization.ts +27 -0
- package/src/plugins/oauth-provider/oauth-provider-mutation-keys.ts +12 -0
- package/src/plugins/oauth-provider/oauth-provider-plugin.ts +132 -0
- package/src/plugins/oauth-provider/oauth-provider-query-keys.ts +10 -0
- package/src/plugins.ts +10 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createAuthPlugin } from "../../lib/create-auth-plugin"
|
|
2
|
+
// Side-effect import so this file participates in declaration merging on the
|
|
3
|
+
// same module instance that external consumers reach via `@better-auth-ui/core`.
|
|
4
|
+
import type {} from "../../lib/view-paths"
|
|
5
|
+
import {
|
|
6
|
+
type DeviceAuthorizationLocalization,
|
|
7
|
+
deviceAuthorizationLocalization
|
|
8
|
+
} from "./device-authorization-localization"
|
|
9
|
+
|
|
10
|
+
declare module "../../lib/view-paths" {
|
|
11
|
+
/** Widens `AuthViewPaths` with the device-authorization path when this plugin is imported. */
|
|
12
|
+
interface AuthViewPaths {
|
|
13
|
+
/** @default "device" */
|
|
14
|
+
deviceAuthorization?: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type DeviceAuthorizationPluginOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Override the plugin's default localization strings.
|
|
21
|
+
* @remarks `DeviceAuthorizationLocalization`
|
|
22
|
+
*/
|
|
23
|
+
localization?: Partial<DeviceAuthorizationLocalization>
|
|
24
|
+
/**
|
|
25
|
+
* URL segment for the device-authorization view.
|
|
26
|
+
* @remarks `string`
|
|
27
|
+
* @default "device"
|
|
28
|
+
*/
|
|
29
|
+
path?: string
|
|
30
|
+
/**
|
|
31
|
+
* Number of characters rendered by the device-code input.
|
|
32
|
+
*
|
|
33
|
+
* Keep this in sync with Better Auth's `deviceAuthorization({ userCodeLength })`
|
|
34
|
+
* server option.
|
|
35
|
+
*
|
|
36
|
+
* @default 8
|
|
37
|
+
*/
|
|
38
|
+
userCodeLength?: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const DEFAULT_USER_CODE_LENGTH = 8
|
|
42
|
+
|
|
43
|
+
function resolveUserCodeLength(value?: number) {
|
|
44
|
+
if (value === undefined || !Number.isFinite(value)) {
|
|
45
|
+
return DEFAULT_USER_CODE_LENGTH
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return Math.max(1, Math.floor(value))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const deviceAuthorizationPlugin = createAuthPlugin(
|
|
52
|
+
"deviceAuthorization",
|
|
53
|
+
(options: DeviceAuthorizationPluginOptions = {}) => ({
|
|
54
|
+
localization: {
|
|
55
|
+
...deviceAuthorizationLocalization,
|
|
56
|
+
...options.localization
|
|
57
|
+
},
|
|
58
|
+
userCodeLength: resolveUserCodeLength(options.userCodeLength),
|
|
59
|
+
viewPaths: {
|
|
60
|
+
auth: {
|
|
61
|
+
deviceAuthorization: options.path ?? "device"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const oauthProviderLocalization = {
|
|
2
|
+
/** @remarks `"Authorize {{client}}"` */
|
|
3
|
+
authorize: "Authorize {{client}}",
|
|
4
|
+
/** @remarks `"{{client}} wants to access your account."` */
|
|
5
|
+
authorizationDescription: "{{client}} wants to access your account.",
|
|
6
|
+
/** @remarks `"This will allow {{client}} to:"` */
|
|
7
|
+
requestedPermissions: "This will allow {{client}} to:",
|
|
8
|
+
/** @remarks `"Signed in as"` */
|
|
9
|
+
signedInAs: "Signed in as",
|
|
10
|
+
/** @remarks `"Allow"` */
|
|
11
|
+
allow: "Allow",
|
|
12
|
+
/** @remarks `"Cancel"` */
|
|
13
|
+
cancel: "Cancel",
|
|
14
|
+
/** @remarks `"Privacy policy"` */
|
|
15
|
+
privacyPolicy: "Privacy policy",
|
|
16
|
+
/** @remarks `"Terms of service"` */
|
|
17
|
+
termsOfService: "Terms of service",
|
|
18
|
+
/** @remarks `"Invalid authorization request"` */
|
|
19
|
+
invalidRequest: "Invalid authorization request",
|
|
20
|
+
/** @remarks `"This authorization request is missing required information or is no longer valid."` */
|
|
21
|
+
invalidRequestDescription:
|
|
22
|
+
"This authorization request is missing required information or is no longer valid.",
|
|
23
|
+
/** @remarks `"Application"` */
|
|
24
|
+
application: "Application"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type OAuthProviderLocalization = typeof oauthProviderLocalization
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutation keys contributed by the OAuth provider plugin.
|
|
3
|
+
*
|
|
4
|
+
* All keys live under the shared `["auth"]` namespace so global auth
|
|
5
|
+
* mutation observers handle errors consistently.
|
|
6
|
+
*/
|
|
7
|
+
export const oauthProviderMutationKeys = {
|
|
8
|
+
/** Prefix matching every OAuth provider mutation. */
|
|
9
|
+
all: ["auth", "oauthProvider"] as const,
|
|
10
|
+
/** Key for accepting or denying an OAuth authorization request. */
|
|
11
|
+
consent: ["auth", "oauthProvider", "consent"] as const
|
|
12
|
+
} as const
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { createAuthPlugin } from "../../lib/create-auth-plugin"
|
|
2
|
+
// Side-effect import so this file participates in declaration merging on the
|
|
3
|
+
// same module instance that external consumers reach via `@better-auth-ui/core`.
|
|
4
|
+
import type {} from "../../lib/view-paths"
|
|
5
|
+
import {
|
|
6
|
+
type OAuthProviderLocalization,
|
|
7
|
+
oauthProviderLocalization
|
|
8
|
+
} from "./oauth-provider-localization"
|
|
9
|
+
|
|
10
|
+
declare module "../../lib/view-paths" {
|
|
11
|
+
/** Widens `AuthViewPaths` with the OAuth consent path when this plugin is imported. */
|
|
12
|
+
interface AuthViewPaths {
|
|
13
|
+
/** @default "consent" */
|
|
14
|
+
oauthConsent?: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type OAuthScopeMetadata = {
|
|
19
|
+
/** Short permission label displayed to the user. */
|
|
20
|
+
label: string
|
|
21
|
+
/** Optional explanation of the data or access represented by the scope. */
|
|
22
|
+
description?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type OAuthScopeMetadataMap = Record<string, OAuthScopeMetadata>
|
|
26
|
+
|
|
27
|
+
export const oauthProviderScopeMetadata: OAuthScopeMetadataMap = {
|
|
28
|
+
openid: {
|
|
29
|
+
label: "Verify your identity",
|
|
30
|
+
description: "Access your unique account identifier."
|
|
31
|
+
},
|
|
32
|
+
profile: {
|
|
33
|
+
label: "View your profile",
|
|
34
|
+
description: "View your name and profile picture."
|
|
35
|
+
},
|
|
36
|
+
email: {
|
|
37
|
+
label: "View your email address",
|
|
38
|
+
description: "View your email address and whether it is verified."
|
|
39
|
+
},
|
|
40
|
+
offline_access: {
|
|
41
|
+
label: "Maintain access",
|
|
42
|
+
description:
|
|
43
|
+
"Access your data when you are not actively using the application."
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type OAuthAuthorizationRequest = {
|
|
48
|
+
clientId?: string
|
|
49
|
+
scopes: string[]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Keep client-controlled links and images on browser-safe web protocols.
|
|
54
|
+
*/
|
|
55
|
+
export function sanitizeOAuthClientUrl(
|
|
56
|
+
value: string | null | undefined
|
|
57
|
+
): string | undefined {
|
|
58
|
+
if (!value) return undefined
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const url = new URL(value)
|
|
62
|
+
|
|
63
|
+
return url.protocol === "https:" || url.protocol === "http:"
|
|
64
|
+
? url.href
|
|
65
|
+
: undefined
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Read the display-safe parts of Better Auth's signed authorization query.
|
|
73
|
+
*
|
|
74
|
+
* The complete query string must remain in the browser URL so
|
|
75
|
+
* `oauthProviderClient()` can forward and verify it during consent.
|
|
76
|
+
*/
|
|
77
|
+
export function parseOAuthAuthorizationRequest(
|
|
78
|
+
search: string
|
|
79
|
+
): OAuthAuthorizationRequest {
|
|
80
|
+
const params = new URLSearchParams(search)
|
|
81
|
+
const clientId = params.get("client_id")?.trim() || undefined
|
|
82
|
+
const scopes = Array.from(
|
|
83
|
+
new Set(
|
|
84
|
+
(params.get("scope") ?? "")
|
|
85
|
+
.split(/\s+/)
|
|
86
|
+
.map((scope) => scope.trim())
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return { clientId, scopes }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type OAuthProviderPluginOptions = {
|
|
95
|
+
/**
|
|
96
|
+
* Override the plugin's default localization strings.
|
|
97
|
+
* @remarks `OAuthProviderLocalization`
|
|
98
|
+
*/
|
|
99
|
+
localization?: Partial<OAuthProviderLocalization>
|
|
100
|
+
/**
|
|
101
|
+
* URL segment for the OAuth consent view.
|
|
102
|
+
* @remarks `string`
|
|
103
|
+
* @default "consent"
|
|
104
|
+
*/
|
|
105
|
+
path?: string
|
|
106
|
+
/**
|
|
107
|
+
* Labels and descriptions for custom OAuth scopes.
|
|
108
|
+
*
|
|
109
|
+
* Entries override the built-in metadata for `openid`, `profile`, `email`,
|
|
110
|
+
* and `offline_access`. Unknown scopes remain visible using their raw value.
|
|
111
|
+
*/
|
|
112
|
+
scopeMetadata?: OAuthScopeMetadataMap
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export const oauthProviderPlugin = createAuthPlugin(
|
|
116
|
+
"oauthProvider",
|
|
117
|
+
(options: OAuthProviderPluginOptions = {}) => ({
|
|
118
|
+
localization: {
|
|
119
|
+
...oauthProviderLocalization,
|
|
120
|
+
...options.localization
|
|
121
|
+
},
|
|
122
|
+
scopeMetadata: {
|
|
123
|
+
...oauthProviderScopeMetadata,
|
|
124
|
+
...options.scopeMetadata
|
|
125
|
+
},
|
|
126
|
+
viewPaths: {
|
|
127
|
+
auth: {
|
|
128
|
+
oauthConsent: options.path ?? "consent"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Query keys contributed by the OAuth provider plugin. */
|
|
2
|
+
export const oauthProviderQueryKeys = {
|
|
3
|
+
/** Prefix matching every OAuth provider query. */
|
|
4
|
+
all: ["auth", "oauthProvider"] as const,
|
|
5
|
+
/** Prefix for public OAuth client metadata queries. */
|
|
6
|
+
publicClients: ["auth", "oauthProvider", "publicClient"] as const,
|
|
7
|
+
/** Key for the public metadata of a specific OAuth client. */
|
|
8
|
+
publicClient: (clientId: string | undefined) =>
|
|
9
|
+
[...oauthProviderQueryKeys.publicClients, clientId ?? null] as const
|
|
10
|
+
} as const
|
package/src/plugins.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export * from "./plugins/admin/admin-localization"
|
|
2
|
+
export * from "./plugins/admin/admin-mutation-keys"
|
|
3
|
+
export * from "./plugins/admin/admin-plugin"
|
|
1
4
|
export * from "./plugins/api-key/api-key-localization"
|
|
2
5
|
export * from "./plugins/api-key/api-key-mutation-keys"
|
|
3
6
|
export * from "./plugins/api-key/api-key-plugin"
|
|
@@ -5,6 +8,9 @@ export * from "./plugins/api-key/api-key-query-keys"
|
|
|
5
8
|
export * from "./plugins/delete-user/delete-user-localization"
|
|
6
9
|
export * from "./plugins/delete-user/delete-user-mutation-keys"
|
|
7
10
|
export * from "./plugins/delete-user/delete-user-plugin"
|
|
11
|
+
export * from "./plugins/device-authorization/device-authorization-localization"
|
|
12
|
+
export * from "./plugins/device-authorization/device-authorization-mutation-keys"
|
|
13
|
+
export * from "./plugins/device-authorization/device-authorization-plugin"
|
|
8
14
|
export * from "./plugins/last-login-method/last-login-method-localization"
|
|
9
15
|
export * from "./plugins/last-login-method/last-login-method-plugin"
|
|
10
16
|
export * from "./plugins/magic-link/magic-link-localization"
|
|
@@ -14,6 +20,10 @@ export * from "./plugins/multi-session/multi-session-localization"
|
|
|
14
20
|
export * from "./plugins/multi-session/multi-session-mutation-keys"
|
|
15
21
|
export * from "./plugins/multi-session/multi-session-plugin"
|
|
16
22
|
export * from "./plugins/multi-session/multi-session-query-keys"
|
|
23
|
+
export * from "./plugins/oauth-provider/oauth-provider-localization"
|
|
24
|
+
export * from "./plugins/oauth-provider/oauth-provider-mutation-keys"
|
|
25
|
+
export * from "./plugins/oauth-provider/oauth-provider-plugin"
|
|
26
|
+
export * from "./plugins/oauth-provider/oauth-provider-query-keys"
|
|
17
27
|
export * from "./plugins/organization/organization-localization"
|
|
18
28
|
export * from "./plugins/organization/organization-mutation-keys"
|
|
19
29
|
export * from "./plugins/organization/organization-plugin"
|