feat: line (#13)
* add wedhook line * text message * add router get employee, request, quotation * move code * do not crash application when not set line token This feature is opt-in * dot not crash when not set line client id Main auth method is keycloak * change dotenv * fix: wrong env * refactor: change to get instead of post * refactor: remove body for employee get endpoint * feat: add work relation include * feat: include customer relation in employee * feat: add line file controller * add detail flex message and get date requestWork * chore: update deps lock * fix: error line token * fix: redirect head instead if response with body * feat: add response relation * fix: route casing * add userId in customerBranch verifyOTP * delete consile log * add is registered endpoint placeholder * feat: quotation list * fix: wrong endpoint name * feat: include relation in get by id request data * add where userId line * refactor: adjust parameter for liff app * delete code * refactor: remove post quotation endpoint * refactor: add where userId line for quotation * feat: add pending only parameter * refactor: more condition for inProgressOnly * refactor: update condition * feat: add line quotation attachment endpoint * feat: include product in request work line endpoint * refactor: pending only now cover more condition * feat: include invoice with payment relation * chore: update api docs tag * chore: clean * feat: check for registered user * fix: wrong file location * feat: add email client for sending an otp * chore: move some deps to dev deps * add otpCode otpExpires * add send-otp and verify-otp --------- Co-authored-by: Kanjana <kanjana@chamomind.com> Co-authored-by: chamomind <chamomind@localhost> Co-authored-by: Methapon2001 <61303214+Methapon2001@users.noreply.github.com>
This commit is contained in:
parent
8709a7dcc8
commit
12bf2182dc
15 changed files with 10449 additions and 4 deletions
47
src/middlewares/auth-provider/line.ts
Normal file
47
src/middlewares/auth-provider/line.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import Express from "express";
|
||||
|
||||
import HttpError from "../../interfaces/http-error";
|
||||
import HttpStatus from "../../interfaces/http-status";
|
||||
|
||||
export async function lineAuth(request: Express.Request) {
|
||||
const data = new URLSearchParams();
|
||||
const token = request.headers["authorization"];
|
||||
|
||||
if (!process.env.LINE_CLIENT_ID) {
|
||||
console.warn("Line related endpoint was called but LINE_CLIENT_ID not set.");
|
||||
throw new HttpError(HttpStatus.NOT_IMPLEMENTED, "NOT IMPLEMENTED", "notImplemented");
|
||||
}
|
||||
|
||||
const LINE_CLIENT_ID = process.env.LINE_CLIENT_ID;
|
||||
|
||||
if (!token || typeof token !== "string") {
|
||||
throw new HttpError(
|
||||
HttpStatus.UNAUTHORIZED,
|
||||
"authorization data not found.",
|
||||
"authDataNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
data.append("id_token", token);
|
||||
data.append("client_id", LINE_CLIENT_ID);
|
||||
|
||||
const dataUser = await fetch("https://api.line.me/oauth2/v2.1/verify", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
body: data.toString(),
|
||||
});
|
||||
|
||||
if (!dataUser)
|
||||
throw new HttpError(
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
"Error authentication service.",
|
||||
"authFailedFatal",
|
||||
);
|
||||
if (!dataUser.ok) {
|
||||
throw new HttpError(HttpStatus.UNAUTHORIZED, "Unauthorized.", "authFailed");
|
||||
}
|
||||
|
||||
return await dataUser.json();
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import Express from "express";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import { keycloakAuth } from "./auth-provider/keycloak";
|
||||
import { lineAuth } from "./auth-provider/line";
|
||||
|
||||
export async function expressAuthentication(
|
||||
request: Express.Request,
|
||||
|
|
@ -17,6 +18,9 @@ export async function expressAuthentication(
|
|||
request.app.locals.logData.userName = authData.name;
|
||||
request.app.locals.logData.userId = authData.sub;
|
||||
return authData;
|
||||
case "line":
|
||||
const authLineData = await lineAuth(request);
|
||||
return authLineData;
|
||||
default:
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_IMPLEMENTED,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue