diff --git a/.changeset/great-rabbits-juggle.md b/.changeset/great-rabbits-juggle.md index afa170bfb8..649af14aeb 100644 --- a/.changeset/great-rabbits-juggle.md +++ b/.changeset/great-rabbits-juggle.md @@ -2,4 +2,35 @@ '@backstage/plugin-catalog-import': minor --- -Switched to using the `ScmAuthApi` for authentication rather than GitHub auth. If you are instantiating your `CatalogImportClient` manually you now need to pass in an instance of `ScmAuthApi` instead. Also be sure to register the `scmAuthApiRef` from the `@backstage/integration-react` in your app. +Switched to using the `ScmAuthApi` for authentication rather than GitHub auth. If you are instantiating your `CatalogImportClient` manually you now need to pass in an instance of `ScmAuthApi` instead. + +Also be sure to register the `scmAuthApiRef` from the `@backstage/integration-react` in your app: + +```ts +import { ScmAuth } from '@backstage/integration-react'; + +// in packages/app/apis.ts + +const apis = [ +// ... other APIs + +ScmAuth.createDefaultApiFactory(); + +// OR + +createApiFactory({ + api: scmAuthApiRef, + deps: { + gheAuthApi: gheAuthApiRef, + githubAuthApi: githubAuthApiRef, + }, + factory: ({ githubAuthApi, gheAuthApi }) => + ScmAuth.merge( + ScmAuth.forGithub(githubAuthApi), + ScmAuth.forGithub(gheAuthApi, { + host: 'ghe.example.com', + }), + ), +}); +] +``` diff --git a/.changeset/purple-scissors-allow.md b/.changeset/purple-scissors-allow.md index 0cf4b30884..39d70d4c2a 100644 --- a/.changeset/purple-scissors-allow.md +++ b/.changeset/purple-scissors-allow.md @@ -42,3 +42,48 @@ createApiFactory({ ), }); ``` + +The additional `gheAuthApiRef` utility API can be defined either inside the app itself if it's only used for this purpose, for inside an internal common package for APIs, such as `@internal/apis`: + +```ts +const gheAuthApiRef: ApiRef = + createApiRef({ + id: 'internal.auth.ghe', + }); +``` + +And then implemented using the `GithubAuth` class from `@backstage/core-app-api`: + +```ts +createApiFactory({ + api: githubAuthApiRef, + deps: { + discoveryApi: discoveryApiRef, + oauthRequestApi: oauthRequestApiRef, + configApi: configApiRef, + }, + factory: ({ discoveryApi, oauthRequestApi, configApi }) => + GithubAuth.create({ + provider: { + id: 'ghe', + icon: ..., + title: 'GHE' + }, + discoveryApi, + oauthRequestApi, + defaultScopes: ['read:user'], + environment: configApi.getOptionalString('auth.environment'), + }), +}) +``` + +Finally you also need to add and configure another GitHub provider to the `auth-backend` using the provider ID `ghe`: + +```ts +// Add the following options to `createRouter` in packages/backend/src/plugins/auth.ts +providerFactories: { + ghe: createGithubProvider(), +}, +``` + +Other providers follow the same steps, but you will want to use the appropriate auth API implementation in the frontend, such as for example `GitlabAuth`. diff --git a/packages/integration-react/src/api/ScmAuth.ts b/packages/integration-react/src/api/ScmAuth.ts index beb66222d7..c34c4da758 100644 --- a/packages/integration-react/src/api/ScmAuth.ts +++ b/packages/integration-react/src/api/ScmAuth.ts @@ -36,7 +36,7 @@ type ScopeMapping = { }; class ScmAuthMux implements ScmAuthApi { - #providers = new Array(); + #providers: Array; constructor(providers: ScmAuth[]) { this.#providers = providers; diff --git a/packages/integration-react/src/api/ScmAuthApi.ts b/packages/integration-react/src/api/ScmAuthApi.ts index ddb9922a19..d8fc413620 100644 --- a/packages/integration-react/src/api/ScmAuthApi.ts +++ b/packages/integration-react/src/api/ScmAuthApi.ts @@ -59,7 +59,7 @@ export interface ScmAuthTokenResponse { /** * ScmAuthApi provides methods for authenticating towards source code management services. * - * As opposed to using the using the GitHub, GitLab and other auth APIs + * As opposed to using the GitHub, GitLab and other auth APIs * directly, this API allows for more generic access to SCM services. * * @public