allow immediate redirect on auth
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Timo Hocker
2021-05-10 12:26:56 +02:00
parent a3f021fdd2
commit e7ad5656e3
4 changed files with 785 additions and 543 deletions

View File

@ -13,6 +13,7 @@ interface AccessSettings {
access_token_expires_in: number
include_refresh_token?: boolean
refresh_token_expires_in?: number
redirect_to?: string
data?: Record<string, unknown>
}
@ -62,19 +63,21 @@ class AuthRequest {
this._cookie_name = cookie;
}
private default_header () {
private default_header (set_content = true) {
this.response.setHeader ('Cache-Control', 'no-store');
this.response.setHeader ('Pragma', 'no-cache');
this.response.setHeader ('Content-Type', 'application/json');
if (set_content)
this.response.setHeader ('Content-Type', 'application/json');
}
public async allow_access ({
access_token_expires_in,
include_refresh_token,
refresh_token_expires_in,
redirect_to,
data
}: AccessSettings): Promise<AccessResult> {
this.default_header ();
this.default_header (typeof redirect_to !== 'string');
const at = await auth.sign (
'access_token',
@ -109,6 +112,14 @@ class AuthRequest {
res.refresh_expires_in = refresh_token_expires_in;
result.refresh_token_id = rt.id;
}
if (typeof redirect_to === 'string') {
this.response.setHeader ('Location', redirect_to);
this.response.writeHead (302);
this.response.end ();
return result;
}
this.response.writeHead (200);
this.response.end (JSON.stringify (res));
@ -156,7 +167,7 @@ class AuthRequest {
}
}
type AuthRequestHandler = (req: AuthRequest) => void|Promise<void>;
type AuthRequestHandler = (req: AuthRequest) => Promise<void> | void;
interface CreateHandlerOptions {
refresh?: AccessSettings;