feat: add allow static cookie auth
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -72,8 +72,17 @@ export const techdocsPlugin = createBackendPlugin({
|
||||
http: coreServices.httpRouter,
|
||||
discovery: coreServices.discovery,
|
||||
cache: coreServices.cache,
|
||||
httpAuth: coreServices.httpAuth,
|
||||
},
|
||||
async init({ config, logger, urlReader, http, discovery, cache }) {
|
||||
async init({
|
||||
config,
|
||||
logger,
|
||||
urlReader,
|
||||
http,
|
||||
discovery,
|
||||
cache,
|
||||
httpAuth,
|
||||
}) {
|
||||
const winstonLogger = loggerToWinstonLogger(logger);
|
||||
// Preparers are responsible for fetching source files for documentation.
|
||||
const preparers = await Preparers.fromConfig(config, {
|
||||
@@ -114,8 +123,14 @@ export const techdocsPlugin = createBackendPlugin({
|
||||
publisher,
|
||||
config,
|
||||
discovery,
|
||||
httpAuth,
|
||||
}),
|
||||
);
|
||||
|
||||
http.addAuthPolicy({
|
||||
path: '/static',
|
||||
allow: 'user-cookie',
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import {
|
||||
PluginEndpointDiscovery,
|
||||
PluginCacheManager,
|
||||
createLegacyAuthAdapters,
|
||||
} from '@backstage/backend-common';
|
||||
import { CatalogClient } from '@backstage/catalog-client';
|
||||
import { stringifyEntityRef } from '@backstage/catalog-model';
|
||||
@@ -37,6 +38,7 @@ import { createCacheMiddleware, TechDocsCache } from '../cache';
|
||||
import { CachedEntityLoader } from './CachedEntityLoader';
|
||||
import { DefaultDocsBuildStrategy } from './DefaultDocsBuildStrategy';
|
||||
import * as winston from 'winston';
|
||||
import { HttpAuthService } from '@backstage/backend-plugin-api';
|
||||
|
||||
/**
|
||||
* Required dependencies for running TechDocs in the "out-of-the-box"
|
||||
@@ -56,6 +58,7 @@ export type OutOfTheBoxDeploymentOptions = {
|
||||
docsBuildStrategy?: DocsBuildStrategy;
|
||||
buildLogTransport?: winston.transport;
|
||||
catalogClient?: CatalogClient;
|
||||
httpAuth?: HttpAuthService;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -73,6 +76,7 @@ export type RecommendedDeploymentOptions = {
|
||||
docsBuildStrategy?: DocsBuildStrategy;
|
||||
buildLogTransport?: winston.transport;
|
||||
catalogClient?: CatalogClient;
|
||||
httpAuth?: HttpAuthService;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -106,6 +110,9 @@ export async function createRouter(
|
||||
): Promise<express.Router> {
|
||||
const router = Router();
|
||||
const { publisher, config, logger, discovery } = options;
|
||||
|
||||
const { httpAuth } = createLegacyAuthAdapters(options);
|
||||
|
||||
const catalogClient =
|
||||
options.catalogClient ?? new CatalogClient({ discoveryApi: discovery });
|
||||
const docsBuildStrategy =
|
||||
@@ -287,6 +294,12 @@ export async function createRouter(
|
||||
// Route middleware which serves files from the storage set in the publisher.
|
||||
router.use('/static/docs', publisher.docsRouter());
|
||||
|
||||
// Endpoint that sets the cookie for the user
|
||||
router.get('/cookie', async (req, res) => {
|
||||
const { expiresAt } = await httpAuth.issueUserCookie(req);
|
||||
res.json({ expiresAt: expiresAt.toISOString() });
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user