allow bearer and other types of authorization in default handler
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-01-06 11:38:56 +01:00
parent df8de9e0c8
commit 5df2577e71
2 changed files with 59 additions and 32 deletions

View File

@ -37,8 +37,12 @@ class AuthRequest {
public is_basic: boolean;
public user: string;
public password: string;
public is_bearer: boolean;
public token?: string;
public token_data?: unknown;
public token_id?: string;
public body: string;
private _cookie_name?: string;
@ -53,6 +57,7 @@ class AuthRequest {
this.response = res;
this.body = body;
this.is_basic = false;
this.is_bearer = false;
this.user = '';
this.password = '';
this._cookie_name = cookie;
@ -180,7 +185,7 @@ export default function create_auth_handler (
.exec (req.headers.authorization as string);
if (token === null) {
request.deny ();
request.invalid ('missing authorization header');
return Promise.resolve ();
}
@ -197,37 +202,42 @@ export default function create_auth_handler (
return default_handler (request);
}
const token_data = auth.verify (token?.groups?.token as string);
if ((/Bearer/ui).test (token?.groups?.type as string)) {
request.is_bearer = true;
request.token = token?.groups?.token;
if (!token_data.valid) {
request.deny ();
const token_data = auth.verify (request.token as string);
if (!token_data.valid)
return default_handler (request);
request.token_data = token_data.data;
request.token_id = token_data.id;
if (
typeof options !== 'undefined'
&& typeof options.refresh !== 'undefined'
&& token_data.type === 'refresh_token'
) {
request.allow_access (options.refresh);
return Promise.resolve ();
}
if (
typeof options !== 'undefined'
&& typeof options.modules !== 'undefined'
&& token_data.type === 'part_token'
&& typeof token_data.next_module !== 'undefined'
&& Object.keys (options.modules)
.includes (token_data.next_module)
)
return options.modules[token_data.next_module] (request);
request.invalid ('invalid bearer type');
return Promise.resolve ();
}
request.token_data = token_data.data;
request.token_id = token_data.id;
if (
typeof options !== 'undefined'
&& typeof options.refresh !== 'undefined'
&& token_data.type === 'refresh_token'
) {
request.allow_access (options.refresh);
return Promise.resolve ();
}
if (
typeof options !== 'undefined'
&& typeof options.modules !== 'undefined'
&& token_data.type === 'part_token'
&& typeof token_data.next_module !== 'undefined'
&& Object.keys (options.modules)
.includes (token_data.next_module)
)
return options.modules[token_data.next_module] (request);
request.invalid ('invalid bearer type');
return Promise.resolve ();
return default_handler (request);
};
}