Skip to content

Commit fd70c9d

Browse files
committed
setup github auth and update dependencies
1 parent 7aa0bb5 commit fd70c9d

File tree

5 files changed

+89
-34
lines changed

5 files changed

+89
-34
lines changed

app-config.production.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
app:
2+
baseUrl: prodlink
3+
4+
backend:
5+
baseUrl: prodlink
6+
cors:
7+
origin: prodlink
8+
methods: [GET, HEAD, PATCH, POST, PUT, DELETE]
9+
credentials: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"private": true,
55
"engines": {
6-
"node": "20 || 22"
6+
"node": "18 || 20"
77
},
88
"scripts": {
99
"dev": "yarn workspaces foreach -A --include backend --include app --parallel -v -i run start",

packages/app/src/App.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { CatalogGraphPage } from '@backstage/plugin-catalog-graph';
3434
import { RequirePermission } from '@backstage/plugin-permission-react';
3535
import { catalogEntityCreatePermission } from '@backstage/plugin-catalog-common/alpha';
3636

37-
import { googleAuthApiRef } from '@backstage/core-plugin-api';
37+
import { googleAuthApiRef, githubAuthApiRef } from '@backstage/core-plugin-api';
3838
import { SignInPage, SignInProviderConfig } from '@backstage/core-components';
3939

4040
const googleProvider: SignInProviderConfig = {
@@ -44,6 +44,12 @@ const googleProvider: SignInProviderConfig = {
4444
apiRef: googleAuthApiRef,
4545
};
4646

47+
const githubProvider: SignInProviderConfig = {
48+
id: 'github-auth-provider',
49+
title: 'GitHub',
50+
message: 'Sign in using GitHub',
51+
apiRef: githubAuthApiRef,
52+
};
4753

4854
const app = createApp({
4955
apis,
@@ -53,7 +59,8 @@ const app = createApp({
5359
{...props}
5460
auto
5561
providers={[
56-
googleProvider
62+
googleProvider,
63+
githubProvider
5764
]}
5865
/>
5966
),

packages/backend/src/index.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,64 @@
11
import { createBackend } from '@backstage/backend-defaults';
2-
// import { customGoogleAuth } from './plugins/plugins_helper/googleCustomAuth';
32

3+
import { createBackendModule } from '@backstage/backend-plugin-api';
4+
import { stringifyEntityRef } from '@backstage/catalog-model';
5+
import { githubAuthenticator } from '@backstage/plugin-auth-backend-module-github-provider';
6+
import { authProvidersExtensionPoint, createOAuthProviderFactory } from '@backstage/plugin-auth-node';
7+
8+
// Create a new backend instance
49
const backend = createBackend();
510

611
backend.add(import('@backstage/plugin-app-backend'));
7-
// backend.add(import('@spotify/backstage-plugin-soundcheck-backend'));
812
backend.add(import('@backstage/plugin-proxy-backend'))
913
backend.add(import('@backstage/plugin-scaffolder-backend'));
1014
backend.add(import('@backstage/plugin-techdocs-backend'));
1115

1216
// Add the auth backend
1317
backend.add(import('@backstage/plugin-auth-backend'));
1418
backend.add(import('@backstage/plugin-auth-backend-module-google-provider'));
15-
// backend.add(customGoogleAuth);
19+
20+
// Custom Github Auth Provider
21+
export const customGithubAuth = createBackendModule({
22+
pluginId: 'auth',
23+
moduleId: 'githubProvider',
24+
register(reg) {
25+
reg.registerInit({
26+
deps: { providers: authProvidersExtensionPoint },
27+
async init({ providers }) {
28+
providers.registerProvider({
29+
providerId: 'github',
30+
factory: createOAuthProviderFactory({
31+
authenticator: githubAuthenticator,
32+
async signInResolver(info, ctx) {
33+
const { profile: { email } } = info;
34+
35+
if (!email) {
36+
throw new Error('User profile has no email');
37+
}
38+
39+
const [userId] = email.split('@');
40+
41+
const userEntity = stringifyEntityRef({
42+
kind: 'User',
43+
namespace: 'default',
44+
name: userId,
45+
})
46+
47+
return ctx.issueToken({
48+
claims: {
49+
sub: userEntity,
50+
ent: [userEntity],
51+
}
52+
})
53+
},
54+
}),
55+
});
56+
},
57+
});
58+
},
59+
});
60+
61+
backend.add(customGithubAuth);
1662

1763
// Add the catalog backend and the catalog entities
1864
backend.add(import('@backstage/plugin-catalog-backend'));

yarn.lock

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ __metadata:
385385
ajv-formats: "npm:^2.1.1"
386386
avsc: "npm:^5.7.5"
387387
js-yaml: "npm:^4.1.0"
388-
jsonpath-plus: "npm:^10.0.0"
388+
jsonpath-plus: "npm:^10.0.7"
389389
node-fetch: "npm:2.6.7"
390390
checksum: 10c0/340906e46bb87486d738917035433dc19eafcd4f9dcef7168f8d1379b559d67aa1489e51fd3a030ec4bab74c7708b8a7e3fd01af83ab51a6dbbf9bf32f8d6e2f
391391
languageName: node
@@ -9097,7 +9097,7 @@ __metadata:
90979097
byline: "npm:^5.0.0"
90989098
isomorphic-ws: "npm:^5.0.0"
90999099
js-yaml: "npm:^4.1.0"
9100-
jsonpath-plus: "npm:^7.2.0"
9100+
jsonpath-plus: "npm:^10.0.7"
91019101
openid-client: "npm:^5.3.0"
91029102
request: "npm:^2.88.0"
91039103
rfc4648: "npm:^1.3.0"
@@ -9125,7 +9125,7 @@ __metadata:
91259125
form-data: "npm:^4.0.0"
91269126
isomorphic-ws: "npm:^5.0.0"
91279127
js-yaml: "npm:^4.1.0"
9128-
jsonpath-plus: "npm:^10.0.0"
9128+
jsonpath-plus: "npm:^10.0.7"
91299129
node-fetch: "npm:^2.6.9"
91309130
openid-client: "npm:^5.6.5"
91319131
rfc4648: "npm:^1.3.0"
@@ -13567,7 +13567,7 @@ __metadata:
1356713567
ajv-errors: "npm:~3.0.0"
1356813568
ajv-formats: "npm:~2.1.0"
1356913569
es-aggregate-error: "npm:^1.0.7"
13570-
jsonpath-plus: "npm:7.1.0"
13570+
jsonpath-plus: "npm:10.0.7"
1357113571
lodash: "npm:~4.17.21"
1357213572
lodash.topath: "npm:^4.5.2"
1357313573
minimatch: "npm:3.1.2"
@@ -18867,7 +18867,7 @@ __metadata:
1886718867
version: 1.0.2
1886818868
resolution: "codeowners-utils@npm:1.0.2"
1886918869
dependencies:
18870-
cross-spawn: "npm:^7.0.2"
18870+
cross-spawn: "npm:^7.0.3"
1887118871
find-up: "npm:^4.1.0"
1887218872
ignore: "npm:^5.1.4"
1887318873
locate-path: "npm:^5.0.0"
@@ -19754,7 +19754,7 @@ __metadata:
1975419754
version: 7.0.3
1975519755
resolution: "cross-env@npm:7.0.3"
1975619756
dependencies:
19757-
cross-spawn: "npm:^7.0.1"
19757+
cross-spawn: "npm:^7.0.3"
1975819758
bin:
1975919759
cross-env: src/bin/cross-env.js
1976019760
cross-env-shell: src/bin/cross-env-shell.js
@@ -19798,7 +19798,7 @@ __metadata:
1979819798
languageName: node
1979919799
linkType: hard
1980019800

19801-
"cross-spawn@npm:^7.0.0, cross-spawn@npm:^7.0.1, cross-spawn@npm:^7.0.2, cross-spawn@npm:^7.0.3":
19801+
"cross-spawn@npm:^7.0.3":
1980219802
version: 7.0.3
1980319803
resolution: "cross-spawn@npm:7.0.3"
1980419804
dependencies:
@@ -22044,7 +22044,7 @@ __metadata:
2204422044
"@ungap/structured-clone": "npm:^1.2.0"
2204522045
ajv: "npm:^6.12.4"
2204622046
chalk: "npm:^4.0.0"
22047-
cross-spawn: "npm:^7.0.2"
22047+
cross-spawn: "npm:^7.0.3"
2204822048
debug: "npm:^4.3.2"
2204922049
doctrine: "npm:^3.0.0"
2205022050
escape-string-regexp: "npm:^4.0.0"
@@ -23047,7 +23047,7 @@ __metadata:
2304723047
version: 3.1.1
2304823048
resolution: "foreground-child@npm:3.1.1"
2304923049
dependencies:
23050-
cross-spawn: "npm:^7.0.0"
23050+
cross-spawn: "npm:^7.0.3"
2305123051
signal-exit: "npm:^4.0.1"
2305223052
checksum: 10c0/9700a0285628abaeb37007c9a4d92bd49f67210f09067638774338e146c8e9c825c5c877f072b2f75f41dc6a2d0be8664f79ffc03f6576649f54a84fb9b47de0
2305323053
languageName: node
@@ -26984,7 +26984,14 @@ __metadata:
2698426984
languageName: node
2698526985
linkType: hard
2698626986

26987-
"jsonpath-plus@npm:10.2.0, jsonpath-plus@npm:^10.0.0, jsonpath-plus@npm:^10.2.0, jsonpath-plus@npm:^6.0.1 || ^10.1.0":
26987+
"jsonpath-plus@npm:10.0.7":
26988+
version: 10.0.7
26989+
resolution: "jsonpath-plus@npm:7.1.0"
26990+
checksum: 10c0/3a74b39f434c6496191eaa2820331407d89868b59cfbb9458c0f665e6877a67125b506d68c887746420660e7a3c4f279367182bec38093f3a0129f3757c85c48
26991+
languageName: node
26992+
linkType: hard
26993+
26994+
"jsonpath-plus@npm:10.2.0, jsonpath-plus@npm:^10.0.7 || ^10.1.0, jsonpath-plus@npm:^10.2.0":
2698826995
version: 10.2.0
2698926996
resolution: "jsonpath-plus@npm:10.2.0"
2699026997
dependencies:
@@ -26998,22 +27005,8 @@ __metadata:
2699827005
languageName: node
2699927006
linkType: hard
2700027007

27001-
"jsonpath-plus@npm:7.1.0":
27002-
version: 7.1.0
27003-
resolution: "jsonpath-plus@npm:7.1.0"
27004-
checksum: 10c0/3a74b39f434c6496191eaa2820331407d89868b59cfbb9458c0f665e6877a67125b506d68c887746420660e7a3c4f279367182bec38093f3a0129f3757c85c48
27005-
languageName: node
27006-
linkType: hard
27007-
27008-
"jsonpath-plus@npm:^6.0.1":
27009-
version: 6.0.1
27010-
resolution: "jsonpath-plus@npm:6.0.1"
27011-
checksum: 10c0/ecbe5caad723a42e1cc4a28058ca837eba00d36075766a7f3cf828491648e3b64d9fa0d5a64dd868e7c3180b1f9fcec565c32a1c05b34bef9f88c3c0c7acd1a2
27012-
languageName: node
27013-
linkType: hard
27014-
27015-
"jsonpath-plus@npm:^7.2.0":
27016-
version: 7.2.0
27008+
"jsonpath-plus@npm:^10.0.7":
27009+
version: 10.0.7
2701727010
resolution: "jsonpath-plus@npm:7.2.0"
2701827011
checksum: 10c0/b4fbb8387b80721a47e8098f390dbaa5c74ff4e778832d9f662bcf4ab6038ded26944b8dd433f0474b51fb3e0d7e960990c03af89f4f922a6dc0905102ed86b2
2701927012
languageName: node
@@ -29925,7 +29918,7 @@ __metadata:
2992529918
"@jsep-plugin/ternary": "npm:^1.0.2"
2992629919
astring: "npm:^1.8.1"
2992729920
jsep: "npm:^1.2.0"
29928-
jsonpath-plus: "npm:^6.0.1"
29921+
jsonpath-plus: "npm:^10.0.7"
2992929922
lodash.topath: "npm:^4.5.2"
2993029923
dependenciesMeta:
2993129924
jsonpath-plus:
@@ -29944,7 +29937,7 @@ __metadata:
2994429937
"@jsep-plugin/ternary": "npm:^1.0.2"
2994529938
astring: "npm:^1.8.1"
2994629939
jsep: "npm:^1.2.0"
29947-
jsonpath-plus: "npm:^6.0.1 || ^10.1.0"
29940+
jsonpath-plus: "npm:^10.0.7 || ^10.1.0"
2994829941
lodash.topath: "npm:^4.5.2"
2994929942
dependenciesMeta:
2995029943
jsonpath-plus:

0 commit comments

Comments
 (0)