File

src/issuer/authorize/authorize.controller.ts

Prefix

:tenantId/authorize

Description

Controller for the OpenID4VCI authorization endpoints. This controller handles the authorization requests, token requests.

Index

Methods

Methods

authorizationChallengeEndpoint
authorizationChallengeEndpoint(res: Response, body: AuthorizeQueries, tenantId: string)
Decorators :
@Post('challenge')

Endpoint for the authorization challenge.

Parameters :
Name Type Optional
res Response No
body AuthorizeQueries No
tenantId string No
Returns : any
Async authorize
authorize(queries: AuthorizeQueries, res: Response, tenantId: string)
Decorators :
@Get()

Endpoint to handle the Authorization Request.

Parameters :
Name Type Optional
queries AuthorizeQueries No
res Response No
tenantId string No
Returns : unknown
Async par
par(body: AuthorizeQueries, tenantId: string)
Decorators :
@ApiBody({description: 'Pushed Authorization Request', type: AuthorizeQueries})
@Post('par')

Endpoint to handle the Pushed Authorization Request (PAR).

Parameters :
Name Type Optional
body AuthorizeQueries No
tenantId string No
Async token
token(body: any, req: Request, tenantId: string)
Decorators :
@Post('token')

Endpoint to validate the token request. This endpoint is used to exchange the authorization code for an access token.

Parameters :
Name Type Optional
body any No
req Request No
tenantId string No
Returns : Promise<any>
import { randomUUID } from 'node:crypto';
import {
    Body,
    Controller,
    Get,
    Param,
    Post,
    Query,
    Req,
    Res,
} from '@nestjs/common';
import type { Request, Response } from 'express';
import { AuthorizeService } from './authorize.service';
import { AuthorizeQueries } from './dto/authorize-request.dto';
import { SessionService } from '../../session/session.service';
import { ParResponseDto } from './dto/par-response.dto';
import { ApiBody } from '@nestjs/swagger';

/**
 * Controller for the OpenID4VCI authorization endpoints.
 * This controller handles the authorization requests, token requests.
 */
@Controller(':tenantId/authorize')
export class AuthorizeController {
    constructor(
        private readonly authorizeService: AuthorizeService,
        private sessionService: SessionService,
    ) {}

    /**
     * Endpoint to handle the Authorization Request.
     * @param queries
     * @param res
     */
    @Get()
    async authorize(
        @Query() queries: AuthorizeQueries,
        @Res() res: Response,
        @Param('tenantId') tenantId: string,
    ) {
        return this.authorizeService.sendAuthorizationResponse(
            queries,
            res,
            tenantId,
        );
    }

    /**
     * Endpoint to handle the Pushed Authorization Request (PAR).
     * @param body
     * @returns
     */
    @ApiBody({
        description: 'Pushed Authorization Request',
        type: AuthorizeQueries,
    })
    @Post('par')
    async par(
        @Body() body: AuthorizeQueries,
        @Param('tenantId') tenantId: string,
    ): Promise<ParResponseDto> {
        const request_uri = `urn:${randomUUID()}`;
        // save both so we can retrieve the session also via the request_uri in the authorize step.
        await this.sessionService.add(body.issuer_state!, tenantId, {
            request_uri,
            auth_queries: body,
        });
        return {
            expires_in: 500,
            request_uri,
        };
    }

    /**
     * Endpoint to validate the token request.
     * This endpoint is used to exchange the authorization code for an access token.
     * @param body
     * @param req
     * @returns
     */
    @Post('token')
    async token(
        @Body() body: any,
        @Req() req: Request,
        @Param('tenantId') tenantId: string,
    ): Promise<any> {
        //TODO: define body
        return this.authorizeService.validateTokenRequest(body, req, tenantId);
    }

    /**
     * Endpoint for the authorization challenge.
     * @param res
     * @param body
     * @returns
     */
    @Post('challenge')
    authorizationChallengeEndpoint(
        @Res() res: Response,
        @Body() body: AuthorizeQueries,
        @Param('tenantId') tenantId: string,
    ) {
        return this.authorizeService.authorizationChallengeEndpoint(
            res,
            body,
            tenantId,
        );
    }
}

results matching ""

    No results matching ""