From 1935b98a432444672033be1cf1fe0ece0b53e44e Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 5 Sep 2021 13:51:53 +0200 Subject: [PATCH] integration-react: add ScmAuth.createDefaultApiFactory Signed-off-by: Patrik Oldsberg --- packages/integration-react/src/api/ScmAuth.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/integration-react/src/api/ScmAuth.ts b/packages/integration-react/src/api/ScmAuth.ts index 54a85e94c7..a2b7da3785 100644 --- a/packages/integration-react/src/api/ScmAuth.ts +++ b/packages/integration-react/src/api/ScmAuth.ts @@ -14,9 +14,16 @@ * limitations under the License. */ -import { OAuthApi } from '@backstage/core-plugin-api'; +import { + createApiFactory, + githubAuthApiRef, + gitlabAuthApiRef, + microsoftAuthApiRef, + OAuthApi, +} from '@backstage/core-plugin-api'; import { ScmAuthApi, + scmAuthApiRef, ScmAuthTokenOptions, ScmAuthTokenResponse, } from './ScmAuthApi'; @@ -55,6 +62,23 @@ class ScmAuthMux implements ScmAuthApi { * to form a single instance that can handles authentication for multiple providers. */ export class ScmAuth implements ScmAuthApi { + static createDefaultApiFactory() { + return createApiFactory({ + api: scmAuthApiRef, + deps: { + github: githubAuthApiRef, + gitlab: gitlabAuthApiRef, + azure: microsoftAuthApiRef, + }, + factory: ({ github, gitlab, azure }) => + ScmAuth.merge( + ScmAuth.forGithub(github), + ScmAuth.forGitlab(gitlab), + ScmAuth.forAzure(azure), + ), + }); + } + /** * Creates a general purpose ScmAuth instance with a custom scope mapping. */ @@ -137,13 +161,13 @@ export class ScmAuth implements ScmAuthApi { * `vso.code_manage` */ static forAzure( - microsoftAuthApiRef: OAuthApi, + microsoftAuthApi: OAuthApi, options?: { host?: string; }, ): ScmAuth { const host = options?.host ?? 'dev.azure.com'; - return new ScmAuth(microsoftAuthApiRef, host, { + return new ScmAuth(microsoftAuthApi, host, { default: [ 'vso.build', 'vso.code',