diff --git a/.changeset/warm-snakes-film.md b/.changeset/warm-snakes-film.md new file mode 100644 index 00000000..2dff9ec6 --- /dev/null +++ b/.changeset/warm-snakes-film.md @@ -0,0 +1,5 @@ +--- +"@openauthjs/openauth": patch +--- + +Feat: Added Bitbucket Adapter diff --git a/packages/openauth/src/adapter/bitbucket.ts b/packages/openauth/src/adapter/bitbucket.ts new file mode 100644 index 00000000..c49e2a3f --- /dev/null +++ b/packages/openauth/src/adapter/bitbucket.ts @@ -0,0 +1,63 @@ +import { Oauth2Adapter, Oauth2WrappedConfig } from "./oauth2.js" + +/** + * Represents the various scopes that can be used for Bitbucket API access. + * + * A descriptor lacking the scopes element is implicitly assumed to require all scopes and as a result, Bitbucket will require end users authorizing/installing the add-on to explicitly accept all scopes. + * + * @see {@link https://developer.atlassian.com/cloud/bitbucket/rest/intro/#bitbucket-oauth-2-0-scopes} + */ +type Scope = + | "project" + | "project:write" + | "project:admin" + | "repository" + | "repository:write" + | "repository:admin" + | "repository:delete" + | "pullrequest" + | "pullrequest:write" + | "issue" + | "issue:write" + | "wiki" + | "webhook" + | "snippet" + | "snippet:write" + | "email" + | "account" + | "account:write" + | "pipeline" + | "pipeline:write" + | "pipeline:variable" + | "runner" + | "runner:write" + +/** + * Configuration interface for Bitbucket OAuth2 integration. + * + * @extends Oauth2WrappedConfig + * + * @property {Scope[]} scopes - An array of scopes that specify the permissions requested from the user. + */ +export interface BitbucketConfig extends Oauth2WrappedConfig { + scopes: Scope[] +} + +/** + * Creates an OAuth2 adapter configured for Bitbucket. + * + * This function configures an OAuth2 adapter specifically for Bitbucket by + * providing the necessary authorization and token endpoints. + * + * @see {@link https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication} + */ +export function BitbucketAdapter(config: BitbucketConfig) { + return Oauth2Adapter({ + ...config, + type: "bitbucket", + endpoint: { + authorization: "https://bitbucket.org/site/oauth2/authorize", + token: "https://bitbucket.org/site/oauth2/access_token", + }, + }) +}