-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f08c0d
commit 9e4d419
Showing
9 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { IncomingMessage, ServerResponse } from "http"; | ||
import { HttpMethod, ProxyRequest, RequestHandlerConfig } from "prxi"; | ||
import { getConfig } from "../config/getConfig"; | ||
import { invalidateAuthCookies, sendRedirect } from "../utils/ResponseUtils"; | ||
import { OpenIDUtils } from "../utils/OpenIDUtils"; | ||
import { Logger } from "pino"; | ||
import getLogger from "../Logger"; | ||
import { JwtPayload, verify } from "jsonwebtoken"; | ||
import { RequestUtils } from "../utils/RequestUtils"; | ||
|
||
export class LoginHandler implements RequestHandlerConfig { | ||
private logger: Logger; | ||
|
||
constructor() { | ||
this.logger = getLogger('LoginHandler') | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public isMatching(method: HttpMethod, path: string): boolean { | ||
return method === 'GET' && path === getConfig().loginPath; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public async handle(req: IncomingMessage, res: ServerResponse, proxyRequest: ProxyRequest): Promise<void> { | ||
this.logger.info('Handle login request'); | ||
|
||
await sendRedirect(res, OpenIDUtils.getAuthorizationUrl()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { suite, test } from "@testdeck/mocha"; | ||
import { BaseSuite } from "./Base.suite"; | ||
import { getConfig } from "../src/config/getConfig"; | ||
import { strictEqual } from "assert"; | ||
|
||
@suite() | ||
export class LoginHandlerSuite extends BaseSuite { | ||
@test() | ||
async login() { | ||
const uri = '/api/test?q=str'; | ||
await this.withNewPage(getConfig().hostURL + getConfig().loginPath, async (page) => { | ||
await this.loginOnKeycloak(page); | ||
|
||
// make sure we can access the resource | ||
await this.navigate(page, getConfig().hostURL + uri); | ||
const json = await this.getJsonFromPage(page); | ||
strictEqual(json.http.originalUrl, uri); | ||
}); | ||
} | ||
} |