@authyon/server 0.1.5 → 0.2.0-beta.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 +84 -84
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
# @authyon/server
|
|
2
|
-
|
|
3
|
-
SDK server-side para o [Authyon](https://authyon.com) — administração de ambiente/tenants (OAuth client-credentials) e verificação de access token (publishable key). Nunca importe este pacote em código de browser.
|
|
4
|
-
|
|
5
|
-
## Instalação
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @authyon/server
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Chaves e credenciais
|
|
12
|
-
|
|
13
|
-
| Credencial | Uso |
|
|
14
|
-
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
-
| `envKey` (`pk_...`) | Selecionado em **toda** chamada via `X-Authyon-Environment` (Test/Live). Não é sensível — é a mesma chave do frontend, mas sozinha não autoriza nada. |
|
|
16
|
-
| `clientId` / `clientSecret` (ambiente) | Credenciais OAuth client-credentials de nível ambiente, mintadas no console. O SDK troca por um access token (`POST /env/oauth/token`) e o renova sozinho, usado em todo `environment.*` / `permissions.*`. **Nunca** exponha ao navegador. |
|
|
17
|
-
| `clientId` / `clientSecret` (tenant) | Credenciais por-tenant, usadas via `authyon.tenant({ clientId, clientSecret })` para as chamadas `TenantManagement` (`/tenant/...`). |
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { createClient } from "@authyon/server";
|
|
21
|
-
|
|
22
|
-
const authyon = createClient({
|
|
23
|
-
envKey: process.env.AUTHYON_ENV_KEY, // pk_live_...
|
|
24
|
-
clientId: process.env.AUTHYON_CLIENT_ID, // ec_live_...
|
|
25
|
-
clientSecret: process.env.AUTHYON_CLIENT_SECRET,
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
> `@authyon/auth` também exporta um `createClient`. Se algum dia precisar dos dois no mesmo arquivo, use um alias no import: `import { createClient as createServerClient } from "@authyon/server"`.
|
|
30
|
-
|
|
31
|
-
## Verificação de token
|
|
32
|
-
|
|
33
|
-
```ts
|
|
34
|
-
const { active, sub } = await authyon.introspect(token); // leve
|
|
35
|
-
const { user, organization } = await authyon.validate(token); // recomendado — cross-checa revogação
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Veja [`examples/token-verification.ts`](./examples/token-verification.ts) para um middleware completo.
|
|
39
|
-
|
|
40
|
-
## Administração de ambiente (`environment.*`)
|
|
41
|
-
|
|
42
|
-
Usa as credenciais de ambiente (`clientId`/`clientSecret`) automaticamente — o SDK minta e renova o token sozinho.
|
|
43
|
-
|
|
44
|
-
```ts
|
|
45
|
-
const org = await authyon.environment.tenants.create({ name: "Acme", slug: "acme" });
|
|
46
|
-
await authyon.environment.tenants.members.add(org.id, userId, ["owner"]);
|
|
47
|
-
await authyon.environment.tenants.members.assignRole(org.id, userId, "billing-admin");
|
|
48
|
-
await authyon.environment.tenants.members.remove(org.id, userId);
|
|
49
|
-
|
|
50
|
-
await authyon.environment.users.list({ search: "acme.com" });
|
|
51
|
-
await authyon.environment.roles.create({ name: "support", permissions: ["tickets:read"] });
|
|
52
|
-
await authyon.environment.audit.list({ take: 50 });
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Veja [`examples/organization-membership.ts`](./examples/organization-membership.ts) para o fluxo completo, incluindo as rotas de backend que o `@authyon/auth` chamaria.
|
|
56
|
-
|
|
57
|
-
Namespaces disponíveis: `environment.users`, `environment.tenants` (com `.members` e `.roles` aninhados), `environment.roles`, `environment.permissions`, `environment.audit`.
|
|
58
|
-
|
|
59
|
-
## Administração por tenant (`tenant()`)
|
|
60
|
-
|
|
61
|
-
As credenciais de um tenant são próprias dele — use `authyon.tenant(credentials)` para obter um cliente escopado, que minta e cacheia seu próprio token via `POST /tenant/oauth/token`:
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
const acme = authyon.tenant({ clientId: acmeClientId, clientSecret: acmeClientSecret });
|
|
65
|
-
|
|
66
|
-
await acme.members.list();
|
|
67
|
-
await acme.members.add(userId, ["member"]);
|
|
68
|
-
await acme.roles.create({ name: "viewer", permissions: ["reports:read"] });
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Descoberta
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
await authyon.discovery.jwks(); // GET /.well-known/jwks.json
|
|
75
|
-
await authyon.discovery.openidConfiguration(); // GET /.well-known/openid-configuration
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Build
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
npm install
|
|
82
|
-
npm run build # dist/ (ESM + CJS + .d.ts via tsup)
|
|
83
|
-
npm run typecheck
|
|
84
|
-
```
|
|
1
|
+
# @authyon/server
|
|
2
|
+
|
|
3
|
+
SDK server-side para o [Authyon](https://authyon.com) — administração de ambiente/tenants (OAuth client-credentials) e verificação de access token (publishable key). Nunca importe este pacote em código de browser.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @authyon/server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Chaves e credenciais
|
|
12
|
+
|
|
13
|
+
| Credencial | Uso |
|
|
14
|
+
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `envKey` (`pk_...`) | Selecionado em **toda** chamada via `X-Authyon-Environment` (Test/Live). Não é sensível — é a mesma chave do frontend, mas sozinha não autoriza nada. |
|
|
16
|
+
| `clientId` / `clientSecret` (ambiente) | Credenciais OAuth client-credentials de nível ambiente, mintadas no console. O SDK troca por um access token (`POST /env/oauth/token`) e o renova sozinho, usado em todo `environment.*` / `permissions.*`. **Nunca** exponha ao navegador. |
|
|
17
|
+
| `clientId` / `clientSecret` (tenant) | Credenciais por-tenant, usadas via `authyon.tenant({ clientId, clientSecret })` para as chamadas `TenantManagement` (`/tenant/...`). |
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createClient } from "@authyon/server";
|
|
21
|
+
|
|
22
|
+
const authyon = createClient({
|
|
23
|
+
envKey: process.env.AUTHYON_ENV_KEY, // pk_live_...
|
|
24
|
+
clientId: process.env.AUTHYON_CLIENT_ID, // ec_live_...
|
|
25
|
+
clientSecret: process.env.AUTHYON_CLIENT_SECRET,
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
> `@authyon/auth` também exporta um `createClient`. Se algum dia precisar dos dois no mesmo arquivo, use um alias no import: `import { createClient as createServerClient } from "@authyon/server"`.
|
|
30
|
+
|
|
31
|
+
## Verificação de token
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const { active, sub } = await authyon.introspect(token); // leve
|
|
35
|
+
const { user, organization } = await authyon.validate(token); // recomendado — cross-checa revogação
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Veja [`examples/token-verification.ts`](./examples/token-verification.ts) para um middleware completo.
|
|
39
|
+
|
|
40
|
+
## Administração de ambiente (`environment.*`)
|
|
41
|
+
|
|
42
|
+
Usa as credenciais de ambiente (`clientId`/`clientSecret`) automaticamente — o SDK minta e renova o token sozinho.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const org = await authyon.environment.tenants.create({ name: "Acme", slug: "acme" });
|
|
46
|
+
await authyon.environment.tenants.members.add(org.id, userId, ["owner"]);
|
|
47
|
+
await authyon.environment.tenants.members.assignRole(org.id, userId, "billing-admin");
|
|
48
|
+
await authyon.environment.tenants.members.remove(org.id, userId);
|
|
49
|
+
|
|
50
|
+
await authyon.environment.users.list({ search: "acme.com" });
|
|
51
|
+
await authyon.environment.roles.create({ name: "support", permissions: ["tickets:read"] });
|
|
52
|
+
await authyon.environment.audit.list({ take: 50 });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Veja [`examples/organization-membership.ts`](./examples/organization-membership.ts) para o fluxo completo, incluindo as rotas de backend que o `@authyon/auth` chamaria.
|
|
56
|
+
|
|
57
|
+
Namespaces disponíveis: `environment.users`, `environment.tenants` (com `.members` e `.roles` aninhados), `environment.roles`, `environment.permissions`, `environment.audit`.
|
|
58
|
+
|
|
59
|
+
## Administração por tenant (`tenant()`)
|
|
60
|
+
|
|
61
|
+
As credenciais de um tenant são próprias dele — use `authyon.tenant(credentials)` para obter um cliente escopado, que minta e cacheia seu próprio token via `POST /tenant/oauth/token`:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const acme = authyon.tenant({ clientId: acmeClientId, clientSecret: acmeClientSecret });
|
|
65
|
+
|
|
66
|
+
await acme.members.list();
|
|
67
|
+
await acme.members.add(userId, ["member"]);
|
|
68
|
+
await acme.roles.create({ name: "viewer", permissions: ["reports:read"] });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Descoberta
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
await authyon.discovery.jwks(); // GET /.well-known/jwks.json
|
|
75
|
+
await authyon.discovery.openidConfiguration(); // GET /.well-known/openid-configuration
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Build
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npm install
|
|
82
|
+
npm run build # dist/ (ESM + CJS + .d.ts via tsup)
|
|
83
|
+
npm run typecheck
|
|
84
|
+
```
|
package/package.json
CHANGED