api_ianmenethil_combrowserChain.ts3 matches
24* Creates a complete browser-to-backend middleware chain per server.md specification.
25*
26* @returns {Array<(c: Context, next: Next) => unknown>} Array of middleware functions in execution order
27*/
28export function createBrowserMiddlewareChain(): Array<
29MiddlewareHandler<{ Variables: HonoVariables }>
30> {
54* @throws {Error} When middleware application fails
55*/
56export function applyBrowserMiddleware(
57app: Hono<{ Variables: HonoVariables }>,
58path: string = "/v1/*",
api_ianmenethil_combackendChains.ts2 matches
23* Creates a complete backend-to-backend middleware chain.
24*/
25export function createBackendMiddlewareChain(): Array<
26(c: Context, next: Next) => unknown
27> {
45* Applies backend middleware chain to a Hono application.
46*/
47export function applyBackendMiddleware(
48app: any, // Use any to avoid Hono type complexity
49path: string = "/v1/*",
api_ianmenethil_comauthSession.ts2 matches
21* Session-based authentication middleware (for orchestrator)
22*/
23export async function sessionAuthMiddleware(
24c: Context<{ Variables: HonoVariables }>,
25next: Next,
37* Session-based authentication logic.
38*/
39export function applySessionAuth(
40c: Context<{ Variables: HonoVariables }>,
41): AuthResult {
api_ianmenethil_comauthOauth.ts3 matches
17* OAuth authentication middleware
18*/
19export async function oauthAuthMiddleware(
20c: Context<{ Variables: Variables }>,
21next: () => Promise<void>,
38* OAuth authentication logic (checks session for OAuth data)
39*/
40export function applyOAuthAuth(
41c: Context<{ Variables: Variables }>,
42): AuthResult {
96* Generate OAuth authorization URL
97*/
98export function generateOAuthUrl(provider: string, state: string): string | null {
99const providerConfig =
100AUTH_CONFIG.oauth.providers[provider as keyof typeof AUTH_CONFIG.oauth.providers];
api_ianmenethil_comauthJWT.ts7 matches
17* Creates a JWT token with the provided payload
18*/
19export async function createJWT(payload: AppJwtPayload): Promise<string> {
20try {
21const { iat: _iat, exp: _exp, ...restPayload } = payload;
41* Verifies and decodes a JWT token
42*/
43export async function verifyAppJWT(
44token: string,
45customSecret?: string,
73* JWT authentication logic
74*/
75export async function applyJwtAuth(
76request: Request,
77customSecret?: string,
166* JWT Bearer token authentication middleware
167*/
168export async function jwtAuthMiddleware(
169c: Context<{ Variables: HonoVariables }>,
170next: Next,
197* JWT-only middleware for endpoints that strictly require JWT authentication
198*/
199export function jwtOnlyMiddleware(customSecret?: string) {
200return async (c: Context<{ Variables: HonoVariables }>, next: Next): Promise<Response | void> => {
201const authResult = await applyJwtAuth(c.req.raw, customSecret);
227* Creates a refresh token with extended expiry
228*/
229export async function createRefreshToken(payload: AppJwtPayload): Promise<string> {
230try {
231const { iat: _iat, exp: _exp, ...restPayload } = payload;
256* Validates a refresh token and returns new access token
257*/
258export async function refreshAccessToken(
259refreshTokenValue: string,
260): Promise<{ accessToken: string; refreshToken: string } | null> {
api_ianmenethil_comauthInternal.ts2 matches
5import { internalJwtService } from "@/services/internalJWTService.ts"; // Adjust path if necessary
67export function createInternalAuthMiddleware() {
8const internalJwtConfig = AUTH_CONFIG.jwt.INTERNAL;
9if (!internalJwtConfig.enabled) {
75}
7677export function requireInternalAuth(requiredScope?: string) {
78return async (c: Context<{ Variables: HonoVariables }>, next: Next): Promise<Response | void> => {
79const internalContext = c.get("internalAuth");
api_ianmenethil_comauthentication.ts11 matches
32* Apply authentication based on method
33*/
34async function applyAuthMethod(
35method: AuthMethod,
36c: Context<{ Variables: HonoVariables }>,
94* Multi-method authentication middleware
95*/
96export function createAuthMiddleware(options: AuthMiddlewareOptions = {}) {
97const defaultAuthTypes: AuthMethod[] = [
98AUTH_CONFIG.jwt.API.enabled && "jwt",
234235/**
236* Helper functions
237*/
238export function getAuthContext(c: Context<{ Variables: HonoVariables }>): AuthContext | undefined {
239return c.get("auth");
240}
241242export function isAuthenticated(c: Context<{ Variables: HonoVariables }>): boolean {
243return !!c.get("auth");
244}
245246export function getCurrentUserId(c: Context<{ Variables: HonoVariables }>): string | undefined {
247const auth = c.get("auth");
248return auth?.userId || auth?.user;
249}
250251export function getCurrentUserEmail(c: Context<{ Variables: HonoVariables }>): string | undefined {
252const auth = c.get("auth");
253return auth?.email;
254}
255256export function hasScope(c: Context<{ Variables: HonoVariables }>, scope: string): boolean {
257const auth = c.get("auth");
258return auth?.scopes?.includes(scope) || false;
259}
260261export function hasPermission(
262c: Context<{ Variables: HonoVariables }>,
263permission: string,
267}
268269export function getAuthMethod(c: Context<{ Variables: HonoVariables }>): AuthMethod | undefined {
270const auth = c.get("auth");
271return auth?.type;
273274/**
275* Shorthand functions for specific auth requirements
276*/
277export const requireJWT = createAuthMiddleware({ methods: ["jwt"] });
api_ianmenethil_comauthBasic.ts3 matches
50* Basic Auth authentication logic for the authentication orchestrator
51*/
52export async function applyBasicAuth(
53c: Context<{ Variables: HonoVariables }>,
54): Promise<AuthResult> {
171* Basic Auth authentication middleware for the orchestrator
172*/
173export async function basicAuthMiddleware(
174c: Context<{ Variables: HonoVariables }>,
175next: () => Promise<void>,
413414/**
415* Utility function to hash passwords using bcrypt
416*/
417export const hashPassword = async (password: string, saltRounds = 12): Promise<string> => {
api_ianmenethil_comauthApiKey.ts6 matches
15* Validates API key against configured valid keys
16*/
17export function validateApiKey(apiKey: string): boolean {
18if (!apiKey) return false;
1927* Validates internal API key for server-to-server communication
28*/
29export function validateInternalApiKey(apiKey: string): boolean {
30return apiKey === AUTH_CONFIG.methods.API_KEY.keys.internal;
31}
34* Validates webhook secret for webhook authentication
35*/
36export function validateWebhookSecret(secret: string): boolean {
37return secret === AUTH_CONFIG.methods.API_KEY.keys.webhook;
38}
41* Validates service-to-service API key
42*/
43export function validateServiceKey(serviceKey: string): boolean {
44return serviceKey === AUTH_CONFIG.methods.API_KEY.keys.serviceToService;
45}
48* API Key authentication middleware
49*/
50export async function apiKeyAuthMiddleware(
51c: Context<{ Variables: Variables }>,
52next: () => Promise<void>,
80* API Key authentication logic
81*/
82export function applyApiKeyAuth(request: Request): AuthResult {
83const apiKeyConfig = AUTH_CONFIG.methods.API_KEY;
84
api_ianmenethil_comauth.jwt.ts9 matches
1/**
2* JWT authentication middleware for Hono-based API server.
3* Provides JWT token creation, verification, and middleware functions.
4*/
521* @returns A string representation of the error message
22*/
23function getErrorMessage(error: unknown): string {
24if (error instanceof Error) {
25return error.message;
40* const token = await createJWT({ sub: 'user123', email: 'user@example.com' });
41*/
42export async function createJWT(payload: AppJwtPayload): Promise<string> {
43try {
44const { iat: _iat, exp: _exp, ...restPayload } = payload;
67* @returns Promise resolving to decoded payload or null if invalid
68*/
69export async function verifyAppJWT(
70token: string,
71customSecret?: string,
106* @returns Promise resolving to authentication result
107*/
108export async function applyJwtAuth(
109request: Request,
110customSecret?: string,
199* JWT Bearer token authentication middleware
200*/
201export async function jwtAuthMiddleware(
202c: Context<{ Variables: HonoVariables }>,
203next: Next,
230* JWT-only middleware for endpoints that strictly require JWT authentication
231*/
232export function jwtOnlyMiddleware(customSecret?: string) {
233return async (c: Context<{ Variables: HonoVariables }>, next: Next): Promise<Response | void> => {
234const authResult = await applyJwtAuth(c.req.raw, customSecret);
260* Creates a refresh token with extended expiry
261*/
262export async function createRefreshToken(payload: AppJwtPayload): Promise<string> {
263try {
264const { iat: _iat, exp: _exp, ...restPayload } = payload;
291* @returns Promise resolving to new token pair or null if invalid
292*/
293export async function refreshAccessToken(
294refreshTokenValue: string,
295): Promise<{ accessToken: string; refreshToken: string } | null> {