algorithms field is now array for IdentityClient

Signed-off-by: Manuel Scurti <manuel.scurti@agilelab.it>
This commit is contained in:
Manuel Scurti
2022-05-18 11:31:29 +02:00
parent f6aae90e4e
commit 9079a78078
5 changed files with 27 additions and 11 deletions
+2 -3
View File
@@ -1,6 +1,5 @@
---
'@backstage/plugin-auth-backend': minor
'@backstage/plugin-auth-node': minor
'@backstage/plugin-auth-backend': patch
---
Added configurable algorithm field for IdentityClient and TokenFactory
Added configurable algorithm field for TokenFactory
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-auth-node': patch
---
Added configurable algorithms array for IdentityClient
@@ -33,7 +33,7 @@ type Options = {
/** Expiration time of signing keys in seconds */
keyDurationSeconds: number;
/** JWS "alg" (Algorithm) Header Parameter value. Defaults to ES256.
* Must match the algorithm defined in IdentityClient.
* Must match one of the algorithms defined for IdentityClient.
* More info on supported algorithms: https://github.com/panva/jose */
algorithm?: string;
};
+14 -1
View File
@@ -146,11 +146,24 @@ describe('IdentityClient', () => {
});
});
it('should throw error on empty algorithms array', async () => {
const identityClient = IdentityClient.create({
discovery,
issuer: mockBaseUrl,
algorithms: [''],
});
const token = await factory.issueToken({ claims: { sub: 'foo' } });
return expect(
async () => await identityClient.authenticate(token),
).rejects.toThrow();
});
it('should throw error on empty algorithm string', async () => {
const identityClient = IdentityClient.create({
discovery,
issuer: mockBaseUrl,
algorithm: '',
algorithms: [],
});
const token = await factory.issueToken({ claims: { sub: 'foo' } });
+5 -6
View File
@@ -33,10 +33,9 @@ export type IdentityClientOptions = {
discovery: PluginEndpointDiscovery;
issuer: string;
/** JWS "alg" (Algorithm) Header Parameter value. Defaults to ES256.
* Must match the algorithm defined in TokenFactory.
/** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
* More info on supported algorithms: https://github.com/panva/jose */
algorithm?: string;
algorithms?: string[];
};
/**
@@ -49,7 +48,7 @@ export type IdentityClientOptions = {
export class IdentityClient {
private readonly discovery: PluginEndpointDiscovery;
private readonly issuer: string;
private readonly algorithm: string;
private readonly algorithms: string[];
private keyStore?: GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;
private keyStoreUpdated: number = 0;
@@ -63,7 +62,7 @@ export class IdentityClient {
private constructor(options: IdentityClientOptions) {
this.discovery = options.discovery;
this.issuer = options.issuer;
this.algorithm = options.algorithm ?? 'ES256';
this.algorithms = options.algorithms ?? ['ES256'];
}
/**
@@ -88,7 +87,7 @@ export class IdentityClient {
throw new AuthenticationError('No keystore exists');
}
const decoded = await jwtVerify(token, this.keyStore, {
algorithms: [this.algorithm],
algorithms: this.algorithms,
audience: 'backstage',
issuer: this.issuer,
});