From dee70987eb74eda4a9ab7332522fa5540cee9761 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 3 Sep 2024 22:55:44 +0200 Subject: [PATCH] fix: improve oidc error logging --- backend/src/oauth/provider/genericOidc.provider.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/oauth/provider/genericOidc.provider.ts b/backend/src/oauth/provider/genericOidc.provider.ts index e1f211d1..9c83bccd 100644 --- a/backend/src/oauth/provider/genericOidc.provider.ts +++ b/backend/src/oauth/provider/genericOidc.provider.ts @@ -1,13 +1,13 @@ -import { Logger } from "@nestjs/common"; -import { ConfigService } from "../../config/config.service"; +import { InternalServerErrorException, Logger } from "@nestjs/common"; import { JwtService } from "@nestjs/jwt"; import { Cache } from "cache-manager"; import * as jmespath from "jmespath"; import { nanoid } from "nanoid"; +import { ConfigService } from "../../config/config.service"; import { OAuthCallbackDto } from "../dto/oauthCallback.dto"; -import { OAuthProvider, OAuthToken } from "./oauthProvider.interface"; import { OAuthSignInDto } from "../dto/oauthSignIn.dto"; import { ErrorPageException } from "../exceptions/errorPage.exception"; +import { OAuthProvider, OAuthToken } from "./oauthProvider.interface"; export abstract class GenericOidcProvider implements OAuthProvider { protected discoveryUri: string; @@ -116,7 +116,13 @@ export abstract class GenericOidcProvider implements OAuthProvider { }, ): Promise { const idTokenData = this.decodeIdToken(token.idToken); - // maybe it's not necessary to verify the id token since it's directly obtained from the provider + + if (!idTokenData) { + this.logger.error( + `Can not get ID Token from response ${JSON.stringify(token.rawToken, undefined, 2)}`, + ); + throw new InternalServerErrorException(); + } const key = `oauth-${this.name}-nonce-${query.state}`; const nonce = await this.cache.get(key);