set and use access-token cookie
This commit is contained in:
@@ -82,9 +82,15 @@ export async function createRouter({
|
||||
const { kind, namespace, name } = req.params;
|
||||
|
||||
try {
|
||||
const token =
|
||||
getBearerToken(req.headers.authorization) ||
|
||||
req.cookies['access-token'];
|
||||
const entity = (await (
|
||||
await fetch(
|
||||
`${catalogUrl}/entities/by-name/${kind}/${namespace}/${name}`,
|
||||
{
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
},
|
||||
)
|
||||
).json()) as Entity;
|
||||
|
||||
@@ -109,7 +115,11 @@ export async function createRouter({
|
||||
const catalogUrl = await discovery.getBaseUrl('catalog');
|
||||
const triple = [kind, namespace, name].map(encodeURIComponent).join('/');
|
||||
|
||||
const catalogRes = await fetch(`${catalogUrl}/entities/by-name/${triple}`);
|
||||
const token =
|
||||
getBearerToken(req.headers.authorization) || req.cookies['access-token'];
|
||||
const catalogRes = await fetch(`${catalogUrl}/entities/by-name/${triple}`, {
|
||||
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
||||
});
|
||||
if (!catalogRes.ok) {
|
||||
const catalogResText = await catalogRes.text();
|
||||
res.status(catalogRes.status);
|
||||
@@ -202,3 +212,7 @@ export async function createRouter({
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
function getBearerToken(header?: string): string | undefined {
|
||||
return header?.match(/(?:Bearer|Basic)\s+(\S+)/i)?.[1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user