@polaris-auth/client 0.7.0 → 0.9.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.
- package/README.md +38 -3
- package/dist/api-keys.d.ts +2657 -0
- package/dist/api-keys.js +19 -0
- package/dist/index.d.ts +19 -2
- package/dist/index.js +14 -1
- package/dist/oauth.d.ts +8556 -0
- package/dist/oauth.js +57 -0
- package/dist/passkey.d.ts +2028 -0
- package/dist/passkey.js +19 -0
- package/dist/social.d.ts +2791 -0
- package/dist/social.js +23 -0
- package/dist/webauthn.d.ts +27 -0
- package/dist/webauthn.js +129 -0
- package/openapi.json +7332 -1
- package/package.json +18 -3
- package/src/api-keys.ts +26 -0
- package/src/index.ts +23 -2
- package/src/oauth.ts +64 -0
- package/src/passkey.ts +26 -0
- package/src/schema.d.ts +8501 -4043
- package/src/social.ts +30 -0
- package/src/webauthn.ts +172 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polaris-auth/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Typed TypeScript client for Polaris for PHP, generated from the route manifest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"polaris",
|
|
@@ -22,7 +22,20 @@
|
|
|
22
22
|
"openapi",
|
|
23
23
|
"openapi-fetch",
|
|
24
24
|
"typescript",
|
|
25
|
-
"client"
|
|
25
|
+
"client",
|
|
26
|
+
"passkey",
|
|
27
|
+
"webauthn",
|
|
28
|
+
"social-login",
|
|
29
|
+
"api-keys",
|
|
30
|
+
"oauth2",
|
|
31
|
+
"oauth2-server",
|
|
32
|
+
"oidc",
|
|
33
|
+
"openid-connect",
|
|
34
|
+
"pkce",
|
|
35
|
+
"dpop",
|
|
36
|
+
"device-flow",
|
|
37
|
+
"ciba",
|
|
38
|
+
"token-exchange"
|
|
26
39
|
],
|
|
27
40
|
"homepage": "https://github.com/univeros/polaris-core/tree/main/packages/client-ts#readme",
|
|
28
41
|
"bugs": "https://github.com/univeros/polaris-core/issues",
|
|
@@ -57,12 +70,14 @@
|
|
|
57
70
|
"generate": "php ../../bin/polaris manifest --format=openapi --bootstrap=polaris.php > openapi.json && openapi-typescript openapi.json -o src/schema.d.ts && node scripts/generate-namespaces.mjs",
|
|
58
71
|
"typecheck": "tsc --noEmit",
|
|
59
72
|
"build": "tsc -p tsconfig.build.json",
|
|
60
|
-
"test": "vitest run"
|
|
73
|
+
"test": "vitest run",
|
|
74
|
+
"e2e": "playwright test"
|
|
61
75
|
},
|
|
62
76
|
"dependencies": {
|
|
63
77
|
"openapi-fetch": "^0.17.0"
|
|
64
78
|
},
|
|
65
79
|
"devDependencies": {
|
|
80
|
+
"@playwright/test": "^1.56.1",
|
|
66
81
|
"@types/node": "^22.20.2",
|
|
67
82
|
"openapi-typescript": "^7.13.0",
|
|
68
83
|
"typescript": "^5.9.3",
|
package/src/api-keys.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* Generated by scripts/generate-namespaces.mjs from openapi.json; do not edit. */
|
|
2
|
+
import type { Client } from "openapi-fetch";
|
|
3
|
+
import type { paths } from "./schema.js";
|
|
4
|
+
import type { Init } from "./namespace.js";
|
|
5
|
+
|
|
6
|
+
/** The `api-keys` plugin's routes as methods of `client.apiKeys`. */
|
|
7
|
+
export function apiKeys(client: Client<paths>) {
|
|
8
|
+
return {
|
|
9
|
+
/** POST /api-keys: Create an API key */
|
|
10
|
+
create: (...init: Init<"/api-keys", "post">) => client.POST("/api-keys", ...init),
|
|
11
|
+
/** DELETE /api-keys/{id}: Revoke an API key */
|
|
12
|
+
delete: (...init: Init<"/api-keys/{id}", "delete">) => client.DELETE("/api-keys/{id}", ...init),
|
|
13
|
+
/** GET /api-keys: List API keys */
|
|
14
|
+
list: (...init: Init<"/api-keys", "get">) => client.GET("/api-keys", ...init),
|
|
15
|
+
/** GET /api-keys/{id}: Read an API key */
|
|
16
|
+
read: (...init: Init<"/api-keys/{id}", "get">) => client.GET("/api-keys/{id}", ...init),
|
|
17
|
+
/** POST /api-keys/{id}/rotate: Rotate an API key */
|
|
18
|
+
rotate: (...init: Init<"/api-keys/{id}/rotate", "post">) => client.POST("/api-keys/{id}/rotate", ...init),
|
|
19
|
+
/** PATCH /api-keys/{id}: Update an API key */
|
|
20
|
+
update: (...init: Init<"/api-keys/{id}", "patch">) => client.PATCH("/api-keys/{id}", ...init),
|
|
21
|
+
/** POST /api-keys/verify: Verify an API key */
|
|
22
|
+
verify: (...init: Init<"/api-keys/verify", "post">) => client.POST("/api-keys/verify", ...init),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ApiKeysApi = ReturnType<typeof apiKeys>;
|
package/src/index.ts
CHANGED
|
@@ -4,9 +4,13 @@ import { anonymous, type AnonymousApi } from "./anonymous.js";
|
|
|
4
4
|
import { audit, type AuditApi } from "./audit.js";
|
|
5
5
|
import { challengeRetry, type ChallengeOptions } from "./challenge.js";
|
|
6
6
|
import { multiSession, type MultiSessionApi } from "./multi-session.js";
|
|
7
|
+
import { passkey, type PasskeyApi } from "./passkey.js";
|
|
7
8
|
import { passwordless, type PasswordlessApi } from "./passwordless.js";
|
|
8
9
|
import { sentinel, type SentinelApi } from "./sentinel.js";
|
|
9
10
|
import { scim, type ScimApi } from "./scim.js";
|
|
11
|
+
import { social, type SocialApi } from "./social.js";
|
|
12
|
+
import { apiKeys, type ApiKeysApi } from "./api-keys.js";
|
|
13
|
+
import { oauth, type OauthApi } from "./oauth.js";
|
|
10
14
|
import { sso, type SsoApi } from "./sso.js";
|
|
11
15
|
import { username, type UsernameApi } from "./username.js";
|
|
12
16
|
import type { components, paths } from "./schema.js";
|
|
@@ -17,17 +21,22 @@ export { anonymous, type AnonymousApi } from "./anonymous.js";
|
|
|
17
21
|
export { audit, type AuditApi } from "./audit.js";
|
|
18
22
|
export { challengeRetry, type ChallengeOptions } from "./challenge.js";
|
|
19
23
|
export { multiSession, type MultiSessionApi } from "./multi-session.js";
|
|
24
|
+
export { passkey, type PasskeyApi } from "./passkey.js";
|
|
20
25
|
export { passwordless, type PasswordlessApi } from "./passwordless.js";
|
|
21
26
|
export { sentinel, type SentinelApi } from "./sentinel.js";
|
|
22
27
|
export { scim, type ScimApi } from "./scim.js";
|
|
28
|
+
export { social, type SocialApi } from "./social.js";
|
|
29
|
+
export { apiKeys, type ApiKeysApi } from "./api-keys.js";
|
|
30
|
+
export { oauth, type OauthApi } from "./oauth.js";
|
|
23
31
|
export { sso, type SsoApi } from "./sso.js";
|
|
24
32
|
export { username, type UsernameApi } from "./username.js";
|
|
33
|
+
export { registerPasskey, signInWithPasskey, passkeyAssertion, passkeyAutofillAvailable, type SignInWithPasskeyOptions } from "./webauthn.js";
|
|
25
34
|
|
|
26
35
|
/** The `{ error, message }` envelope every non-2xx response of a core route carries. */
|
|
27
36
|
export type ErrorBody = components["schemas"]["Error"];
|
|
28
37
|
/** The `{ errors: [...] }` envelope of a core route's 422. */
|
|
29
38
|
export type ValidationErrorBody = components["schemas"]["ValidationError"];
|
|
30
|
-
/** The RFC 9457 problem document every non-2xx response of a plugin route (`audit`, `admin`, `sentinel`, `sso`, `scim`, `passwordless`, `username`, `anonymous`, `multi-session`) carries. */
|
|
39
|
+
/** The RFC 9457 problem document every non-2xx response of a plugin route (`audit`, `admin`, `sentinel`, `sso`, `scim`, `passwordless`, `username`, `anonymous`, `multi-session`, `social`, `passkey`, `api-keys`, `oauth`) carries. */
|
|
31
40
|
export type ProblemBody = components["schemas"]["Problem"];
|
|
32
41
|
|
|
33
42
|
export interface PolarisClientOptions extends ClientOptions {
|
|
@@ -67,6 +76,14 @@ export interface PolarisClient extends Client<paths> {
|
|
|
67
76
|
* The device travels as the `X-Polaris-Device` header a sign-in answers (or the HttpOnly cookie in a browser).
|
|
68
77
|
*/
|
|
69
78
|
readonly multiSession: MultiSessionApi;
|
|
79
|
+
/** The `polaris/social` routes: `client.social.start()`, `exchange()`, `oneTap()`, `accounts()`, `link()`, `unlink()`, `token()`. */
|
|
80
|
+
readonly social: SocialApi;
|
|
81
|
+
/** The `polaris/passkey` routes (`registerOptions()`, `registerVerify()`, `authenticateOptions()`, `authenticateVerify()`, `list()`, `rename()`, `delete()`); `registerPasskey()` and `signInWithPasskey()` run the browser ceremonies. */
|
|
82
|
+
readonly passkey: PasskeyApi;
|
|
83
|
+
/** The `polaris/api-keys` routes: `client.apiKeys.list()`, `create()`, `read()`, `update()`, `delete()`, `rotate()`, `verify()`. A key goes in `Authorization: Bearer pk_...` like a session token. */
|
|
84
|
+
readonly apiKeys: ApiKeysApi;
|
|
85
|
+
/** The `polaris/oauth-provider` routes: `client.oauth.authorize()`, `decision()`, `token()`, `userinfo()`, `revoke()`, `introspect()`, `register()`, the device, CIBA, consent, client-management and discovery methods. */
|
|
86
|
+
readonly oauth: OauthApi;
|
|
70
87
|
/** A new client on the same options bound to another token (null for anonymous); this one is unchanged. */
|
|
71
88
|
withToken(token: string | null): PolarisClient;
|
|
72
89
|
}
|
|
@@ -75,7 +92,7 @@ export interface PolarisClient extends Client<paths> {
|
|
|
75
92
|
* An `openapi-fetch` client typed by `paths` (generated from `polaris manifest --format=openapi`), so
|
|
76
93
|
* `client.POST("/auth/login", { body })` checks the body and types `data` and `error`; the plugins' routes
|
|
77
94
|
* are also methods of `client.audit`, `client.admin`, `client.sentinel`, `client.sso`, `client.scim`, `client.passwordless`,
|
|
78
|
-
* `client.username`, `client.anonymous` and `client.
|
|
95
|
+
* `client.username`, `client.anonymous`, `client.multiSession`, `client.social`, `client.passkey`, `client.apiKeys` and `client.oauth`; `challenge.captcha`
|
|
79
96
|
* answers a sentinel captcha challenge with one retry. No refresh loop and no storage: when to refresh
|
|
80
97
|
* and where to keep tokens is the application's policy.
|
|
81
98
|
*/
|
|
@@ -106,6 +123,10 @@ export function createClient(options: PolarisClientOptions): PolarisClient {
|
|
|
106
123
|
username: username(client),
|
|
107
124
|
anonymous: anonymous(client),
|
|
108
125
|
multiSession: multiSession(client),
|
|
126
|
+
social: social(client),
|
|
127
|
+
passkey: passkey(client),
|
|
128
|
+
apiKeys: apiKeys(client),
|
|
129
|
+
oauth: oauth(client),
|
|
109
130
|
withToken: (next: string | null) => createClient({ ...options, token: next }),
|
|
110
131
|
};
|
|
111
132
|
}
|
package/src/oauth.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* Generated by scripts/generate-namespaces.mjs from openapi.json; do not edit. */
|
|
2
|
+
import type { Client } from "openapi-fetch";
|
|
3
|
+
import type { paths } from "./schema.js";
|
|
4
|
+
import type { Init } from "./namespace.js";
|
|
5
|
+
|
|
6
|
+
/** The `oauth` plugin's routes as methods of `client.oauth`. */
|
|
7
|
+
export function oauth(client: Client<paths>) {
|
|
8
|
+
return {
|
|
9
|
+
/** POST /admin/oauth/clients: Register an OAuth client as an operator */
|
|
10
|
+
adminCreateClient: (...init: Init<"/admin/oauth/clients", "post">) => client.POST("/admin/oauth/clients", ...init),
|
|
11
|
+
/** DELETE /admin/oauth/clients/{id}: Delete an OAuth client as an operator */
|
|
12
|
+
adminDeleteClient: (...init: Init<"/admin/oauth/clients/{id}", "delete">) => client.DELETE("/admin/oauth/clients/{id}", ...init),
|
|
13
|
+
/** GET /admin/oauth/clients: List every OAuth client */
|
|
14
|
+
adminListClients: (...init: Init<"/admin/oauth/clients", "get">) => client.GET("/admin/oauth/clients", ...init),
|
|
15
|
+
/** GET /.well-known/oauth-authorization-server: Authorization server metadata */
|
|
16
|
+
authorizationServer: (...init: Init<"/.well-known/oauth-authorization-server", "get">) => client.GET("/.well-known/oauth-authorization-server", ...init),
|
|
17
|
+
/** GET /oauth2/authorize: Start an authorization (consent) request */
|
|
18
|
+
authorize: (...init: Init<"/oauth2/authorize", "get">) => client.GET("/oauth2/authorize", ...init),
|
|
19
|
+
/** POST /oauth2/ciba: Backchannel authentication request */
|
|
20
|
+
ciba: (...init: Init<"/oauth2/ciba", "post">) => client.POST("/oauth2/ciba", ...init),
|
|
21
|
+
/** POST /oauth2/ciba/{id}/decide: Approve or refuse a backchannel request */
|
|
22
|
+
cibaDecide: (...init: Init<"/oauth2/ciba/{id}/decide", "post">) => client.POST("/oauth2/ciba/{id}/decide", ...init),
|
|
23
|
+
/** GET /oauth2/ciba/pending: List pending backchannel requests */
|
|
24
|
+
cibaPending: (...init: Init<"/oauth2/ciba/pending", "get">) => client.GET("/oauth2/ciba/pending", ...init),
|
|
25
|
+
/** DELETE /oauth2/consents/{clientId}: Revoke a consent */
|
|
26
|
+
consentRevoke: (...init: Init<"/oauth2/consents/{clientId}", "delete">) => client.DELETE("/oauth2/consents/{clientId}", ...init),
|
|
27
|
+
/** GET /oauth2/consents: List your consents */
|
|
28
|
+
consentsList: (...init: Init<"/oauth2/consents", "get">) => client.GET("/oauth2/consents", ...init),
|
|
29
|
+
/** POST /orgs/{id}/oauth/clients: Register an OAuth client for the organization */
|
|
30
|
+
createClient: (...init: Init<"/orgs/{id}/oauth/clients", "post">) => client.POST("/orgs/{id}/oauth/clients", ...init),
|
|
31
|
+
/** POST /oauth2/authorize/decision: Approve or refuse an authorization request */
|
|
32
|
+
decision: (...init: Init<"/oauth2/authorize/decision", "post">) => client.POST("/oauth2/authorize/decision", ...init),
|
|
33
|
+
/** DELETE /orgs/{id}/oauth/clients/{clientId}: Delete an OAuth client of the organization */
|
|
34
|
+
deleteClient: (...init: Init<"/orgs/{id}/oauth/clients/{clientId}", "delete">) => client.DELETE("/orgs/{id}/oauth/clients/{clientId}", ...init),
|
|
35
|
+
/** POST /oauth2/device/approve: Approve or refuse a device */
|
|
36
|
+
deviceApprove: (...init: Init<"/oauth2/device/approve", "post">) => client.POST("/oauth2/device/approve", ...init),
|
|
37
|
+
/** POST /oauth2/device/code: Start the device flow */
|
|
38
|
+
deviceCode: (...init: Init<"/oauth2/device/code", "post">) => client.POST("/oauth2/device/code", ...init),
|
|
39
|
+
/** GET /oauth2/device/verify: Read the device behind a user code */
|
|
40
|
+
deviceVerify: (...init: Init<"/oauth2/device/verify", "get">) => client.GET("/oauth2/device/verify", ...init),
|
|
41
|
+
/** POST /oauth2/introspect: Introspect a token */
|
|
42
|
+
introspect: (...init: Init<"/oauth2/introspect", "post">) => client.POST("/oauth2/introspect", ...init),
|
|
43
|
+
/** GET /orgs/{id}/oauth/clients: List the organization's OAuth clients */
|
|
44
|
+
listClients: (...init: Init<"/orgs/{id}/oauth/clients", "get">) => client.GET("/orgs/{id}/oauth/clients", ...init),
|
|
45
|
+
/** GET /.well-known/openid-configuration: OpenID Connect Discovery */
|
|
46
|
+
openIdConfiguration: (...init: Init<"/.well-known/openid-configuration", "get">) => client.GET("/.well-known/openid-configuration", ...init),
|
|
47
|
+
/** GET /orgs/{id}/oauth/clients/{clientId}: Read an OAuth client of the organization */
|
|
48
|
+
readClient: (...init: Init<"/orgs/{id}/oauth/clients/{clientId}", "get">) => client.GET("/orgs/{id}/oauth/clients/{clientId}", ...init),
|
|
49
|
+
/** POST /oauth2/register: Register a client (RFC 7591) */
|
|
50
|
+
register: (...init: Init<"/oauth2/register", "post">) => client.POST("/oauth2/register", ...init),
|
|
51
|
+
/** POST /oauth2/revoke: Revoke a token */
|
|
52
|
+
revoke: (...init: Init<"/oauth2/revoke", "post">) => client.POST("/oauth2/revoke", ...init),
|
|
53
|
+
/** POST /oauth2/token: Issue tokens */
|
|
54
|
+
token: (...init: Init<"/oauth2/token", "post">) => client.POST("/oauth2/token", ...init),
|
|
55
|
+
/** PATCH /orgs/{id}/oauth/clients/{clientId}: Update an OAuth client of the organization */
|
|
56
|
+
updateClient: (...init: Init<"/orgs/{id}/oauth/clients/{clientId}", "patch">) => client.PATCH("/orgs/{id}/oauth/clients/{clientId}", ...init),
|
|
57
|
+
/** GET /oauth2/userinfo: The user's OpenID claims */
|
|
58
|
+
userinfo: (...init: Init<"/oauth2/userinfo", "get">) => client.GET("/oauth2/userinfo", ...init),
|
|
59
|
+
/** POST /oauth2/userinfo: The user's OpenID claims (POST) */
|
|
60
|
+
userinfoPost: (...init: Init<"/oauth2/userinfo", "post">) => client.POST("/oauth2/userinfo", ...init),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type OauthApi = ReturnType<typeof oauth>;
|
package/src/passkey.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* Generated by scripts/generate-namespaces.mjs from openapi.json; do not edit. */
|
|
2
|
+
import type { Client } from "openapi-fetch";
|
|
3
|
+
import type { paths } from "./schema.js";
|
|
4
|
+
import type { Init } from "./namespace.js";
|
|
5
|
+
|
|
6
|
+
/** The `passkey` plugin's routes as methods of `client.passkey`. */
|
|
7
|
+
export function passkey(client: Client<paths>) {
|
|
8
|
+
return {
|
|
9
|
+
/** POST /passkey/authenticate/options: Start a passkey sign-in */
|
|
10
|
+
authenticateOptions: (...init: Init<"/passkey/authenticate/options", "post">) => client.POST("/passkey/authenticate/options", ...init),
|
|
11
|
+
/** POST /passkey/authenticate/verify: Sign in with a passkey */
|
|
12
|
+
authenticateVerify: (...init: Init<"/passkey/authenticate/verify", "post">) => client.POST("/passkey/authenticate/verify", ...init),
|
|
13
|
+
/** DELETE /passkey/{id}: Remove a passkey */
|
|
14
|
+
delete: (...init: Init<"/passkey/{id}", "delete">) => client.DELETE("/passkey/{id}", ...init),
|
|
15
|
+
/** GET /passkey/list: List your passkeys */
|
|
16
|
+
list: (...init: Init<"/passkey/list", "get">) => client.GET("/passkey/list", ...init),
|
|
17
|
+
/** POST /passkey/register/options: Start registering a passkey */
|
|
18
|
+
registerOptions: (...init: Init<"/passkey/register/options", "post">) => client.POST("/passkey/register/options", ...init),
|
|
19
|
+
/** POST /passkey/register/verify: Finish registering a passkey */
|
|
20
|
+
registerVerify: (...init: Init<"/passkey/register/verify", "post">) => client.POST("/passkey/register/verify", ...init),
|
|
21
|
+
/** PATCH /passkey/{id}: Rename a passkey */
|
|
22
|
+
rename: (...init: Init<"/passkey/{id}", "patch">) => client.PATCH("/passkey/{id}", ...init),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type PasskeyApi = ReturnType<typeof passkey>;
|