Afiq 379eb17246 Implement Authentik Integration and Simplify RBAC Structure
- Updated nuxt.config.js to include Authentik configuration and public keys for client-side access.
- Introduced a new composable, useAuth.js, for handling authentication logic with Authentik, including user validation, login, and logout functionalities.
- Enhanced documentation to reflect the simplified RBAC structure and the integration of Authentik, emphasizing user-centric design and streamlined permission management.
- Refactored middleware for authentication checks and improved error handling during user validation.
- Created new pages for login and dashboard, ensuring proper routing and user experience.
- Removed obsolete Metabase integration and unnecessary complexity from the project structure.
2025-05-31 19:15:21 +08:00

62 lines
1.9 KiB
JavaScript

import { authentikFetch, createAuthentikApplication, createAuthentikProvider, linkProviderToApplication } from '../../utils/authentik';
import { requireAuth } from '../../utils/auth';
// /api/applications - Handle GET and POST
export default defineEventHandler(async (event) => {
const method = getMethod(event);
// Require authentication for all application endpoints
await requireAuth(event);
switch (method) {
case 'GET':
try {
const applications = await authentikFetch('/core/applications/');
return applications;
} catch (error) {
throw createError({
statusCode: error.statusCode || 500,
message: error.message
});
}
case 'POST':
try {
const body = await readBody(event);
// Create application in Authentik
const application = await createAuthentikApplication({
name: body.name,
slug: body.slug || body.name.toLowerCase().replace(/\s+/g, '-'),
meta_description: body.description,
meta_publisher: 'CorradAF RBAC'
});
// Create OAuth2 provider if web application
if (body.type === 'web-app') {
const provider = await createAuthentikProvider({
name: `${body.name} OAuth2`,
client_type: 'confidential',
redirect_uris: body.redirectUris,
authorization_flow: body.authorizationFlow || 'default-authentication-flow'
});
// Link provider to application
await linkProviderToApplication(application.pk, provider.pk);
}
return application;
} catch (error) {
throw createError({
statusCode: error.statusCode || 500,
message: error.message
});
}
default:
throw createError({
statusCode: 405,
message: 'Method not allowed'
});
}
});