Add fetchApiRef which implements fetch, plus Backstage token header when available.
This intends to be the basis for other plugins' data fetching needs, so that they can transparently interact with the catalog and other parts of the Backstage ecosystem without explicitly having to deal with authenticating themselves. Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -34,6 +34,9 @@ import {
|
||||
OneLoginAuth,
|
||||
UnhandledErrorForwarder,
|
||||
AtlassianAuth,
|
||||
FetchApiBuilder,
|
||||
IdentityAwareFetchMiddleware,
|
||||
BackstageProtocolResolverFetchMiddleware,
|
||||
} from '@backstage/core-app-api';
|
||||
|
||||
import {
|
||||
@@ -42,6 +45,8 @@ import {
|
||||
analyticsApiRef,
|
||||
errorApiRef,
|
||||
discoveryApiRef,
|
||||
fetchApiRef,
|
||||
identityApiRef,
|
||||
oauthRequestApiRef,
|
||||
googleAuthApiRef,
|
||||
githubAuthApiRef,
|
||||
@@ -92,6 +97,24 @@ export const apis = [
|
||||
deps: { errorApi: errorApiRef },
|
||||
factory: ({ errorApi }) => WebStorage.create({ errorApi }),
|
||||
}),
|
||||
createApiFactory({
|
||||
api: fetchApiRef,
|
||||
deps: { identityApi: identityApiRef, discoveryApi: discoveryApiRef },
|
||||
factory: ({ identityApi, discoveryApi }) => {
|
||||
return FetchApiBuilder.create()
|
||||
.with(
|
||||
new IdentityAwareFetchMiddleware(() => {
|
||||
return identityApi.getCredentials().then(r => r.token);
|
||||
}),
|
||||
)
|
||||
.with(
|
||||
new BackstageProtocolResolverFetchMiddleware(plugin => {
|
||||
return discoveryApi.getBaseUrl(plugin);
|
||||
}),
|
||||
)
|
||||
.build();
|
||||
},
|
||||
}),
|
||||
createApiFactory({
|
||||
api: oauthRequestApiRef,
|
||||
deps: {},
|
||||
|
||||
Reference in New Issue
Block a user