Browse Source

Remove logging

pull/6075/head
Germán Martín 2 weeks ago
parent
commit
ac2836bd26
  1. 23
      apps/api/src/app/auth/auth.controller.ts
  2. 35
      apps/api/src/app/auth/auth.service.ts
  3. 33
      apps/api/src/app/auth/oidc-state.store.ts
  4. 10
      apps/api/src/app/auth/oidc.strategy.ts

23
apps/api/src/app/auth/auth.controller.ts

@ -16,7 +16,6 @@ import {
Logger,
Param,
Post,
Query,
Req,
Res,
UseGuards,
@ -107,7 +106,7 @@ export class AuthController {
@Get('oidc')
@UseGuards(AuthGuard('oidc'))
@Version(VERSION_NEUTRAL)
public oidcLogin(@Query('linkMode') linkMode: string) {
public oidcLogin() {
if (!this.configurationService.get('ENABLE_FEATURE_AUTH_OIDC')) {
throw new HttpException(
getReasonPhrase(StatusCodes.FORBIDDEN),
@ -117,15 +116,6 @@ export class AuthController {
// Link mode is handled automatically by OidcStateStore.store()
// which extracts the token from query params and validates it
if (linkMode === 'true') {
Logger.log(
'OIDC link mode requested - token validation handled by OidcStateStore',
'AuthController'
);
} else {
Logger.debug('OIDC normal login flow initiated', 'AuthController');
}
// The AuthGuard('oidc') handles the redirect to the OIDC provider
}
@ -141,11 +131,6 @@ export class AuthController {
// Check if this is a link mode callback
if (result.linkState?.linkMode) {
Logger.log(
`OIDC callback: Link mode detected for user ${result.linkState.userId.substring(0, 8)}...`,
'AuthController'
);
try {
// Link the OIDC account to the existing user
await this.authService.linkOidcToUser(
@ -153,11 +138,6 @@ export class AuthController {
result.thirdPartyId
);
Logger.log(
`OIDC callback: Successfully linked OIDC to user ${result.linkState.userId.substring(0, 8)}...`,
'AuthController'
);
// Redirect to account page with success message
response.redirect(
`${rootUrl}/${DEFAULT_LANGUAGE_CODE}/account?linkSuccess=true`
@ -188,7 +168,6 @@ export class AuthController {
}
// Normal OIDC login flow
Logger.debug('OIDC callback: Normal login flow', 'AuthController');
const jwt: string = result.jwt;
if (jwt) {

35
apps/api/src/app/auth/auth.service.ts

@ -45,11 +45,6 @@ export class AuthService {
thirdPartyId
}: ValidateOAuthLoginParams): Promise<string> {
try {
Logger.debug(
`validateOAuthLogin: Validating login for provider ${provider}, thirdPartyId ${thirdPartyId?.substring(0, 8)}...`,
'AuthService'
);
// First, search by thirdPartyId only to support linked accounts
// (users with provider ANONYMOUS but with thirdPartyId set)
let [user] = await this.userService.users({
@ -57,36 +52,19 @@ export class AuthService {
});
if (user) {
Logger.log(
`validateOAuthLogin: Found existing user ${user.id.substring(0, 8)}... with provider ${user.provider} for thirdPartyId`,
'AuthService'
);
return this.jwtService.sign({
id: user.id
});
}
Logger.debug(
`validateOAuthLogin: No user found with thirdPartyId, checking if signup is enabled`,
'AuthService'
);
const isUserSignupEnabled =
await this.propertyService.isUserSignupEnabled();
if (!isUserSignupEnabled) {
Logger.warn(
`validateOAuthLogin: Sign up is disabled, rejecting new user`,
'AuthService'
);
throw new Error('Sign up forbidden');
}
// Create new user if not found
Logger.log(
`validateOAuthLogin: Creating new user with provider ${provider}`,
'AuthService'
);
user = await this.userService.createUser({
data: {
provider,
@ -157,18 +135,10 @@ export class AuthService {
const user = await this.userService.user({ id: userId });
if (!user) {
Logger.error(
`linkOidcToUser: User ${userId.substring(0, 8)}... not found`,
'AuthService'
);
throw new Error('User not found');
}
if (user.provider !== 'ANONYMOUS') {
Logger.error(
`linkOidcToUser: User ${userId.substring(0, 8)}... has provider ${user.provider}, expected ANONYMOUS`,
'AuthService'
);
throw new Error('Only users with token authentication can link OIDC');
}
@ -178,11 +148,6 @@ export class AuthService {
data: { thirdPartyId }
});
Logger.log(
`linkOidcToUser: Successfully linked OIDC to user ${userId.substring(0, 8)}...`,
'AuthService'
);
return this.jwtService.sign({ id: userId });
}
}

33
apps/api/src/app/auth/oidc-state.store.ts

@ -84,10 +84,6 @@ export class OidcStateStore {
linkMode: true,
userId: decoded.id
};
Logger.log(
`Link mode validated for user ${decoded.id.substring(0, 8)}... from request`,
'OidcStateStore'
);
}
} catch (error) {
Logger.warn(
@ -104,12 +100,6 @@ export class OidcStateStore {
}
}
const isLinkMode = linkState?.linkMode ?? false;
Logger.debug(
`Storing OIDC state with handle ${handle.substring(0, 8)}... (linkMode: ${isLinkMode})`,
'OidcStateStore'
);
this.stateMap.set(handle, {
appState,
ctx,
@ -146,19 +136,10 @@ export class OidcStateStore {
const data = this.stateMap.get(handle);
if (!data) {
Logger.debug(
`OIDC state not found for handle ${handle.substring(0, 8)}...`,
'OidcStateStore'
);
return callback(null, undefined, undefined);
}
if (Date.now() - data.timestamp > this.STATE_EXPIRY_MS) {
// State has expired
Logger.debug(
`OIDC state expired for handle ${handle.substring(0, 8)}...`,
'OidcStateStore'
);
this.stateMap.delete(handle);
return callback(null, undefined, undefined);
}
@ -166,19 +147,9 @@ export class OidcStateStore {
// Remove state after verification (one-time use)
this.stateMap.delete(handle);
const isLinkMode = data.linkState?.linkMode ?? false;
Logger.debug(
`Verified OIDC state for handle ${handle.substring(0, 8)}... (linkMode: ${isLinkMode})`,
'OidcStateStore'
);
// Attach linkState directly to request object for retrieval in validate()
if (data.linkState) {
(req as any).oidcLinkState = data.linkState;
Logger.log(
`Attached linkState to request for user ${data.linkState.userId.substring(0, 8)}...`,
'OidcStateStore'
);
}
callback(null, data.ctx, data.appState);
@ -223,10 +194,6 @@ export class OidcStateStore {
*/
public setLinkStateForNextStore(linkState: OidcLinkState) {
this.pendingLinkState = linkState;
Logger.log(
`Link state prepared for user ${linkState.userId.substring(0, 8)}...`,
'OidcStateStore'
);
}
/**

10
apps/api/src/app/auth/oidc.strategy.ts

@ -44,7 +44,6 @@ export class OidcStrategy extends PassportStrategy(Strategy, 'oidc') {
// Configure JWT secret for link mode validation
if (options.jwtSecret) {
OidcStrategy.stateStore.setJwtSecret(options.jwtSecret);
Logger.debug('JWT secret configured for OIDC link mode', 'OidcStrategy');
}
}
@ -82,11 +81,6 @@ export class OidcStrategy extends PassportStrategy(Strategy, 'oidc') {
| undefined;
if (linkState?.linkMode) {
Logger.log(
`OidcStrategy: Link mode detected for user ${linkState.userId.substring(0, 8)}...`,
'OidcStrategy'
);
// In link mode, we don't validate OAuth login (which would create a new user)
// Instead, we return the thirdPartyId for the controller to link
return {
@ -96,10 +90,6 @@ export class OidcStrategy extends PassportStrategy(Strategy, 'oidc') {
}
// Normal OIDC login flow
Logger.debug(
`OidcStrategy: Normal login flow for thirdPartyId ${thirdPartyId.substring(0, 8)}...`,
'OidcStrategy'
);
const jwt = await this.authService.validateOAuthLogin({
thirdPartyId,

Loading…
Cancel
Save