chore: support unauthenticated request

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-03-11 15:46:31 +01:00
parent 0bab667c3e
commit 617d2df982
@@ -461,13 +461,18 @@ export async function createRouter(
defaultKind: 'template',
});
const credentials = await httpAuth.credentials(req, { allow: ['user'] });
// TODO(blam): This should be forced user auth eventually, but let's keep it as is for now,
// with the ability to do unauthenticated task creation.
const credentials = await httpAuth.credentials(req);
const { token } = await auth.getPluginRequestToken({
onBehalfOf: credentials,
targetPluginId: 'catalog',
});
const userEntityRef = credentials.principal.userEntityRef;
const userEntityRef = auth.isPrincipal(credentials, 'user')
? credentials.principal.userEntityRef
: undefined;
const userEntity = userEntityRef
? await catalogClient.getEntityByRef(userEntityRef, { token })