Skip to content

Commit f43dbbe

Browse files
committed
Resolve gitlab auth to guest user
1 parent 96f561d commit f43dbbe

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

backstage/app-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,11 @@ techdocs:
5353
auth:
5454
environment: development
5555
providers:
56-
guest: {}
5756
gitlab:
5857
development:
5958
clientId: ${AUTH_GITLAB_CLIENT_ID}
6059
clientSecret: ${AUTH_GITLAB_CLIENT_SECRET}
6160
audience: https://gitlab.diamond.ac.uk
62-
signIn:
63-
resolvers:
64-
- resolver: usernameMatchingUserEntityName
6561

6662
catalog:
6763
readonly: true

backstage/packages/backend/src/index.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
11
import { createBackend } from '@backstage/backend-defaults';
2+
import { createBackendModule } from '@backstage/backend-plugin-api';
3+
import { gitlabAuthenticator } from '@backstage/plugin-auth-backend-module-gitlab-provider';
4+
import {
5+
authProvidersExtensionPoint,
6+
createOAuthProviderFactory,
7+
} from '@backstage/plugin-auth-node';
28
import {
39
catalogPluginGitlabFillerProcessorModule,
410
gitlabPlugin,
511
} from '@immobiliarelabs/backstage-plugin-gitlab-backend';
612

13+
const customAuth = createBackendModule({
14+
// This ID must be exactly "auth" because that's the plugin it targets
15+
pluginId: 'auth',
16+
// This ID must be unique, but can be anything
17+
moduleId: 'custom-auth-provider',
18+
register(reg) {
19+
reg.registerInit({
20+
deps: { providers: authProvidersExtensionPoint },
21+
async init({ providers }) {
22+
providers.registerProvider({
23+
providerId: 'gitlab',
24+
factory: createOAuthProviderFactory({
25+
authenticator: gitlabAuthenticator,
26+
async signInResolver(info, ctx) {
27+
console.log(info);
28+
const userEntity = 'user:default/guest';
29+
return ctx.issueToken({
30+
claims: {
31+
sub: userEntity,
32+
ent: [userEntity],
33+
},
34+
});
35+
},
36+
}),
37+
});
38+
},
39+
});
40+
},
41+
});
42+
743
const backend = createBackend();
844

945
// Auth
1046
backend.add(import('@backstage/plugin-auth-backend'));
11-
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
12-
backend.add(import('@backstage/plugin-auth-backend-module-gitlab-provider'));
47+
backend.add(customAuth);
1348

1449
// Catalog with Scaffolder module
1550
backend.add(import('@backstage/plugin-catalog-backend'));

0 commit comments

Comments
 (0)