Add TODOs

Signed-off-by: Nataliya Issayeva <nissayeva@users.noreply.github.com>
This commit is contained in:
Nataliya Issayeva
2021-10-27 16:49:56 -04:00
parent 4f066c3be6
commit 7b4f1ed0b9
2 changed files with 8 additions and 2 deletions
@@ -27,6 +27,8 @@ const CLOCK_MARGIN_S = 10;
*
* @experimental This is not a stable API yet
*/
// TODO: (b2b-auth) integrate IdentityClient into the TokenManager instead
export class IdentityClient {
private readonly discovery: PluginEndpointDiscovery;
private readonly issuer: string;
@@ -90,6 +92,7 @@ export class IdentityClient {
* Returns the public signing key matching the given jwt token,
* or null if no matching key was found
*/
// TODO (b2b-auth): switch on type to identify server tokens?
private async getKey(rawJwtToken: string): Promise<JWK.Key | null> {
const { header, payload } = JWT.decode(rawJwtToken, {
complete: true,
@@ -19,6 +19,7 @@ import { IdentityClient } from '../identity';
import { PluginEndpointDiscovery } from '../discovery';
export class AuthIdentityTokenManager implements TokenManager {
// TODO: (b2b-auth) replace this in favor of actual server token in config likely
private readonly SERVER_TOKEN = 'server-token';
private identityClient: IdentityClient;
@@ -33,13 +34,15 @@ export class AuthIdentityTokenManager implements TokenManager {
return { token: this.SERVER_TOKEN };
}
// TODO: (b2b-auth) authenticate returns a Backstage Identity
// need to figure out what to return after validating a server token
async validateToken(token: string): Promise<void> {
if (token !== this.SERVER_TOKEN) {
try {
await this.identityClient.authenticate(token);
return;
} catch (e) {
throw new Error('Invalid token');
} catch (error) {
throw new Error(`Invalid token, ${error}`);
}
}
}