Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/ffdc 3331 region specific redirect uri #317

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a059f9c
remove global logger, add logs to login flow, error logs, one omslogg…
Aug 12, 2024
13d949a
server instance id as injection token, injecting generic logger class
Aug 12, 2024
b8329d4
server instance id injection token, dynamic module configuration
Aug 13, 2024
0ac8e73
tests, console.log logger method
Aug 13, 2024
f384b39
oidc module test
Aug 13, 2024
48e8d6c
remove req.body and req.headers logging, http exception filer name, i…
Aug 21, 2024
ebab114
remove instance id from oidc module, remove logging of res.body
Aug 22, 2024
66f3114
instance id passed trough config service
Sep 10, 2024
3e93ee2
fix tests
Sep 10, 2024
69f61d4
session logging, restore httpexceptionfilter, added logging to differ…
Sep 18, 2024
7c73c9b
remove req.session from log
Sep 30, 2024
92a2693
region specific redirect uri, logging
Oct 1, 2024
332e3ab
Merge branch 'develop' into bugfix/FFDC-3331-region-specific-redirect…
Oct 2, 2024
d6e5e47
update package.lock
Oct 2, 2024
3f01c98
remove fallback method for wrong region, log method object parameter,…
Oct 3, 2024
dd8f6b5
restore redirect_uri setup logic
Oct 4, 2024
7f0ed8e
login callback separate logic, session log in exception filter, manua…
Oct 22, 2024
a05d794
redirect to main dns with query from /login/callback
Oct 23, 2024
134afb5
redirect to main dns
Oct 24, 2024
2dbf428
remove sessionKey, disable redirect from regional url
Nov 6, 2024
a6e5426
set cookie domain, oidc session key, logging
Nov 15, 2024
9b226a6
test fix, remove most logs
Dec 2, 2024
6a518fb
update package-lock.json
Dec 3, 2024
611d535
fix main.ts for app build
Dec 5, 2024
e15cec7
update oidc package-lock
Dec 9, 2024
002cdac
rise github actions node version
Dec 10, 2024
cbaa903
fix for oidc module test undefined env variable
Dec 10, 2024
7242ba5
tests fix, rename private filds for tests
Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove req.body and req.headers logging, http exception filer name, i…
…nstance id for oidc
  • Loading branch information
