Skip to content

Commit a2286c6

Browse files
Fix auth handler
1 parent ac332ab commit a2286c6

3 files changed

Lines changed: 6 additions & 55 deletions

File tree

packages/react-ui/src/app/interceptors/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
import axios from 'axios';
22

3-
import { createRequestInterceptor } from './request-interceptor';
43
import {
54
createFederatedResponseInterceptor,
65
createResponseInterceptor,
76
} from './response-interceptor';
87

9-
let requestInterceptorId: number | null = null;
108
let responseInterceptorId: number | null = null;
119

12-
function setupRequestInterceptor(): void {
13-
if (requestInterceptorId === null) {
14-
const requestInterceptor = createRequestInterceptor();
15-
requestInterceptorId = axios.interceptors.request.use(requestInterceptor);
16-
}
17-
}
18-
19-
setupRequestInterceptor();
20-
2110
type ResponseInterceptorOptions = {
2211
isFederatedAuth: boolean;
2312
};

packages/react-ui/src/app/interceptors/request-interceptor.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/server/api/src/app/core/security/authn/access-token-authn-handler.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cacheWrapper, logger } from '@openops/server-shared';
1+
import { logger } from '@openops/server-shared';
22
import {
33
ApplicationError,
44
ErrorCode,
@@ -11,15 +11,13 @@ import { userService } from '../../../user/user-service';
1111
import { BaseSecurityHandler } from '../security-handler';
1212

1313
export class AccessTokenAuthnHandler extends BaseSecurityHandler {
14-
private static readonly HEADER_NAME = 'authorization';
15-
private static readonly HEADER_PREFIX = 'Bearer ';
14+
private static readonly COOKIE_NAME = 'token';
1615

1716
protected canHandle(request: FastifyRequest): Promise<boolean> {
18-
const header = request.headers[AccessTokenAuthnHandler.HEADER_NAME];
19-
const prefix = AccessTokenAuthnHandler.HEADER_PREFIX;
20-
const routeMatches = header?.startsWith(prefix) ?? false;
17+
const token = request.cookies?.[AccessTokenAuthnHandler.COOKIE_NAME];
18+
const hasToken = !isNil(token);
2119
const skipAuth = request.routeOptions.config?.skipAuth ?? false;
22-
return Promise.resolve(routeMatches && !skipAuth);
20+
return Promise.resolve(hasToken && !skipAuth);
2321
}
2422

2523
protected async doHandle(request: FastifyRequest): Promise<void> {
@@ -50,9 +48,7 @@ export class AccessTokenAuthnHandler extends BaseSecurityHandler {
5048
}
5149

5250
private extractAccessTokenOrThrow(request: FastifyRequest): string {
53-
const header = request.headers[AccessTokenAuthnHandler.HEADER_NAME];
54-
const prefix = AccessTokenAuthnHandler.HEADER_PREFIX;
55-
const accessToken = header?.substring(prefix.length);
51+
const accessToken = request.cookies?.[AccessTokenAuthnHandler.COOKIE_NAME];
5652

5753
if (isNil(accessToken)) {
5854
throw new ApplicationError({

0 commit comments

Comments
 (0)