Make tokenManager constructor private and add static create method
Signed-off-by: Nataliya Issayeva <nissayeva@users.noreply.github.com>
This commit is contained in:
@@ -28,7 +28,8 @@ const CLOCK_MARGIN_S = 10;
|
||||
* @experimental This is not a stable API yet
|
||||
*/
|
||||
|
||||
// TODO: (b2b-auth) integrate IdentityClient into the TokenManager instead
|
||||
// TODO: (b2b-auth) move IdentityClient into tokens
|
||||
// perhaps also create an interface?
|
||||
export class IdentityClient {
|
||||
private readonly discovery: PluginEndpointDiscovery;
|
||||
private readonly issuer: string;
|
||||
|
||||
@@ -19,19 +19,30 @@ import { TokenManager } from './types';
|
||||
import { IdentityClient } from '../identity';
|
||||
import { PluginEndpointDiscovery } from '../discovery';
|
||||
|
||||
// TODO: (b2b-auth) rename this class
|
||||
export class AuthIdentityTokenManager implements TokenManager {
|
||||
private identityClient: IdentityClient;
|
||||
private key: JWK.OctKey;
|
||||
|
||||
constructor(discovery: PluginEndpointDiscovery, secret: string) {
|
||||
this.identityClient = new IdentityClient({
|
||||
discovery,
|
||||
static create(options: {
|
||||
discovery: PluginEndpointDiscovery;
|
||||
secret: string;
|
||||
}) {
|
||||
const identityClient = new IdentityClient({
|
||||
discovery: options.discovery,
|
||||
issuer: 'auth-identity-token-manager',
|
||||
});
|
||||
return new AuthIdentityTokenManager(identityClient, options.secret);
|
||||
}
|
||||
|
||||
private constructor(identityClient: IdentityClient, secret: string) {
|
||||
this.identityClient = identityClient;
|
||||
// TODO: (b2b-auth) how do we get this to be the right JWK type
|
||||
this.key = JWK.asKey(Buffer.from(secret)) as JWK.OctKey;
|
||||
}
|
||||
|
||||
async getServerToken(): Promise<{ token: string }> {
|
||||
// TODO: (b2b-auth) figure out how to use HMAC as the alg
|
||||
const jwt = JWT.sign({ sub: 'backstage-server' }, this.key);
|
||||
return { token: jwt };
|
||||
}
|
||||
|
||||
@@ -66,7 +66,10 @@ function makeCreateEnv(config: Config) {
|
||||
const root = getRootLogger();
|
||||
const reader = UrlReaders.default({ logger: root, config });
|
||||
const discovery = SingleHostDiscovery.fromConfig(config);
|
||||
const tokenManager = new AuthIdentityTokenManager(discovery);
|
||||
const tokenManager = AuthIdentityTokenManager.create({
|
||||
discovery,
|
||||
secret: 'secret-tehe',
|
||||
});
|
||||
|
||||
root.info(`Created UrlReader ${reader}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user