SebastianW committed Aug 21, 2024
commit 48e8d6c9e9346be70cc4db11b080c5602fc8ee4e
7 changes: 4 additions & 3 deletions libs/oidc/src/filters/http-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import { SSRPagesService } from '../services';
export class HttpExceptionFilter implements ExceptionFilter {
readonly logger = new Logger(HttpExceptionFilter.name);

constructor(private ssrPagesService: SSRPagesService) {}
constructor(private ssrPagesService: SSRPagesService) { }

catch(exception: any, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest();
const status = exception instanceof HttpException ? exception.getStatus() : HttpStatus.INTERNAL_SERVER_ERROR;

const { body, headers, method, params, query, url, user } = request;
const { method, params, query, url, user } = request;

this.logger.error({ request: { body, headers, method, params, query, url, user }, exception });
// this.logger.error({ request: { method, params, query, url, user }, exception });
this.logger.error(`${{ 'HttpExceptionFilter': method, params, query, url, user, exception }}`);

switch (status) {
case MisdirectedStatus.MISDIRECTED:
Expand Down
2 changes: 1 addition & 1 deletion libs/oidc/src/oidc.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('OidcModule', () => {
IssuerMock.keystore = jest.fn();
jest.spyOn(Issuer, 'discover').mockImplementation(() => Promise.resolve(IssuerMock));
module = await Test.createTestingModule({
imports: [OidcModule.forRoot(MOCK_OIDC_MODULE_OPTIONS)],
imports: [OidcModule.forRoot(MOCK_OIDC_MODULE_OPTIONS, randomUUID())],
}).compile();
});

Expand Down
4 changes: 3 additions & 1 deletion libs/oidc/src/oidc.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SERVER_INSTANCE_ID } from '@finastra/nestjs-logger';
import { DynamicModule, Global, MiddlewareConsumer, Module, NestModule, Provider, RequestMethod } from '@nestjs/common';
import { APP_FILTER, APP_GUARD } from '@nestjs/core';
import { JwtModule } from '@nestjs/jwt';
Expand Down Expand Up @@ -58,7 +59,7 @@ export class OidcModule implements NestModule {
);
}

static forRoot(options: OidcModuleOptions): DynamicModule {
static forRoot(options: OidcModuleOptions, serverInstanceID: string): DynamicModule {
options = mergeDefaults(options);
return {
module: OidcModule,
Expand All @@ -67,6 +68,7 @@ export class OidcModule implements NestModule {
provide: OIDC_MODULE_OPTIONS,
useValue: options,
},
{ provide: SERVER_INSTANCE_ID, useValue: serverInstanceID }
],
};
}
Expand Down
15 changes: 8 additions & 7 deletions libs/oidc/src/services/oidc.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SERVER_INSTANCE_ID } from '@finastra/nestjs-logger';
import { HttpStatus, Inject, Injectable, Logger, Next, OnModuleInit, Param, Req, Res } from '@nestjs/common';
import axios from 'axios';
import { Request, Response } from 'express';
Expand Down Expand Up @@ -36,7 +37,7 @@ export class OidcService implements OnModuleInit {

constructor(
@Inject(OIDC_MODULE_OPTIONS) public options: OidcModuleOptions,
@Inject('SERVER_INSTANCE_ID') private serverInstanceID: string,
@Inject(SERVER_INSTANCE_ID) private serverInstanceID: string,
private ssrPagesService: SSRPagesService,
) {
this.isMultitenant = !!this.options.issuerOrigin;
Expand Down Expand Up @@ -94,14 +95,14 @@ export class OidcService implements OnModuleInit {
} catch (err) {
if (this.isMultitenant) {
const errorMsg = JSON.stringify({
error: err.message,
error: err?.message,
debug: {
origin: this.options.origin,
tenantId,
channelType,
},
});
this.logger.error(err.message, err.stack, errorMsg);
this.logger.error(err?.message, err?.stack, errorMsg);
throw new Error();
}
const docUrl = 'https://github.com/finastra/finastra-nodejs-libs/blob/develop/libs/oidc/README.md';
Expand All @@ -125,7 +126,7 @@ export class OidcService implements OnModuleInit {
}

async login(@Req() req: Request, @Res() res: Response, @Next() next: Function, @Param() params) {
this.logger.log(`url: ${req.url}, body: ${JSON.stringify(req.body)}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}`);
this.logger.log(`url: ${req.url}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}`);
try {
const tenantId = params.tenantId || req.session['tenant'];
const channel = this.options.channelType || params.channelType || req.session['channel'];
Expand Down Expand Up @@ -174,12 +175,12 @@ export class OidcService implements OnModuleInit {
},
(err, user, info) => {
if (err || !user) {
this.logger.error(`url: ${req.url}, body: ${JSON.stringify(req.body)}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}, message: ${err.message}`);
this.logger.error(`url: ${req.url}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}, error message: ${err?.message}`);
return next(err || info);
}
req.logIn(user, err => {
if (err) {
this.logger.error(`url: ${req.url}, body: ${JSON.stringify(req.body)}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}, message: ${err.message}`);
this.logger.error(`url: ${req.url}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}, error message: ${err?.message}`);
return next(err);
}
this.updateSessionDuration(req);
Expand All @@ -203,7 +204,7 @@ export class OidcService implements OnModuleInit {
)(req, res, next);
}
} catch (err) {
this.logger.error(`url: ${req.url}, body: ${JSON.stringify(req.body)}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}, message: ${err.message}`);
this.logger.error(`url: ${req.url}, session: ${JSON.stringify(req.session)}, ip: ${req.ip}, method: ${req.method}, instanceID: ${this.serverInstanceID}, message: ${err.message}`);
res.status(HttpStatus.NOT_FOUND).send();
}
}
Expand Down