@backstage/backend-defaults
Version:
Backend defaults used by Backstage backend apps
32 lines (28 loc) • 970 B
JavaScript
;
var helpers = require('./helpers.cjs.js');
const MIN_TOKEN_LENGTH = 8;
const staticTokenHandler = helpers.createExternalTokenHandler({
type: "static",
initialize(ctx) {
const token = ctx.options.getString("token");
const subject = ctx.options.getString("subject");
if (!token.match(/^\S+$/)) {
throw new Error("Illegal token, must be a set of non-space characters");
} else if (token.length < MIN_TOKEN_LENGTH) {
throw new Error(
`Illegal token, must be at least ${MIN_TOKEN_LENGTH} characters length`
);
} else if (!subject.match(/^\S+$/)) {
throw new Error("Illegal subject, must be a set of non-space characters");
}
return { token, subject };
},
async verifyToken(token, context) {
if (token === context.token) {
return { subject: context.subject };
}
return void 0;
}
});
exports.staticTokenHandler = staticTokenHandler;
//# sourceMappingURL=static.cjs.js.map