File

src/verifier/oid4vp/oid4vp.controller.ts

Prefix

:session/oid4vp

Description

Controller for handling OID4VP (OpenID for Verifiable Presentations) requests.

Index

Methods

Methods

getPostRequestWithSession
getPostRequestWithSession(sessionId: string, req: Request)
Decorators :
@Post('request')
@SessionLogger('session', 'OID4VP')

Returns the authorization request for a given requestId and session.

Parameters :
Name Type Optional
sessionId string No
req Request No
Returns : any
getRequestWithSession
getRequestWithSession(sessionId: string, req: Request)
Decorators :
@Get('request')
@SessionLogger('session', 'OID4VP')

Returns the authorization request for a given requestId and session.

Parameters :
Name Type Optional
sessionId string No
req Request No
Returns : any
getResponse
getResponse(body: AuthorizationResponse, sessionId: string)
Decorators :
@Post()
@HttpCode(HttpStatus.OK)
@SessionLogger('session', 'OID4VP')

Endpoint to receive the response from the wallet.

Parameters :
Name Type Optional
body AuthorizationResponse No
sessionId string No
Returns : any
import {
    Body,
    Controller,
    Get,
    HttpCode,
    HttpStatus,
    Param,
    Post,
    Req,
    UseInterceptors,
} from "@nestjs/common";
import { ApiExcludeController, ApiParam, ApiTags } from "@nestjs/swagger";
import { Request } from "express";
import { SessionLogger } from "../../shared/utils/logger/session-logger.decorator";
import { SessionLoggerInterceptor } from "../../shared/utils/logger/session-logger.interceptor";
import { AuthorizationResponse } from "./dto/authorization-response.dto";
import { Oid4vpService } from "./oid4vp.service";

/**
 * Controller for handling OID4VP (OpenID for Verifiable Presentations) requests.
 */
@ApiTags("OID4VP")
@Controller(":session/oid4vp")
@UseInterceptors(SessionLoggerInterceptor)
@ApiParam({ name: "session", required: true })
@ApiExcludeController(process.env.SWAGGER_ALL !== "true")
export class Oid4vpController {
    /**
     * Constructor for the Oid4vpController.
     * @param oid4vpService - Instance of Oid4vpService for handling OID4VP operations.
     */
    constructor(private readonly oid4vpService: Oid4vpService) {}

    /**
     * Returns the authorization request for a given requestId and session.
     * @param session
     * @param req
     * @returns
     */
    @Get("request")
    @SessionLogger("session", "OID4VP")
    getRequestWithSession(
        @Param("session") sessionId: string,
        @Req() req: Request,
    ) {
        const origin = req.get("origin") as string;
        return this.oid4vpService.createAuthorizationRequest(sessionId, origin);
    }

    /**
     * Returns the authorization request for a given requestId and session.
     * @param sessionId
     * @param req
     * @returns
     */
    @Post("request")
    @SessionLogger("session", "OID4VP")
    getPostRequestWithSession(
        @Param("session") sessionId: string,
        @Req() req: Request,
    ) {
        const origin = req.get("origin") as string;
        return this.oid4vpService.createAuthorizationRequest(sessionId, origin);
    }

    /**
     * Endpoint to receive the response from the wallet.
     * @param body
     * @returns
     */
    @Post()
    @HttpCode(HttpStatus.OK)
    @SessionLogger("session", "OID4VP")
    getResponse(
        @Body() body: AuthorizationResponse,
        @Param("session") sessionId: string,
    ) {
        return this.oid4vpService.getResponse(body, sessionId).catch((err) => {
            console.log("Error in OID4VP response handling:");
            console.error(err);
            throw err;
        });
    }
}

results matching ""

    No results matching ""