import type { HttpContext } from '@adonisjs/core/http';
import type { ApplicationService } from '@adonisjs/core/types';
/**
 * Bridges an MCP sign-in (an authkit access token the dev endpoint verified) into the request, so a
 * console `authorize(ctx)` sees the signed-in account exactly as it would on a browser request:
 * `getAuthkit(ctx)` / `ctx.authkit` answers `check()`, `getIdentity()`, `hasGlobalRole()` and
 * `getUser()`, and an `authkitClientGuard` default guard authenticates `ctx.auth` from it.
 *
 * Also binds the account as this request's bearer caller on `authkit.server` (its
 * `bindBearerAccount`, when the installed authkit-server has it), so an `authorize` written with
 * authkit-server's `getAccountId(ctx)` / `realAccountId(ctx)` sees the account too.
 *
 * Both peers are optional: `@adonis-agora/authkit-client` is imported lazily (its
 * `bindAuthkitIdentity` / `identityFromClaims`, the same helpers an app uses for a remote authkit),
 * and `@adonis-agora/authkit-server` is only read through the container. Without authkit-client a
 * minimal authenticator stands in.
 */
/** The authkit `Identity` shape (from `@adonis-agora/authkit-core`), re-declared. */
export interface BridgedIdentity {
    userId: string;
    email: string;
    globalRoles: string[];
    profile?: {
        name?: string;
        avatarUrl?: string;
    };
    orgId?: string | null;
    orgSlug?: string | null;
    orgRole?: string | null;
    sessionId?: string;
    /** The real actor of an impersonation (`act` claim). */
    actor?: {
        sub: string;
        email?: string;
    };
    issuedAt: number;
    expiresAt: number;
    raw: Record<string, unknown>;
}
/** What the dev endpoint knows about a verified authkit token. */
export interface VerifiedAuthkitToken {
    accountId: string;
    clientId: string | undefined;
    scopes: string[];
    /** Seconds since the epoch. */
    expiresAt?: number;
}
/**
 * Build the account's {@link BridgedIdentity} from the authkit server in this process: its email,
 * profile and global roles (through the app's `resolveTokenRoles` when set). No organization is
 * bridged: a token carries no verified active org. `null` when the account no longer exists.
 */
export declare function identityForToken(app: ApplicationService, token: VerifiedAuthkitToken): Promise<BridgedIdentity | null>;
/**
 * Put `identity` on the request the way a browser session would be:
 *
 * 1. `ctx.authkit` becomes an authkit `Authenticator` resolving to it — built by the app's own
 *    authkit client (so `resolveUser`, e.g. `lucidMirror`, gives `getUser()` the app's user), or a
 *    minimal one when the app has no authkit client.
 * 2. `authkit.server`'s `bindBearerAccount(ctx, accountId)` (optional, newer authkit-server) records
 *    the account for `getAccountId(ctx)`, `realAccountId(ctx)` and `impersonationState(ctx)` (not
 *    impersonating).
 * 3. When `ctx.auth`'s default guard is `authkitClientGuard`, it is (re)authenticated from that, so
 *    `ctx.auth.user` and `ctx.auth.check()` see the account too — even after a silent-auth middleware
 *    already found no browser session on this request.
 *
 * Best effort past step 1: a guard that fails leaves `ctx.auth` as it was.
 */
export declare function bridgeIdentity(app: ApplicationService, ctx: HttpContext, identity: BridgedIdentity): Promise<void>;
/** The parts of `@adonis-agora/authkit-client` the bridge uses (>= 1.0.0-rc.7). */
interface AuthkitClientModule {
    bindAuthkitIdentity(ctx: HttpContext, identity: never): Promise<void>;
    identityFromClaims(claims: Record<string, unknown>, globalRolesClaim?: string): BridgedIdentity;
    Authenticator: new (ctx: HttpContext, deps: {
        resolver: {
            resolve(): Promise<unknown>;
        };
    }) => unknown;
}
/** `@adonis-agora/authkit-client`, when the app has it (with the identity bridge); else `null`. */
export declare function loadAuthkitClient(): Promise<AuthkitClientModule | null>;
/** When a verified JWT is put on the request as an authkit identity. */
export interface BridgeClaimsOptions {
    /** `true`: always; `false`: never; `undefined`: when `@adonis-agora/authkit-client` is installed. */
    mode?: boolean | undefined;
    /** The claim holding the global roles. Default `'roles'`. */
    globalRolesClaim?: string | undefined;
}
/**
 * Put the claims of a JWT access token verified remotely (`jwtAuth`, `oidcAuth`) on the request as
 * an authkit identity, the way authkit-client's `bridgeAuthkitToken` does, without verifying it a
 * second time. A `client_credentials` token (`sub` = `client_id`) has no user and is not bridged.
 *
 * A token without an `email` claim (authkit's access tokens carry none today) is bound to
 * `ctx.authkit` only: the app's `resolveUser` (e.g. `lucidMirror`, which syncs the email) is not run
 * and `ctx.auth` is left alone, so a mirrored user is never overwritten with an empty email.
 * Returns whether an identity was bound.
 */
export declare function bridgeAuthkitClaims(ctx: HttpContext | undefined, claims: Record<string, unknown>, options?: BridgeClaimsOptions): Promise<boolean>;
export {};
//# sourceMappingURL=authkit-bridge.d.ts.map