From 18148f23da682a16a034e1f2a5de5d788793a91a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 5 Sep 2021 14:24:58 +0200 Subject: [PATCH] changesets: added changeset for ScmAuthApi Signed-off-by: Patrik Oldsberg --- .changeset/purple-scissors-allow.md | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .changeset/purple-scissors-allow.md diff --git a/.changeset/purple-scissors-allow.md b/.changeset/purple-scissors-allow.md new file mode 100644 index 0000000000..0cf4b30884 --- /dev/null +++ b/.changeset/purple-scissors-allow.md @@ -0,0 +1,44 @@ +--- +'@backstage/integration-react': patch +--- + +Added `ScmAuthApi` along with the implementation `ScmAuth`. The `ScmAuthApi` provides methods for client-side authentication towards multiple different source code management services simultaneously. + +When requesting credentials you supply a URL along with the same options as the other `OAuthApi`s, and optionally a request for additional high-level scopes. + +For example like this: + +```ts +const { token } = await scmAuthApi.getCredentials({ + url: 'https://ghe.example.com/backstage/backstage', + additionalScope: { + repoWrite: true, + }, +}); +``` + +The instantiation of the API can either be done with a default factory that adds support for the public providers (github.com, gitlab.com, etc.): + +```ts +// in packages/app/apis.ts +ScmAuth.createDefaultApiFactory(); +``` + +Or with a more custom setup that can add support for additional providers, for example like this: + +```ts +createApiFactory({ + api: scmAuthApiRef, + deps: { + gheAuthApi: gheAuthApiRef, + githubAuthApi: githubAuthApiRef, + }, + factory: ({ githubAuthApi, gheAuthApi }) => + ScmAuth.merge( + ScmAuth.forGithub(githubAuthApi), + ScmAuth.forGithub(gheAuthApi, { + host: 'ghe.example.com', + }), + ), +}); +```