Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
Added backstage-plugin-keycloak-backend plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Block <[email protected]>
  • Loading branch information
sabre1041 committed Dec 28, 2022
1 parent 55b8326 commit 1386732
Show file tree
Hide file tree
Showing 4 changed files with 576 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@backstage/plugin-search-backend-module-pg": "^0.3.5",
"@backstage/plugin-search-backend-node": "^1.0.0",
"@backstage/plugin-techdocs-backend": "^1.2.0",
"@janus-idp/backstage-plugin-keycloak-backend": "^1.0.2",
"app": "link:../app",
"dockerode": "^3.3.1",
"express": "^4.17.1",
Expand Down
38 changes: 26 additions & 12 deletions packages/backend/src/plugins/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
providers,
defaultAuthProviderFactories,
} from '@backstage/plugin-auth-backend';

import {
DEFAULT_NAMESPACE,
stringifyEntityRef,
} from '@backstage/catalog-model';

import { NotFoundError } from '@backstage/errors';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { PluginEnvironment, } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
Expand All @@ -29,17 +31,29 @@ export default async function createPlugin(
if (!name) {
throw new Error('Request did not contain a user')
}
const userEntityRef = stringifyEntityRef({
kind: 'User',
name: name,
namespace: DEFAULT_NAMESPACE,
});
return ctx.issueToken({
claims: {
sub: userEntityRef,
ent: [userEntityRef],
},
});

try {

// Attempts to sign in existing user
const signedInUser = await ctx.signInWithCatalogUser({
entityRef: { name },
});

return Promise.resolve(signedInUser);
} catch (e) {
// Create stub user
const userEntityRef = stringifyEntityRef({
kind: 'User',
name: name,
namespace: DEFAULT_NAMESPACE,
});
return ctx.issueToken({
claims: {
sub: userEntityRef,
ent: [userEntityRef],
},
});
}
},
},
}),
Expand Down
28 changes: 20 additions & 8 deletions packages/backend/src/plugins/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backen
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { GithubEntityProvider } from '@backstage/plugin-catalog-backend-module-github';
import { KeycloakOrgEntityProvider } from '@janus-idp/backstage-plugin-keycloak-backend';


export default async function createPlugin(
Expand All @@ -11,14 +12,25 @@ export default async function createPlugin(
const builder = await CatalogBuilder.create(env);
builder.addProcessor(new ScaffolderEntitiesProcessor());
builder.addEntityProvider(
GithubEntityProvider.fromConfig(env.config, {
logger: env.logger,
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { minutes: 30 },
timeout: { minutes: 3 },
})
}),
);
GithubEntityProvider.fromConfig(env.config, {
logger: env.logger,
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { minutes: 30 },
timeout: { minutes: 3 },
})
}),
);
builder.addEntityProvider(
KeycloakOrgEntityProvider.fromConfig(env.config, {
id: 'development',
logger: env.logger,
schedule: env.scheduler.createScheduledTaskRunner({
frequency: { hours: 1 },
timeout: { minutes: 50 },
initialDelay: { seconds: 15 }
}),
}),
);
const { processingEngine, router } = await builder.build();
await processingEngine.start();
return router;
Expand Down
Loading

0 comments on commit 1386732

Please sign in to comment.