Skip to content

Commit

Permalink
Merge pull request #619 from immobiliare/feat/support-for-new-backend…
Browse files Browse the repository at this point in the history
…-system

feat: support for new backend system
  • Loading branch information
antoniomuso committed Mar 5, 2024
2 parents 4488d01 + d711af4 commit 7d9f3d2
Show file tree
Hide file tree
Showing 4 changed files with 915 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/ldap-auth-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-plugin-api": "^0.6.13",
"@backstage/core-plugin-api": "^1.0.3",
"@backstage/errors": "^1.1.0",
"@backstage/plugin-auth-backend": "^0.19.0",
Expand Down
86 changes: 86 additions & 0 deletions packages/ldap-auth-backend/src/alpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
RootConfigService,
coreServices,
createBackendModule,
createExtensionPoint,
createServiceFactory,
createServiceRef,
} from '@backstage/backend-plugin-api';
import { authProvidersExtensionPoint } from '@backstage/plugin-auth-node';
import { JWTTokenValidator, TokenValidator } from './jwt';
import { ldap } from './provider';
import { LDAPResponse } from './types';
import { AuthHandler } from '@backstage/plugin-auth-backend';
import Keyv from 'keyv';

interface AuthHandlerSetter {
set(handler: AuthHandler<Partial<LDAPResponse>>): void;
}
export const ldapAuthExtensionPoint = createExtensionPoint<AuthHandlerSetter>({
id: 'ldap-auth-extension',
});

export const tokenValidatorRef = createServiceRef<TokenValidator>({
scope: 'plugin',
id: 'token-validator',
defaultFactory: async (service) =>
createServiceFactory({
service,
deps: { config: coreServices.rootConfig },
factory({}) {
return new JWTTokenValidator(new Keyv());
},
}),
});

type TokenValidatorOptions = {
createTokenValidator(
config: RootConfigService
): TokenValidator | Promise<TokenValidator>;
};

export const tokenValidatorFactory = createServiceFactory(
(options?: TokenValidatorOptions) => ({
service: tokenValidatorRef,
deps: { config: coreServices.rootConfig },
factory({ config }) {
return (
options?.createTokenValidator(config) ||
new JWTTokenValidator(new Keyv())
);
},
})
);

export default createBackendModule({
pluginId: 'auth',
moduleId: 'ldap',
register(reg) {
let authHandler: AuthHandler<Partial<LDAPResponse>> | undefined;
const authHandlerSetter = {
set(handler: AuthHandler<Partial<LDAPResponse>>) {
authHandler = handler;
},
};
reg.registerExtensionPoint<AuthHandlerSetter>(
ldapAuthExtensionPoint,
authHandlerSetter
);

reg.registerInit({
deps: {
providers: authProvidersExtensionPoint,
tokenValidator: tokenValidatorRef,
},
async init({ providers, tokenValidator }) {
providers.registerProvider({
providerId: 'ldap',
factory: ldap.create({
tokenValidator,
authHandler,
}),
});
},
});
},
});
2 changes: 2 additions & 0 deletions packages/ldap-auth-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { prepareBackstageIdentityResponse } from './auth';
export { ldap, ProviderLdapAuthProvider } from './provider';
export { JWTTokenValidator, parseJwtPayload, normalizeTime } from './jwt';
export type { TokenValidator } from './jwt';
export * from './alpha';
export { default as default } from './alpha';
Loading

0 comments on commit 7d9f3d2

Please sign in to comment.