option to enable body parsing
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cc8762e4ec
commit
ec08f8f04e
@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## 3.1.0
|
||||
|
||||
- Option to enable body parsing
|
||||
|
||||
## 3.0.0
|
||||
|
||||
- Allows Cookies Parameters to be set
|
||||
|
@ -1,6 +1,6 @@
|
||||
# auth-server-helper
|
||||
|
||||
version: 3.0.x
|
||||
version: 3.1.x
|
||||
|
||||
customizable and simple authentication
|
||||
|
||||
@ -104,7 +104,8 @@ const handler = create_auth_handler(
|
||||
},
|
||||
},
|
||||
cookie: { name: 'auth_cookie' }, // if defined, access tokens will be stored in this cookie,
|
||||
refresh_cookie: { name: 'refresh_cookie' } // if defined, refresh tokens will be stored in this cookie
|
||||
refresh_cookie: { name: 'refresh_cookie' }, // if defined, refresh tokens will be stored in this cookie
|
||||
parse_body: true // read the request body into a string (default false)
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -225,14 +225,17 @@ interface CreateHandlerOptions {
|
||||
modules?: Record<string, AuthRequestHandler>;
|
||||
cookie?: CookieSettings;
|
||||
refresh_cookie?: CookieSettings;
|
||||
parse_body?: boolean;
|
||||
}
|
||||
|
||||
type ProcessRequestOptions = Omit<CreateHandlerOptions, 'parse_body'>
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
function process_request (
|
||||
request: AuthRequest,
|
||||
token: RegExpExecArray | null,
|
||||
default_handler: AuthRequestHandler,
|
||||
options?: CreateHandlerOptions
|
||||
options?: ProcessRequestOptions
|
||||
): Promise<void> | void {
|
||||
if (token === null)
|
||||
return default_handler (request);
|
||||
@ -313,15 +316,17 @@ export default function create_auth_handler (
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse
|
||||
): Promise<boolean> => {
|
||||
const body: string = await new Promise ((resolve) => {
|
||||
let data = '';
|
||||
req.on ('data', (c) => {
|
||||
data += c;
|
||||
});
|
||||
req.on ('end', () => {
|
||||
resolve (data);
|
||||
});
|
||||
});
|
||||
const body: string = options?.parse_body
|
||||
? await new Promise ((resolve) => {
|
||||
let data = '';
|
||||
req.on ('data', (c) => {
|
||||
data += c;
|
||||
});
|
||||
req.on ('end', () => {
|
||||
resolve (data);
|
||||
});
|
||||
})
|
||||
: '';
|
||||
|
||||
const request = new AuthRequest (
|
||||
req,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sapphirecode/auth-server-helper",
|
||||
"version": "3.0.0",
|
||||
"version": "3.1.0",
|
||||
"main": "dist/index.js",
|
||||
"author": {
|
||||
"name": "Timo Hocker",
|
||||
|
@ -129,7 +129,8 @@ describe ('auth handler', () => {
|
||||
}
|
||||
else { request.deny (); }
|
||||
}
|
||||
}
|
||||
},
|
||||
parse_body: true
|
||||
});
|
||||
|
||||
server = http.createServer (async (
|
||||
|
Loading…
x
Reference in New Issue
Block a user