Skip to content

Commit

Permalink
fix: token from headers
Browse files Browse the repository at this point in the history
  • Loading branch information
emrahcom committed Aug 7, 2024
1 parent 6b39019 commit 3c46159
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sip-dial-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ async function readDialPlan(): Promise<Response> {
}

// ----------------------------------------------------------------------------
async function getDialPlan(qs: URLSearchParams): Promise<Response> {
const token = qs.get("jwt");
async function getDialPlan(req: Request): Promise<Response> {
const authHeader = req.headers.get("authorization");
if (!authHeader) return emptyList();

const token = authHeader.replace("Bearer ", "");
if (!token) return emptyList();

let jwt: Payload;
Expand Down Expand Up @@ -123,12 +126,11 @@ async function getDialPlan(qs: URLSearchParams): Promise<Response> {
async function handler(req: Request): Promise<Response> {
const url = new URL(req.url);
const path = url.pathname;
const qs = new URLSearchParams(url.search);

if (req.method !== "GET" && req.method !== "HEAD") return methodNotAllowed();
if (path !== "/get-dial-plan") return notFound();

return await getDialPlan(qs);
return await getDialPlan(req);
}

// ----------------------------------------------------------------------------
Expand Down

0 comments on commit 3c46159

Please sign in to comment.