Skip to main content

ScmAuth

Home > @backstage/integration-react > ScmAuth

An implementation of the ScmAuthApi that merges together OAuthApi instances to form a single instance that can handles authentication for multiple providers.

Signature:

class ScmAuth implements ScmAuthApi 

Implements: ScmAuthApi

Example

// Supports authentication towards both public GitHub and GHE:
createApiFactory({
api: scmAuthApiRef,
deps: {
gheAuthApi: gheAuthApiRef,
githubAuthApi: githubAuthApiRef,
},
factory: ({ githubAuthApi, gheAuthApi }) =>
ScmAuth.merge(
ScmAuth.forGithub(githubAuthApi),
ScmAuth.forGithub(gheAuthApi, {
host: 'ghe.example.com',
}),
)
})

Methods

MethodModifiersDescription
createDefaultApiFactory()staticCreates an API factory that enables auth for each of the default SCM providers.
forAuthApi(authApi, options)staticCreates a general purpose ScmAuth instance with a custom scope mapping.
forAzure(microsoftAuthApi, options)static

Creates a new ScmAuth instance that handles authentication towards Azure.

The host option determines which URLs that are handled by this instance and defaults to dev.azure.com.

The default scopes are:

vso.build vso.code vso.graph vso.project vso.profile

If the additional repoWrite permission is requested, these scopes are added:

vso.code_manage

forBitbucket(bitbucketAuthApi, options)static

Creates a new ScmAuth instance that handles authentication towards Bitbucket.

The host option determines which URLs that are handled by this instance and defaults to bitbucket.org.

The default scopes are:

account team pullrequest snippet issue

If the additional repoWrite permission is requested, these scopes are added:

pullrequest:write snippet:write issue:write

forGithub(githubAuthApi, options)static

Creates a new ScmAuth instance that handles authentication towards GitHub.

The host option determines which URLs that are handled by this instance and defaults to github.com.

The default scopes are:

repo read:org read:user

If the additional repoWrite permission is requested, these scopes are added:

gist

forGitlab(gitlabAuthApi, options)static

Creates a new ScmAuth instance that handles authentication towards GitLab.

The host option determines which URLs that are handled by this instance and defaults to gitlab.com.

The default scopes are:

read_user read_api read_repository

If the additional repoWrite permission is requested, these scopes are added:

write_repository api

getCredentials(options)Fetches credentials for the given resource.
isUrlSupported(url)Checks whether the implementation is able to provide authentication for the given URL.
merge(providers)staticMerges together multiple ScmAuth instances into one that routes requests to the correct instance based on the URL.