Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bitbucket Adapter #115

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-snakes-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openauthjs/openauth": patch
---

Feat: Added Bitbucket Adapter
63 changes: 63 additions & 0 deletions packages/openauth/src/adapter/bitbucket.ts
Original file line number Diff line number Diff line change
@@ -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",
},
})
}