-
Notifications
You must be signed in to change notification settings - Fork 14
/
apis.ts
86 lines (85 loc) · 2.46 KB
/
apis.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import {
ScmIntegrationsApi,
scmIntegrationsApiRef,
ScmAuth,
} from '@backstage/integration-react';
import {
AnyApiFactory,
configApiRef,
createApiFactory,
githubAuthApiRef,
errorApiRef,
discoveryApiRef,
oauthRequestApiRef,
} from '@backstage/core-plugin-api';
import {
graphQlBrowseApiRef,
GraphQLEndpoints,
} from '@backstage/plugin-graphiql';
import { OAuth2 } from '@backstage/core-app-api';
import { auth0AuthApiRef } from './internal';
export const apis: AnyApiFactory[] = [
createApiFactory({
api: auth0AuthApiRef,
deps: {
discoveryApi: discoveryApiRef,
oauthRequestApi: oauthRequestApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, oauthRequestApi, configApi }) =>
OAuth2.create({
discoveryApi,
oauthRequestApi,
provider: {
id: 'auth0',
title: 'Auth0',
icon: () => null,
},
defaultScopes: ['openid', 'email', 'profile', 'offline_access'],
environment: configApi.getOptionalString('auth.environment'),
}),
}),
createApiFactory({
api: scmIntegrationsApiRef,
deps: { configApi: configApiRef },
factory: ({ configApi }) => ScmIntegrationsApi.fromConfig(configApi),
}),
ScmAuth.createDefaultApiFactory(),
createApiFactory({
api: graphQlBrowseApiRef,
deps: {
errorApi: errorApiRef,
githubAuthApi: githubAuthApiRef,
discovery: discoveryApiRef,
},
factory: ({ errorApi, githubAuthApi, discovery }) =>
GraphQLEndpoints.from([
{
id: 'backstage-backend',
title: 'Backstage GraphQL API',
// we use the lower level object with a fetcher function
// as we need to `await` the backend url for the graphql plugin
fetcher: async (params: any) => {
const graphqlURL = await discovery.getBaseUrl('graphql');
return fetch(graphqlURL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params),
}).then(res => res.json());
},
},
GraphQLEndpoints.github({
id: 'github',
title: 'GitHub',
errorApi,
githubAuthApi,
}),
// example, remove in the future?
GraphQLEndpoints.create({
id: 'swapi',
title: 'Star Wars API',
url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
}),
]),
}),
];