@dudousxd/adonis-authkit-server 0.1.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/LICENSE +21 -0
- package/README.md +137 -0
- package/build/assets/grafana/authkit-dashboard.json +118 -0
- package/build/commands/commands.json +30 -0
- package/build/commands/configure.d.ts +2 -0
- package/build/commands/configure.js +42 -0
- package/build/commands/eject.d.ts +11 -0
- package/build/commands/eject.js +96 -0
- package/build/commands/main.d.ts +12 -0
- package/build/commands/main.js +38 -0
- package/build/commands/ui_preset.d.ts +4 -0
- package/build/commands/ui_preset.js +32 -0
- package/build/database/migrations/make_authkit_oidc_table.d.ts +6 -0
- package/build/database/migrations/make_authkit_oidc_table.js +19 -0
- package/build/host/views/account/login.edge +29 -0
- package/build/host/views/account/mfa.edge +151 -0
- package/build/host/views/account/tokens.edge +70 -0
- package/build/host/views/admin/audit.edge +72 -0
- package/build/host/views/admin/clients.edge +51 -0
- package/build/host/views/admin/dashboard.edge +58 -0
- package/build/host/views/admin/users.edge +76 -0
- package/build/host/views/consent.edge +19 -0
- package/build/host/views/forgot.edge +30 -0
- package/build/host/views/login.edge +91 -0
- package/build/host/views/mfa-challenge.edge +88 -0
- package/build/host/views/reset.edge +29 -0
- package/build/host/views/signup.edge +44 -0
- package/build/host/views/verify-email.edge +16 -0
- package/build/index.d.ts +42 -0
- package/build/index.js +28 -0
- package/build/providers/authkit_server_provider.d.ts +19 -0
- package/build/providers/authkit_server_provider.js +81 -0
- package/build/src/accounts/account_store.d.ts +136 -0
- package/build/src/accounts/account_store.js +1 -0
- package/build/src/accounts/lucid_account_store.d.ts +75 -0
- package/build/src/accounts/lucid_account_store.js +396 -0
- package/build/src/adapters/adapter_contract.d.ts +18 -0
- package/build/src/adapters/adapter_contract.js +1 -0
- package/build/src/adapters/database_adapter.d.ts +15 -0
- package/build/src/adapters/database_adapter.js +63 -0
- package/build/src/adapters/factory.d.ts +30 -0
- package/build/src/adapters/factory.js +43 -0
- package/build/src/adapters/redis_adapter.d.ts +16 -0
- package/build/src/adapters/redis_adapter.js +95 -0
- package/build/src/audit/audit_sink.d.ts +54 -0
- package/build/src/audit/audit_sink.js +1 -0
- package/build/src/audit/lucid_audit_sink.d.ts +10 -0
- package/build/src/audit/lucid_audit_sink.js +60 -0
- package/build/src/controllers/oidc_callback_controller.d.ts +22 -0
- package/build/src/controllers/oidc_callback_controller.js +33 -0
- package/build/src/define_config.d.ts +261 -0
- package/build/src/define_config.js +115 -0
- package/build/src/host/account_lockout.d.ts +86 -0
- package/build/src/host/account_lockout.js +185 -0
- package/build/src/host/augmentations.d.ts +1 -0
- package/build/src/host/augmentations.js +1 -0
- package/build/src/host/branding.d.ts +17 -0
- package/build/src/host/branding.js +8 -0
- package/build/src/host/controllers/account_mfa_controller.d.ts +30 -0
- package/build/src/host/controllers/account_mfa_controller.js +157 -0
- package/build/src/host/controllers/account_session_controller.d.ts +7 -0
- package/build/src/host/controllers/account_session_controller.js +50 -0
- package/build/src/host/controllers/account_tokens_controller.d.ts +7 -0
- package/build/src/host/controllers/account_tokens_controller.js +55 -0
- package/build/src/host/controllers/admin/admin_audit_controller.d.ts +10 -0
- package/build/src/host/controllers/admin/admin_audit_controller.js +56 -0
- package/build/src/host/controllers/admin/admin_clients_controller.d.ts +10 -0
- package/build/src/host/controllers/admin/admin_clients_controller.js +24 -0
- package/build/src/host/controllers/admin/admin_dashboard_controller.d.ts +10 -0
- package/build/src/host/controllers/admin/admin_dashboard_controller.js +27 -0
- package/build/src/host/controllers/admin/admin_users_controller.d.ts +11 -0
- package/build/src/host/controllers/admin/admin_users_controller.js +53 -0
- package/build/src/host/controllers/interaction_controller.d.ts +44 -0
- package/build/src/host/controllers/interaction_controller.js +304 -0
- package/build/src/host/controllers/pat_introspection_controller.d.ts +22 -0
- package/build/src/host/controllers/pat_introspection_controller.js +46 -0
- package/build/src/host/controllers/registration_controller.d.ts +18 -0
- package/build/src/host/controllers/registration_controller.js +169 -0
- package/build/src/host/controllers/social_controller.d.ts +8 -0
- package/build/src/host/controllers/social_controller.js +82 -0
- package/build/src/host/default_mailer.d.ts +39 -0
- package/build/src/host/default_mailer.js +141 -0
- package/build/src/host/email_templates.d.ts +35 -0
- package/build/src/host/email_templates.js +66 -0
- package/build/src/host/i18n.d.ts +178 -0
- package/build/src/host/i18n.js +208 -0
- package/build/src/host/middleware/account_auth.d.ts +7 -0
- package/build/src/host/middleware/account_auth.js +11 -0
- package/build/src/host/rate_limit.d.ts +32 -0
- package/build/src/host/rate_limit.js +87 -0
- package/build/src/host/register_auth_host.d.ts +41 -0
- package/build/src/host/register_auth_host.js +133 -0
- package/build/src/host/renderers/edge_renderer.d.ts +3 -0
- package/build/src/host/renderers/edge_renderer.js +29 -0
- package/build/src/host/renderers/inertia_renderer.d.ts +5 -0
- package/build/src/host/renderers/inertia_renderer.js +26 -0
- package/build/src/host/validators.d.ts +39 -0
- package/build/src/host/validators.js +13 -0
- package/build/src/keys/jwks_manager.d.ts +6 -0
- package/build/src/keys/jwks_manager.js +11 -0
- package/build/src/mixins/with_audit_log.d.ts +19 -0
- package/build/src/mixins/with_audit_log.js +41 -0
- package/build/src/mixins/with_auth_user.d.ts +18 -0
- package/build/src/mixins/with_auth_user.js +39 -0
- package/build/src/mixins/with_credentials.d.ts +20 -0
- package/build/src/mixins/with_credentials.js +29 -0
- package/build/src/mixins/with_mfa.d.ts +31 -0
- package/build/src/mixins/with_mfa.js +39 -0
- package/build/src/mixins/with_personal_access_token.d.ts +19 -0
- package/build/src/mixins/with_personal_access_token.js +44 -0
- package/build/src/mixins/with_provider_identity.d.ts +20 -0
- package/build/src/mixins/with_provider_identity.js +32 -0
- package/build/src/mixins/with_webauthn_credential.d.ts +37 -0
- package/build/src/mixins/with_webauthn_credential.js +49 -0
- package/build/src/observability/metrics_controller.d.ts +5 -0
- package/build/src/observability/metrics_controller.js +24 -0
- package/build/src/observability/metrics_service.d.ts +2 -0
- package/build/src/observability/metrics_service.js +7 -0
- package/build/src/observability/otel_recorder.d.ts +10 -0
- package/build/src/observability/otel_recorder.js +59 -0
- package/build/src/observability/wire_provider_events.d.ts +12 -0
- package/build/src/observability/wire_provider_events.js +19 -0
- package/build/src/pat/lucid_pat_store.d.ts +6 -0
- package/build/src/pat/lucid_pat_store.js +62 -0
- package/build/src/pat/pat_store.d.ts +31 -0
- package/build/src/pat/pat_store.js +1 -0
- package/build/src/pat/pat_tokens.d.ts +4 -0
- package/build/src/pat/pat_tokens.js +9 -0
- package/build/src/provider/build_provider.d.ts +8 -0
- package/build/src/provider/build_provider.js +101 -0
- package/build/src/provider/interaction_actions.d.ts +21 -0
- package/build/src/provider/interaction_actions.js +32 -0
- package/build/src/provider/oidc_service.d.ts +17 -0
- package/build/src/provider/oidc_service.js +84 -0
- package/build/src/provider/token_exchange.d.ts +15 -0
- package/build/src/provider/token_exchange.js +72 -0
- package/build/src/register_routes.d.ts +16 -0
- package/build/src/register_routes.js +21 -0
- package/build/stubs/config/authkit.stub +29 -0
- package/build/stubs/main.d.ts +1 -0
- package/build/stubs/main.js +2 -0
- package/build/stubs/models/auth_user.stub +13 -0
- package/build/stubs/ui/edge/views/consent.edge +13 -0
- package/build/stubs/ui/edge/views/login.edge +19 -0
- package/build/stubs/ui/react/components/auth_shell.tsx +67 -0
- package/build/stubs/ui/react/pages/account/login.tsx +56 -0
- package/build/stubs/ui/react/pages/account/mfa.tsx +132 -0
- package/build/stubs/ui/react/pages/account/tokens.tsx +88 -0
- package/build/stubs/ui/react/pages/consent.tsx +39 -0
- package/build/stubs/ui/react/pages/forgot.tsx +44 -0
- package/build/stubs/ui/react/pages/login.tsx +171 -0
- package/build/stubs/ui/react/pages/mfa-challenge.tsx +72 -0
- package/build/stubs/ui/react/pages/reset.tsx +58 -0
- package/build/stubs/ui/react/pages/signup.tsx +78 -0
- package/build/stubs/ui/react/pages/verify-email.tsx +24 -0
- package/build/types.d.ts +7 -0
- package/build/types.js +1 -0
- package/package.json +108 -0
- package/stubs/config/authkit.stub +29 -0
- package/stubs/main.ts +2 -0
- package/stubs/models/auth_user.stub +13 -0
- package/stubs/ui/edge/views/consent.edge +13 -0
- package/stubs/ui/edge/views/login.edge +19 -0
- package/stubs/ui/react/components/auth_shell.tsx +67 -0
- package/stubs/ui/react/pages/account/login.tsx +56 -0
- package/stubs/ui/react/pages/account/mfa.tsx +132 -0
- package/stubs/ui/react/pages/account/tokens.tsx +88 -0
- package/stubs/ui/react/pages/consent.tsx +39 -0
- package/stubs/ui/react/pages/forgot.tsx +44 -0
- package/stubs/ui/react/pages/login.tsx +171 -0
- package/stubs/ui/react/pages/mfa-challenge.tsx +72 -0
- package/stubs/ui/react/pages/reset.tsx +58 -0
- package/stubs/ui/react/pages/signup.tsx +78 -0
- package/stubs/ui/react/pages/verify-email.tsx +24 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { errors } from 'oidc-provider';
|
|
2
|
+
const TOKEN_EXCHANGE = 'urn:ietf:params:oauth:grant-type:token-exchange';
|
|
3
|
+
const ACCESS_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:access_token';
|
|
4
|
+
export function registerTokenExchange(provider, deps) {
|
|
5
|
+
const adminRole = deps.adminRole ?? 'ADMIN';
|
|
6
|
+
const handler = async (ctx) => {
|
|
7
|
+
const { params, client } = ctx.oidc;
|
|
8
|
+
if (params.subject_token_type !== ACCESS_TOKEN_TYPE) {
|
|
9
|
+
throw new errors.InvalidRequest('unsupported subject_token_type');
|
|
10
|
+
}
|
|
11
|
+
if (!params.subject_token) {
|
|
12
|
+
throw new errors.InvalidRequest('subject_token is required');
|
|
13
|
+
}
|
|
14
|
+
const subjectAt = await provider.AccessToken.find(params.subject_token);
|
|
15
|
+
if (!subjectAt || subjectAt.isExpired) {
|
|
16
|
+
throw new errors.InvalidGrant('subject_token invalid or expired');
|
|
17
|
+
}
|
|
18
|
+
const actor = await deps.findAccount(subjectAt.accountId);
|
|
19
|
+
if (!actor || !(actor.globalRoles ?? []).includes(adminRole)) {
|
|
20
|
+
throw new errors.InvalidGrant('actor not permitted to impersonate');
|
|
21
|
+
}
|
|
22
|
+
const targetId = params.requested_subject;
|
|
23
|
+
if (!targetId) {
|
|
24
|
+
throw new errors.InvalidRequest('requested_subject is required');
|
|
25
|
+
}
|
|
26
|
+
const target = await deps.findAccount(targetId);
|
|
27
|
+
if (!target) {
|
|
28
|
+
throw new errors.InvalidGrant('requested_subject not found');
|
|
29
|
+
}
|
|
30
|
+
const scope = params.scope || 'openid profile email';
|
|
31
|
+
const at = new provider.AccessToken({ accountId: target.id, client, scope });
|
|
32
|
+
const accessToken = await at.save();
|
|
33
|
+
const idToken = new provider.IdToken({
|
|
34
|
+
sub: target.id,
|
|
35
|
+
email: target.email,
|
|
36
|
+
email_verified: true,
|
|
37
|
+
name: target.name,
|
|
38
|
+
[deps.globalRolesClaim]: target.globalRoles ?? [],
|
|
39
|
+
}, { ctx });
|
|
40
|
+
idToken.scope = scope;
|
|
41
|
+
idToken.set('act', { sub: actor.id });
|
|
42
|
+
const idTokenJwt = await idToken.issue({ use: 'idtoken' });
|
|
43
|
+
await deps.audit?.record({
|
|
44
|
+
type: 'impersonation',
|
|
45
|
+
actorId: actor.id,
|
|
46
|
+
accountId: target.id,
|
|
47
|
+
email: target.email ?? null,
|
|
48
|
+
clientId: client?.clientId ?? null,
|
|
49
|
+
ip: ctx.req?.socket?.remoteAddress ?? null,
|
|
50
|
+
metadata: { scope },
|
|
51
|
+
});
|
|
52
|
+
ctx.body = {
|
|
53
|
+
access_token: accessToken,
|
|
54
|
+
issued_token_type: ACCESS_TOKEN_TYPE,
|
|
55
|
+
token_type: at.tokenType ?? 'Bearer',
|
|
56
|
+
expires_in: at.expiration ?? 3600,
|
|
57
|
+
id_token: idTokenJwt,
|
|
58
|
+
scope,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
provider.registerGrantType(TOKEN_EXCHANGE, handler, [
|
|
62
|
+
'subject_token',
|
|
63
|
+
'subject_token_type',
|
|
64
|
+
'requested_subject',
|
|
65
|
+
'requested_token_type',
|
|
66
|
+
'scope',
|
|
67
|
+
'audience',
|
|
68
|
+
'resource',
|
|
69
|
+
'actor_token',
|
|
70
|
+
'actor_token_type',
|
|
71
|
+
], ['audience', 'resource']);
|
|
72
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Router } from '@adonisjs/core/http';
|
|
2
|
+
/**
|
|
3
|
+
* Registra a rota catch-all que delega ao handler do oidc-provider.
|
|
4
|
+
* O issuer do consumidor deve terminar em `mountPath` (default `/oidc`),
|
|
5
|
+
* pois o oidc-provider roteia internamente sob o issuer.
|
|
6
|
+
* Uso: registerOidcRoutes(router) no start/routes.ts do auth-service.
|
|
7
|
+
*
|
|
8
|
+
* Observabilidade (opt-in):
|
|
9
|
+
* - `metrics: true` monta `GET /authkit/metrics` (snapshot JSON).
|
|
10
|
+
* - `dashboard: true` monta `GET /authkit/dashboard` (HTML embutido).
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerOidcRoutes(router: Router, options?: {
|
|
13
|
+
mountPath?: string;
|
|
14
|
+
metrics?: boolean;
|
|
15
|
+
dashboard?: boolean;
|
|
16
|
+
}): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import OidcCallbackController from './controllers/oidc_callback_controller.js';
|
|
2
|
+
import MetricsController from './observability/metrics_controller.js';
|
|
3
|
+
/**
|
|
4
|
+
* Registra a rota catch-all que delega ao handler do oidc-provider.
|
|
5
|
+
* O issuer do consumidor deve terminar em `mountPath` (default `/oidc`),
|
|
6
|
+
* pois o oidc-provider roteia internamente sob o issuer.
|
|
7
|
+
* Uso: registerOidcRoutes(router) no start/routes.ts do auth-service.
|
|
8
|
+
*
|
|
9
|
+
* Observabilidade (opt-in):
|
|
10
|
+
* - `metrics: true` monta `GET /authkit/metrics` (snapshot JSON).
|
|
11
|
+
* - `dashboard: true` monta `GET /authkit/dashboard` (HTML embutido).
|
|
12
|
+
*/
|
|
13
|
+
export function registerOidcRoutes(router, options = {}) {
|
|
14
|
+
const mount = options.mountPath ?? '/oidc';
|
|
15
|
+
router.any(`${mount}/*`, [OidcCallbackController]).as('authkit.oidc.wildcard');
|
|
16
|
+
router.any(mount, [OidcCallbackController]).as('authkit.oidc.root');
|
|
17
|
+
if (options.metrics)
|
|
18
|
+
router.get('/authkit/metrics', [MetricsController, 'json']);
|
|
19
|
+
if (options.dashboard)
|
|
20
|
+
router.get('/authkit/dashboard', [MetricsController, 'dashboard']);
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.configPath('authkit.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
import env from '#start/env'
|
|
5
|
+
import AuthUser from '#models/auth_user'
|
|
6
|
+
import { defineConfig, adapters } from '@authkit/server'
|
|
7
|
+
|
|
8
|
+
const authServerConfig = defineConfig({
|
|
9
|
+
issuer: env.get('AUTHKIT_ISSUER'),
|
|
10
|
+
adapter: adapters.redis({ connection: 'main' }),
|
|
11
|
+
jwks: { source: 'managed', algorithm: 'RS256' },
|
|
12
|
+
clients: [
|
|
13
|
+
// registre seus clients OIDC aqui
|
|
14
|
+
],
|
|
15
|
+
ttl: { accessToken: '15m', refreshToken: '30d' },
|
|
16
|
+
globalRolesClaim: 'roles',
|
|
17
|
+
findAccount: async (sub) => {
|
|
18
|
+
const user = await AuthUser.find(sub)
|
|
19
|
+
if (!user) return null
|
|
20
|
+
return { id: user.id, email: user.email, globalRoles: user.globalRoles }
|
|
21
|
+
},
|
|
22
|
+
verifyCredentials: async (email, password) => {
|
|
23
|
+
const user = await AuthUser.query().where('email', email).first()
|
|
24
|
+
if (!user || !(await user.verifyPassword(password))) return null
|
|
25
|
+
return { id: user.id }
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
export default authServerConfig
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stubsRoot: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('app/models/auth_user.ts') })
|
|
3
|
+
}}}
|
|
4
|
+
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
|
5
|
+
import { compose } from '@adonisjs/core/helpers'
|
|
6
|
+
import { withAuthUser, withCredentials } from '@authkit/server'
|
|
7
|
+
|
|
8
|
+
export default class AuthUser extends compose(BaseModel, withAuthUser(), withCredentials()) {
|
|
9
|
+
static connection = 'auth'
|
|
10
|
+
|
|
11
|
+
@column({ isPrimary: true })
|
|
12
|
+
declare id: string
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/authkit/consent.edge') })
|
|
3
|
+
}}}
|
|
4
|
+
<!doctype html>
|
|
5
|
+
<html lang="pt-br"><head><meta charset="utf-8"><title>Autorizar</title>
|
|
6
|
+
<script src="https://cdn.tailwindcss.com"></script></head>
|
|
7
|
+
<body class="min-h-screen flex items-center justify-center bg-gray-50">
|
|
8
|
+
<form method="POST" action="/auth/interaction/{{ uid }}/consent" class="w-full max-w-sm bg-white p-6 rounded-lg shadow">
|
|
9
|
+
<h1 class="text-lg font-semibold mb-2">Autorizar acesso</h1>
|
|
10
|
+
<p class="text-sm text-gray-600 mb-4">O app <strong>{{ params.client_id }}</strong> quer acessar sua conta.</p>
|
|
11
|
+
<button class="w-full bg-black text-white rounded py-2">Autorizar</button>
|
|
12
|
+
</form>
|
|
13
|
+
</body></html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('resources/views/authkit/login.edge') })
|
|
3
|
+
}}}
|
|
4
|
+
<!doctype html>
|
|
5
|
+
<html lang="pt-br"><head><meta charset="utf-8"><title>Entrar</title>
|
|
6
|
+
<script src="https://cdn.tailwindcss.com"></script></head>
|
|
7
|
+
<body class="min-h-screen flex items-center justify-center bg-gray-50">
|
|
8
|
+
<form method="POST" action="/auth/interaction/{{ uid }}/login" class="w-full max-w-sm bg-white p-6 rounded-lg shadow">
|
|
9
|
+
<h1 class="text-lg font-semibold mb-4">Entrar</h1>
|
|
10
|
+
@if(error)
|
|
11
|
+
<p class="text-red-600 text-sm mb-3">{{ error }}</p>
|
|
12
|
+
@end
|
|
13
|
+
<label class="block text-sm mb-1">E-mail</label>
|
|
14
|
+
<input name="email" type="email" required class="w-full border rounded px-3 py-2 mb-3" />
|
|
15
|
+
<label class="block text-sm mb-1">Senha</label>
|
|
16
|
+
<input name="password" type="password" required class="w-full border rounded px-3 py-2 mb-4" />
|
|
17
|
+
<button class="w-full bg-black text-white rounded py-2">Entrar</button>
|
|
18
|
+
</form>
|
|
19
|
+
</body></html>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/components/auth_shell.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import type { ReactNode } from 'react'
|
|
5
|
+
|
|
6
|
+
export interface AuthBrand {
|
|
7
|
+
appName: string
|
|
8
|
+
accent: string
|
|
9
|
+
accentSoft?: string
|
|
10
|
+
company?: string
|
|
11
|
+
tagline?: string
|
|
12
|
+
audienceLabel?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const COMPANY_FALLBACK = 'educ(a)ção'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Layout de duas colunas para as telas de autenticacao do IdP.
|
|
19
|
+
* Painel esquerdo: marca (empresa guarda-chuva + produto). Painel direito: formulario.
|
|
20
|
+
*/
|
|
21
|
+
export default function AuthShell({
|
|
22
|
+
brand,
|
|
23
|
+
children,
|
|
24
|
+
}: {
|
|
25
|
+
brand?: AuthBrand
|
|
26
|
+
children: ReactNode
|
|
27
|
+
}) {
|
|
28
|
+
const accent = brand?.accent ?? '#111827'
|
|
29
|
+
const accentSoft = brand?.accentSoft ?? accent
|
|
30
|
+
const company = brand?.company ?? COMPANY_FALLBACK
|
|
31
|
+
const appName = brand?.appName ?? 'Sua conta'
|
|
32
|
+
const tagline = brand?.tagline ?? 'Acesso unificado'
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<div className="min-h-screen flex items-center justify-center bg-gray-100 p-4">
|
|
36
|
+
<div className="w-full max-w-4xl overflow-hidden rounded-2xl bg-white shadow-xl ring-1 ring-black/5 grid md:grid-cols-2">
|
|
37
|
+
{/* Painel da marca */}
|
|
38
|
+
<div
|
|
39
|
+
className="relative flex flex-col justify-between p-8 text-white md:p-10"
|
|
40
|
+
style={{ backgroundImage: `linear-gradient(135deg, ${accent} 0%, ${accentSoft} 100%)` }}
|
|
41
|
+
>
|
|
42
|
+
<div
|
|
43
|
+
className="text-xs font-semibold uppercase tracking-[0.2em] text-white/80"
|
|
44
|
+
aria-label="Empresa"
|
|
45
|
+
>
|
|
46
|
+
{company}
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<div className="mt-10 md:mt-0">
|
|
50
|
+
<h2 className="text-2xl font-bold leading-tight md:text-3xl">{appName}</h2>
|
|
51
|
+
<p className="mt-2 text-sm text-white/85">{tagline}</p>
|
|
52
|
+
{brand?.audienceLabel && (
|
|
53
|
+
<span className="mt-4 inline-block rounded-full bg-white/20 px-3 py-1 text-xs font-medium uppercase tracking-wide text-white ring-1 ring-white/30">
|
|
54
|
+
{brand.audienceLabel}
|
|
55
|
+
</span>
|
|
56
|
+
)}
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<div className="mt-10 text-xs text-white/60">© {company}</div>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
{/* Painel do formulario */}
|
|
63
|
+
<div className="p-8 md:p-10">{children}</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/authkit/account/login.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
interface Props {
|
|
5
|
+
csrfToken: string
|
|
6
|
+
error?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function AccountLogin({ csrfToken, error }: Props) {
|
|
10
|
+
return (
|
|
11
|
+
<div className="min-h-screen flex items-center justify-center bg-gray-100 p-4">
|
|
12
|
+
<form
|
|
13
|
+
method="POST"
|
|
14
|
+
action="/account/login"
|
|
15
|
+
className="w-full max-w-sm rounded-2xl bg-white p-8 shadow-xl ring-1 ring-black/5"
|
|
16
|
+
>
|
|
17
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
18
|
+
<div className="text-xs font-semibold uppercase tracking-[0.2em] text-gray-400">educ(a)ção</div>
|
|
19
|
+
<h1 className="mt-2 text-xl font-semibold text-gray-900">Minha conta</h1>
|
|
20
|
+
<p className="mt-1 text-sm text-gray-500">Gerencie seus tokens de acesso.</p>
|
|
21
|
+
|
|
22
|
+
{error && <p className="mt-4 text-sm text-red-600">{error}</p>}
|
|
23
|
+
|
|
24
|
+
<label htmlFor="email" className="mt-6 mb-1 block text-sm font-medium text-gray-700">
|
|
25
|
+
E-mail
|
|
26
|
+
</label>
|
|
27
|
+
<input
|
|
28
|
+
id="email"
|
|
29
|
+
name="email"
|
|
30
|
+
type="email"
|
|
31
|
+
required
|
|
32
|
+
autoFocus
|
|
33
|
+
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm outline-none focus:border-gray-900"
|
|
34
|
+
/>
|
|
35
|
+
|
|
36
|
+
<label htmlFor="password" className="mt-4 mb-1 block text-sm font-medium text-gray-700">
|
|
37
|
+
Senha
|
|
38
|
+
</label>
|
|
39
|
+
<input
|
|
40
|
+
id="password"
|
|
41
|
+
name="password"
|
|
42
|
+
type="password"
|
|
43
|
+
required
|
|
44
|
+
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm outline-none focus:border-gray-900"
|
|
45
|
+
/>
|
|
46
|
+
|
|
47
|
+
<button
|
|
48
|
+
type="submit"
|
|
49
|
+
className="mt-6 w-full rounded-lg bg-gray-900 py-2.5 text-sm font-semibold text-white transition hover:opacity-90"
|
|
50
|
+
>
|
|
51
|
+
Entrar
|
|
52
|
+
</button>
|
|
53
|
+
</form>
|
|
54
|
+
</div>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/authkit/account/mfa.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
interface Props {
|
|
5
|
+
csrfToken: string
|
|
6
|
+
enabled: boolean
|
|
7
|
+
enrolling?: boolean
|
|
8
|
+
secret?: string | null
|
|
9
|
+
qrDataUrl?: string | null
|
|
10
|
+
error?: string
|
|
11
|
+
recoveryCodes?: string[] | null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default function AccountMfa({
|
|
15
|
+
csrfToken,
|
|
16
|
+
enabled,
|
|
17
|
+
enrolling,
|
|
18
|
+
secret,
|
|
19
|
+
qrDataUrl,
|
|
20
|
+
error,
|
|
21
|
+
recoveryCodes,
|
|
22
|
+
}: Props) {
|
|
23
|
+
return (
|
|
24
|
+
<div className="min-h-screen bg-gray-100 p-4">
|
|
25
|
+
<div className="mx-auto max-w-2xl">
|
|
26
|
+
<div className="flex items-center justify-between py-6">
|
|
27
|
+
<div>
|
|
28
|
+
<div className="text-xs font-semibold uppercase tracking-[0.2em] text-gray-400">educ(a)ção</div>
|
|
29
|
+
<h1 className="text-xl font-semibold text-gray-900">Verificação em duas etapas</h1>
|
|
30
|
+
</div>
|
|
31
|
+
<form method="POST" action="/account/logout">
|
|
32
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
33
|
+
<button type="submit" className="text-sm text-gray-500 hover:underline">
|
|
34
|
+
Sair
|
|
35
|
+
</button>
|
|
36
|
+
</form>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
{error && <p className="mb-4 text-sm text-red-600">{error}</p>}
|
|
40
|
+
|
|
41
|
+
{recoveryCodes && recoveryCodes.length > 0 && (
|
|
42
|
+
<div className="mb-6 rounded-lg border border-emerald-300 bg-emerald-50 p-4">
|
|
43
|
+
<p className="text-sm font-medium text-emerald-900">
|
|
44
|
+
Guarde seus códigos de recuperação — eles não serão mostrados de novo:
|
|
45
|
+
</p>
|
|
46
|
+
<ul className="mt-3 grid grid-cols-2 gap-2">
|
|
47
|
+
{recoveryCodes.map((rc) => (
|
|
48
|
+
<li key={rc}>
|
|
49
|
+
<code className="block rounded bg-white px-3 py-2 text-sm text-emerald-800 ring-1 ring-emerald-200">
|
|
50
|
+
{rc}
|
|
51
|
+
</code>
|
|
52
|
+
</li>
|
|
53
|
+
))}
|
|
54
|
+
</ul>
|
|
55
|
+
</div>
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
{enrolling ? (
|
|
59
|
+
<div className="rounded-xl bg-white p-6 shadow-sm ring-1 ring-black/5">
|
|
60
|
+
<p className="text-sm text-gray-600">
|
|
61
|
+
Escaneie o QR code com seu app autenticador (Google Authenticator, 1Password, etc.).
|
|
62
|
+
</p>
|
|
63
|
+
{qrDataUrl && (
|
|
64
|
+
<img src={qrDataUrl} alt="QR code TOTP" className="mx-auto my-4 h-48 w-48" />
|
|
65
|
+
)}
|
|
66
|
+
{secret && (
|
|
67
|
+
<>
|
|
68
|
+
<p className="text-center text-xs text-gray-500">Ou informe manualmente:</p>
|
|
69
|
+
<code className="mx-auto mt-1 block w-fit break-all rounded bg-gray-100 px-3 py-2 text-sm text-gray-800">
|
|
70
|
+
{secret}
|
|
71
|
+
</code>
|
|
72
|
+
</>
|
|
73
|
+
)}
|
|
74
|
+
<form method="POST" action="/account/mfa/confirm" className="mt-6">
|
|
75
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
76
|
+
<label htmlFor="code" className="mb-1 block text-sm font-medium text-gray-700">
|
|
77
|
+
Código de confirmação
|
|
78
|
+
</label>
|
|
79
|
+
<input
|
|
80
|
+
id="code"
|
|
81
|
+
name="code"
|
|
82
|
+
inputMode="numeric"
|
|
83
|
+
pattern="[0-9]*"
|
|
84
|
+
maxLength={6}
|
|
85
|
+
autoFocus
|
|
86
|
+
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-center text-lg tracking-[0.4em] outline-none focus:border-gray-900"
|
|
87
|
+
/>
|
|
88
|
+
<button
|
|
89
|
+
type="submit"
|
|
90
|
+
className="mt-4 w-full rounded-lg bg-gray-900 py-2.5 text-sm font-semibold text-white"
|
|
91
|
+
>
|
|
92
|
+
Ativar verificação em duas etapas
|
|
93
|
+
</button>
|
|
94
|
+
</form>
|
|
95
|
+
</div>
|
|
96
|
+
) : enabled ? (
|
|
97
|
+
<div className="rounded-xl bg-white p-6 shadow-sm ring-1 ring-black/5">
|
|
98
|
+
<p className="text-sm text-gray-700">
|
|
99
|
+
A verificação em duas etapas está{' '}
|
|
100
|
+
<span className="font-semibold text-emerald-700">ativa</span> nesta conta.
|
|
101
|
+
</p>
|
|
102
|
+
<form method="POST" action="/account/mfa/disable" className="mt-4">
|
|
103
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
104
|
+
<button
|
|
105
|
+
type="submit"
|
|
106
|
+
className="rounded-lg border border-red-300 px-4 py-2 text-sm font-semibold text-red-600 hover:bg-red-50"
|
|
107
|
+
>
|
|
108
|
+
Desativar
|
|
109
|
+
</button>
|
|
110
|
+
</form>
|
|
111
|
+
</div>
|
|
112
|
+
) : (
|
|
113
|
+
<div className="rounded-xl bg-white p-6 shadow-sm ring-1 ring-black/5">
|
|
114
|
+
<p className="text-sm text-gray-700">
|
|
115
|
+
A verificação em duas etapas está desativada. Ative-a para proteger sua conta com um app
|
|
116
|
+
autenticador.
|
|
117
|
+
</p>
|
|
118
|
+
<form method="POST" action="/account/mfa/enroll" className="mt-4">
|
|
119
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
120
|
+
<button
|
|
121
|
+
type="submit"
|
|
122
|
+
className="rounded-lg bg-gray-900 px-4 py-2 text-sm font-semibold text-white"
|
|
123
|
+
>
|
|
124
|
+
Ativar verificação em duas etapas
|
|
125
|
+
</button>
|
|
126
|
+
</form>
|
|
127
|
+
</div>
|
|
128
|
+
)}
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/authkit/account/tokens.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
interface TokenRow {
|
|
5
|
+
id: string
|
|
6
|
+
name: string
|
|
7
|
+
scopes: string[]
|
|
8
|
+
audience: string | null
|
|
9
|
+
lastUsedAt: string | null
|
|
10
|
+
createdAt: string
|
|
11
|
+
}
|
|
12
|
+
interface Props {
|
|
13
|
+
csrfToken: string
|
|
14
|
+
createdToken: string | null
|
|
15
|
+
tokens: TokenRow[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function AccountTokens({ csrfToken, createdToken, tokens }: Props) {
|
|
19
|
+
return (
|
|
20
|
+
<div className="min-h-screen bg-gray-100 p-4">
|
|
21
|
+
<div className="mx-auto max-w-2xl">
|
|
22
|
+
<div className="flex items-center justify-between py-6">
|
|
23
|
+
<div>
|
|
24
|
+
<div className="text-xs font-semibold uppercase tracking-[0.2em] text-gray-400">educ(a)ção</div>
|
|
25
|
+
<h1 className="text-xl font-semibold text-gray-900">Tokens de acesso</h1>
|
|
26
|
+
</div>
|
|
27
|
+
<form method="POST" action="/account/logout">
|
|
28
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
29
|
+
<button type="submit" className="text-sm text-gray-500 hover:underline">
|
|
30
|
+
Sair
|
|
31
|
+
</button>
|
|
32
|
+
</form>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
{createdToken && (
|
|
36
|
+
<div className="mb-6 rounded-lg border border-emerald-300 bg-emerald-50 p-4">
|
|
37
|
+
<p className="text-sm font-medium text-emerald-900">
|
|
38
|
+
Token criado — copie agora, não será mostrado de novo:
|
|
39
|
+
</p>
|
|
40
|
+
<code className="mt-2 block break-all rounded bg-white px-3 py-2 text-sm text-emerald-800 ring-1 ring-emerald-200">
|
|
41
|
+
{createdToken}
|
|
42
|
+
</code>
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
|
|
46
|
+
<form
|
|
47
|
+
method="POST"
|
|
48
|
+
action="/account/tokens"
|
|
49
|
+
className="mb-6 flex gap-2 rounded-xl bg-white p-4 shadow-sm ring-1 ring-black/5"
|
|
50
|
+
>
|
|
51
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
52
|
+
<input
|
|
53
|
+
name="name"
|
|
54
|
+
placeholder="Nome do token (ex.: CI deploy)"
|
|
55
|
+
className="flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm outline-none focus:border-gray-900"
|
|
56
|
+
/>
|
|
57
|
+
<button type="submit" className="rounded-lg bg-gray-900 px-4 text-sm font-semibold text-white">
|
|
58
|
+
Criar
|
|
59
|
+
</button>
|
|
60
|
+
</form>
|
|
61
|
+
|
|
62
|
+
<div className="overflow-hidden rounded-xl bg-white shadow-sm ring-1 ring-black/5">
|
|
63
|
+
{tokens.length === 0 ? (
|
|
64
|
+
<p className="p-6 text-sm text-gray-500">Nenhum token ainda.</p>
|
|
65
|
+
) : (
|
|
66
|
+
tokens.map((t) => (
|
|
67
|
+
<div key={t.id} className="flex items-center justify-between border-b border-gray-100 p-4 last:border-0">
|
|
68
|
+
<div>
|
|
69
|
+
<p className="text-sm font-medium text-gray-900">{t.name}</p>
|
|
70
|
+
<p className="text-xs text-gray-500">
|
|
71
|
+
Criado em {new Date(t.createdAt).toLocaleDateString('pt-BR')}
|
|
72
|
+
{t.lastUsedAt ? ` · último uso ${new Date(t.lastUsedAt).toLocaleDateString('pt-BR')}` : ' · nunca usado'}
|
|
73
|
+
</p>
|
|
74
|
+
</div>
|
|
75
|
+
<form method="POST" action={`/account/tokens/${t.id}/revoke`}>
|
|
76
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
77
|
+
<button type="submit" className="text-sm text-red-600 hover:underline">
|
|
78
|
+
Revogar
|
|
79
|
+
</button>
|
|
80
|
+
</form>
|
|
81
|
+
</div>
|
|
82
|
+
))
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/authkit/consent.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import AuthShell, { type AuthBrand } from '../../components/auth_shell'
|
|
5
|
+
|
|
6
|
+
export default function AuthkitConsent({
|
|
7
|
+
uid,
|
|
8
|
+
params,
|
|
9
|
+
csrfToken,
|
|
10
|
+
brand,
|
|
11
|
+
}: {
|
|
12
|
+
uid: string
|
|
13
|
+
params: { client_id: string }
|
|
14
|
+
csrfToken: string
|
|
15
|
+
brand?: AuthBrand
|
|
16
|
+
}) {
|
|
17
|
+
const accent = brand?.accent ?? '#111827'
|
|
18
|
+
const appName = brand?.appName ?? params.client_id
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<AuthShell brand={brand}>
|
|
22
|
+
<form method="POST" action={'/auth/interaction/' + uid + '/consent'}>
|
|
23
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
24
|
+
<h1 className="text-xl font-semibold text-gray-900">Autorizar acesso</h1>
|
|
25
|
+
<p className="mt-2 text-sm text-gray-600">
|
|
26
|
+
O app <strong>{appName}</strong> quer acessar sua conta.
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<button
|
|
30
|
+
type="submit"
|
|
31
|
+
className="mt-6 w-full rounded-lg py-2.5 text-sm font-semibold text-white transition hover:opacity-90"
|
|
32
|
+
style={{ backgroundColor: accent }}
|
|
33
|
+
>
|
|
34
|
+
Autorizar
|
|
35
|
+
</button>
|
|
36
|
+
</form>
|
|
37
|
+
</AuthShell>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({ to: app.makePath('inertia/pages/authkit/forgot.tsx') })
|
|
3
|
+
}}}
|
|
4
|
+
import AuthShell from '../../components/auth_shell'
|
|
5
|
+
|
|
6
|
+
const inputClass =
|
|
7
|
+
'w-full rounded-lg border border-gray-300 px-3 py-2 text-sm outline-none transition focus:border-transparent focus:ring-2 focus:ring-gray-800'
|
|
8
|
+
|
|
9
|
+
export default function AuthkitForgot({ csrfToken, sent }: { csrfToken: string; sent?: boolean }) {
|
|
10
|
+
if (sent) {
|
|
11
|
+
return (
|
|
12
|
+
<AuthShell>
|
|
13
|
+
<h1 className="text-xl font-semibold text-gray-900">E-mail enviado</h1>
|
|
14
|
+
<p className="mt-2 text-sm text-gray-600">
|
|
15
|
+
Se o e-mail existir, enviaremos instruções de redefinição.
|
|
16
|
+
</p>
|
|
17
|
+
</AuthShell>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<AuthShell>
|
|
23
|
+
<form method="POST" action="/auth/forgot-password">
|
|
24
|
+
<input type="hidden" name="_csrf" value={csrfToken} />
|
|
25
|
+
<h1 className="text-xl font-semibold text-gray-900">Recuperar senha</h1>
|
|
26
|
+
<p className="mt-1 text-sm text-gray-500">Enviaremos um link para redefinir sua senha.</p>
|
|
27
|
+
|
|
28
|
+
<div className="mt-6">
|
|
29
|
+
<label htmlFor="email" className="mb-1 block text-sm font-medium text-gray-700">
|
|
30
|
+
E-mail
|
|
31
|
+
</label>
|
|
32
|
+
<input id="email" name="email" type="email" required className={inputClass} />
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<button
|
|
36
|
+
type="submit"
|
|
37
|
+
className="mt-6 w-full rounded-lg bg-gray-900 py-2.5 text-sm font-semibold text-white transition hover:opacity-90"
|
|
38
|
+
>
|
|
39
|
+
Enviar link
|
|
40
|
+
</button>
|
|
41
|
+
</form>
|
|
42
|
+
</AuthShell>
|
|
43
|
+
)
|
|
44
|
+
}
|