login
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Body, Controller, Get, Param, Post, Req, Res, UnauthorizedException } from '@nestjs/common';
|
import { Body, Controller, Get, Logger, Param, Post, Req, Res, UnauthorizedException } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import type { Interaction } from 'oidc-provider';
|
import type { Interaction } from 'oidc-provider';
|
||||||
@@ -9,6 +9,8 @@ import { OidcProviderService } from './oidc-provider.service';
|
|||||||
|
|
||||||
@Controller('interaction')
|
@Controller('interaction')
|
||||||
export class OidcInteractionController {
|
export class OidcInteractionController {
|
||||||
|
private readonly logger = new Logger(OidcInteractionController.name);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly oidc: OidcProviderService,
|
private readonly oidc: OidcProviderService,
|
||||||
private readonly config: ConfigService,
|
private readonly config: ConfigService,
|
||||||
@@ -22,7 +24,10 @@ export class OidcInteractionController {
|
|||||||
try {
|
try {
|
||||||
details = await this.oidc.interactionDetails(request, response);
|
details = await this.oidc.interactionDetails(request, response);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.logInteractionSessionError(error, uid, request);
|
this.logInteractionSessionError(error, uid, request).catch((logError) => {
|
||||||
|
const message = logError instanceof Error ? logError.message : String(logError);
|
||||||
|
this.logger.error(`OIDC interaction session logging failed: ${message}`);
|
||||||
|
});
|
||||||
response
|
response
|
||||||
.status(400)
|
.status(400)
|
||||||
.send(
|
.send(
|
||||||
@@ -217,6 +222,12 @@ export class OidcInteractionController {
|
|||||||
|
|
||||||
private async logInteractionSessionError(error: unknown, uid: string, request: Request): Promise<void> {
|
private async logInteractionSessionError(error: unknown, uid: string, request: Request): Promise<void> {
|
||||||
const cookieHeader = request.headers.cookie ?? '';
|
const cookieHeader = request.headers.cookie ?? '';
|
||||||
|
const hasCookieHeader = Boolean(cookieHeader);
|
||||||
|
const hasInteractionCookie = /(?:^|;\s*)_interaction=/.test(cookieHeader);
|
||||||
|
this.logger.warn(
|
||||||
|
`OIDC interaction session not found uid=${uid} hasCookieHeader=${hasCookieHeader} hasInteractionCookie=${hasInteractionCookie} host=${request.headers.host ?? ''} forwardedProto=${request.headers['x-forwarded-proto'] ?? ''}`,
|
||||||
|
);
|
||||||
|
|
||||||
await this.applicationErrorLogger.log({
|
await this.applicationErrorLogger.log({
|
||||||
error,
|
error,
|
||||||
category: ApplicationErrorCategory.OIDC,
|
category: ApplicationErrorCategory.OIDC,
|
||||||
@@ -232,8 +243,8 @@ export class OidcInteractionController {
|
|||||||
},
|
},
|
||||||
context: {
|
context: {
|
||||||
uid,
|
uid,
|
||||||
hasCookieHeader: Boolean(cookieHeader),
|
hasCookieHeader,
|
||||||
hasInteractionCookie: /(?:^|;\s*)_interaction=/.test(cookieHeader),
|
hasInteractionCookie,
|
||||||
forwardedProto: request.headers['x-forwarded-proto'],
|
forwardedProto: request.headers['x-forwarded-proto'],
|
||||||
forwardedHost: request.headers['x-forwarded-host'],
|
forwardedHost: request.headers['x-forwarded-host'],
|
||||||
host: request.headers.host,
|
host: request.headers.host,
|
||||||
|
|||||||
Reference in New Issue
Block a user