beps/0003: add none credential and expiration times

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-02-26 10:17:50 +01:00
parent 432fe068fe
commit 05a4bbb5d0
@@ -110,6 +110,8 @@ export type BackstageServicePrincipal = {
export type BackstageCredentials<TPrincipal = unknown> = {
$$type: '@backstage/BackstageCredentials';
expiresAt?: Date;
principal: TPrincipal;
};
@@ -132,6 +134,8 @@ export interface AuthService {
type: TType,
): credentials is BackstageCredentials<BackstagePrincipalTypes[TType]>;
getNoneCredentials(): Promise<BackstageCredentials<BackstageUserPrincipal>>;
getOwnServiceCredentials(): Promise<
BackstageCredentials<BackstageServicePrincipal>
>;
@@ -228,9 +232,9 @@ export default createBackendPlugin({
// Endpoint that sets the cookie for the user
router.get('/cookie', async (req, res) => {
await httpAuth.issueUserCookie(req);
const { expiresAt } = await httpAuth.issueUserCookie(req);
res.json({ ok: true });
res.json({ expiresAt: expiresAt.toISOString() });
});
// Endpoint protected by cookie auth
@@ -303,7 +307,7 @@ export interface HttpAuthService {
// If credentials are not provided, they will be read from the request
credentials?: BackstageCredentials<BackstageUserPrincipal>;
},
): Promise<void>;
): Promise<{ expiresAt: Date }>;
}
```