-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ feat: added QRCode service * ✨ feat: added QRCode API controller * ✨ feat: added QRCode API Router * 🏷️ chore: add QRCode API types * ✨ feat: added QRCode API * ➕ chore(deps): added qrcode deps * ✅ chore: add unit tests * 🏷️ chore: added qr_code_url to the config * ✨ feat: use a QRCode url config * ✅ chore: update unit tests * 📝 chore: update swagger docs * 🔧 chore: add qr_code_url to default config * 🧪 chore: update test config * ✨ feat: added qrcode token service * ✨ feat: added qrcode service * 🎨 chore: expose services * 🎨 feat: use exposes services * 🏷️ chore: update qrcode API related types * ✅ chore: add service tests * 🧪 chore: update controller tests * 🔇 chore: remove console log * 🏷️ chore: add oidc flow related types * ✨ feat: fetch access_token using OIDC * 🎨 feat: use cookies to start the oidc flow * 🐛 fix: Dockerfile QR CODE env variable init * ✨ feat: use OIDC flow to request a new access_token * 🧪 chore: update token service unit tests * 🏷️ chore: add oidc flow related types * 🧪 chore: update controllers unit test
- Loading branch information
Showing
21 changed files
with
1,262 additions
and
9 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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
import { type TwakeLogger } from '@twake/logger' | ||
import { | ||
type IQRCodeTokenService, | ||
type IQRCodeApiController, | ||
type IQRCodeService | ||
} from '../types' | ||
import { type Response, type NextFunction } from 'express' | ||
import type { Config, AuthRequest } from '../../types' | ||
import { QRCodeService, QRCodeTokenService } from '../services' | ||
|
||
class QRCodeApiController implements IQRCodeApiController { | ||
private readonly qrCodeService: IQRCodeService | ||
private readonly qrCodeTokenService: IQRCodeTokenService | ||
|
||
constructor(private readonly logger: TwakeLogger, config: Config) { | ||
this.qrCodeService = new QRCodeService(config, logger) | ||
this.qrCodeTokenService = new QRCodeTokenService(config, logger) | ||
} | ||
|
||
/** | ||
* Get the QR code for the connected user. | ||
* | ||
* @param {AuthRequest} req - The request object. | ||
* @param {Response} res - The response object. | ||
* @param {NextFunction} next - The next function. | ||
*/ | ||
get = async ( | ||
req: AuthRequest, | ||
res: Response, | ||
next: NextFunction | ||
): Promise<void> => { | ||
try { | ||
const cookies = req.headers.cookie | ||
|
||
if (cookies === undefined) { | ||
res.status(400).json({ error: 'Cookies are missing' }) | ||
return | ||
} | ||
|
||
const accessToken = await this.qrCodeTokenService.getAccessToken(cookies) | ||
|
||
if (accessToken === null) { | ||
res.status(400).json({ error: 'Invalid access token' }) | ||
return | ||
} | ||
|
||
const qrcode = await this.qrCodeService.getImage(accessToken) | ||
|
||
res.setHeader('Content-Type', 'image/svg+xml') | ||
res.send(qrcode) | ||
} catch (error) { | ||
this.logger.error('Failed to generate QR Code', { error }) | ||
next(error) | ||
} | ||
} | ||
} | ||
|
||
export default QRCodeApiController |
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 @@ | ||
export { default } from './routes' |
Oops, something went wrong.