Feat: API Playground (#10376)
/claim #10283 --------- Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -3,7 +3,9 @@ import { JwtService, JwtSignOptions, JwtVerifyOptions } from '@nestjs/jwt';
|
||||
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
import { Request as ExpressRequest } from 'express';
|
||||
import * as jwt from 'jsonwebtoken';
|
||||
import { ExtractJwt, JwtFromRequestFunction } from 'passport-jwt';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
import {
|
||||
@ -122,4 +124,20 @@ export class JwtWrapperService {
|
||||
|
||||
return accessTokenSecret;
|
||||
}
|
||||
|
||||
extractJwtFromRequest(): JwtFromRequestFunction {
|
||||
return (request: ExpressRequest) => {
|
||||
// First try to extract token from Authorization header
|
||||
const tokenFromHeader = ExtractJwt.fromAuthHeaderAsBearerToken()(request);
|
||||
|
||||
if (tokenFromHeader) {
|
||||
return tokenFromHeader;
|
||||
}
|
||||
|
||||
// If not found in header, try to extract from URL query parameter
|
||||
// This is for edge cases where we don't control the origin request
|
||||
// (e.g. the REST API playground)
|
||||
return ExtractJwt.fromUrlQueryParameter('token')(request);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user